How to use _get_eligible_host_ids_in_group method in autotest

Best Python code snippet using autotest_python

host_scheduler.py

Source:host_scheduler.py Github

copy

Full Screen

...196 """197 return (id for id, label in self._labels.iteritems()198 if label.atomic_group_id == atomic_group_id199 and not label.invalid)200 def _get_eligible_host_ids_in_group(self, group_hosts, queue_entry):201 """202 @param group_hosts - A sequence of Host ids to test for usability203 and eligibility against the Job associated with queue_entry.204 @param queue_entry - The HostQueueEntry that these hosts are being205 tested for eligibility against.206 @returns A subset of group_hosts Host ids that are eligible for the207 supplied queue_entry.208 """209 return set(host_id for host_id in group_hosts210 if self.is_host_usable(host_id)211 and self.is_host_eligible_for_job(host_id, queue_entry))212 def is_host_eligible_for_job(self, host_id, queue_entry):213 if self._is_host_invalid(host_id):214 # if an invalid host is scheduled for a job, it's a one-time host215 # and it therefore bypasses eligibility checks. note this can only216 # happen for non-metahosts, because invalid hosts have their label217 # relationships cleared.218 return True219 job_dependencies = self._job_dependencies.get(queue_entry.job_id, set())220 host_labels = self._host_labels.get(host_id, set())221 return (self._is_acl_accessible(host_id, queue_entry) and222 self._check_job_dependencies(job_dependencies, host_labels) and223 self._check_only_if_needed_labels(224 job_dependencies, host_labels, queue_entry) and225 self._check_atomic_group_labels(host_labels, queue_entry))226 def _is_host_invalid(self, host_id):227 host_object = self._hosts_available.get(host_id, None)228 return host_object and host_object.invalid229 def _schedule_non_metahost(self, queue_entry):230 if not self.is_host_eligible_for_job(queue_entry.host_id, queue_entry):231 return None232 return self._hosts_available.pop(queue_entry.host_id, None)233 def is_host_usable(self, host_id):234 if host_id not in self._hosts_available:235 # host was already used during this scheduling cycle236 return False237 if self._hosts_available[host_id].invalid:238 # Invalid hosts cannot be used for metahosts. They're included in239 # the original query because they can be used by non-metahosts.240 return False241 return True242 def schedule_entry(self, queue_entry):243 if queue_entry.host_id is not None:244 return self._schedule_non_metahost(queue_entry)245 for scheduler in self._metahost_schedulers:246 if scheduler.can_schedule_metahost(queue_entry):247 scheduler.schedule_metahost(queue_entry, self)248 return None249 raise SchedulerError('No metahost scheduler to handle %s' % queue_entry)250 def find_eligible_atomic_group(self, queue_entry):251 """252 Given an atomic group host queue entry, locate an appropriate group253 of hosts for the associated job to run on.254 The caller is responsible for creating new HQEs for the additional255 hosts returned in order to run the actual job on them.256 @returns A list of Host instances in a ready state to satisfy this257 atomic group scheduling. Hosts will all belong to the same258 atomic group label as specified by the queue_entry.259 An empty list will be returned if no suitable atomic260 group could be found.261 TODO(gps): what is responsible for kicking off any attempted repairs on262 a group of hosts? not this function, but something needs to. We do263 not communicate that reason for returning [] outside of here...264 For now, we'll just be unschedulable if enough hosts within one group265 enter Repair Failed state.266 """267 assert queue_entry.atomic_group_id is not None268 job = queue_entry.job269 assert job.synch_count and job.synch_count > 0270 atomic_group = queue_entry.atomic_group271 if job.synch_count > atomic_group.max_number_of_machines:272 # Such a Job and HostQueueEntry should never be possible to273 # create using the frontend. Regardless, we can't process it.274 # Abort it immediately and log an error on the scheduler.275 queue_entry.set_status(models.HostQueueEntry.Status.ABORTED)276 logging.error(277 'Error: job %d synch_count=%d > requested atomic_group %d '278 'max_number_of_machines=%d. Aborted host_queue_entry %d.',279 job.id, job.synch_count, atomic_group.id,280 atomic_group.max_number_of_machines, queue_entry.id)281 return []282 hosts_in_label = self.hosts_in_label(queue_entry.meta_host)283 ineligible_host_ids = self.ineligible_hosts_for_entry(queue_entry)284 # Look in each label associated with atomic_group until we find one with285 # enough hosts to satisfy the job.286 for atomic_label_id in self._get_atomic_group_labels(atomic_group.id):287 group_hosts = set(self.hosts_in_label(atomic_label_id))288 if queue_entry.meta_host is not None:289 # If we have a metahost label, only allow its hosts.290 group_hosts.intersection_update(hosts_in_label)291 group_hosts -= ineligible_host_ids292 eligible_host_ids_in_group = self._get_eligible_host_ids_in_group(293 group_hosts, queue_entry)294 # Job.synch_count is treated as "minimum synch count" when295 # scheduling for an atomic group of hosts. The atomic group296 # number of machines is the maximum to pick out of a single297 # atomic group label for scheduling at one time.298 min_hosts = job.synch_count299 max_hosts = atomic_group.max_number_of_machines300 if len(eligible_host_ids_in_group) < min_hosts:301 # Not enough eligible hosts in this atomic group label.302 continue303 eligible_hosts_in_group = [self._hosts_available[id]304 for id in eligible_host_ids_in_group]305 # So that they show up in a sane order when viewing the job.306 eligible_hosts_in_group.sort(cmp=scheduler_models.Host.cmp_for_sort)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful