How to use _check_job_dependencies method in autotest

Best Python code snippet using autotest_python

host_scheduler.py

Source:host_scheduler.py Github

copy

Full Screen

...138 def _is_acl_accessible(self, host_id, queue_entry):139 job_acls = self._job_acls.get(queue_entry.job_id, set())140 host_acls = self._host_acls.get(host_id, set())141 return len(host_acls.intersection(job_acls)) > 0142 def _check_job_dependencies(self, job_dependencies, host_labels):143 missing = job_dependencies - host_labels144 return len(missing) == 0145 def _check_only_if_needed_labels(self, job_dependencies, host_labels,146 queue_entry):147 if not queue_entry.meta_host:148 # bypass only_if_needed labels when a specific host is selected149 return True150 for label_id in host_labels:151 label = self._labels[label_id]152 if not label.only_if_needed:153 # we don't care about non-only_if_needed labels154 continue155 if queue_entry.meta_host == label_id:156 # if the label was requested in a metahost it's OK157 continue158 if label_id not in job_dependencies:159 return False160 return True161 def _check_atomic_group_labels(self, host_labels, queue_entry):162 """163 Determine if the given HostQueueEntry's atomic group settings are okay164 to schedule on a host with the given labels.165 @param host_labels: A list of label ids that the host has.166 @param queue_entry: The HostQueueEntry being considered for the host.167 @returns True if atomic group settings are okay, False otherwise.168 """169 return (self._get_host_atomic_group_id(host_labels, queue_entry) ==170 queue_entry.atomic_group_id)171 def _get_host_atomic_group_id(self, host_labels, queue_entry=None):172 """173 Return the atomic group label id for a host with the given set of174 labels if any, or None otherwise. Raises an exception if more than175 one atomic group are found in the set of labels.176 @param host_labels: A list of label ids that the host has.177 @param queue_entry: The HostQueueEntry we're testing. Only used for178 extra info in a potential logged error message.179 @returns The id of the atomic group found on a label in host_labels180 or None if no atomic group label is found.181 """182 atomic_labels = [self._labels[label_id] for label_id in host_labels183 if self._labels[label_id].atomic_group_id is not None]184 atomic_ids = set(label.atomic_group_id for label in atomic_labels)185 if not atomic_ids:186 return None187 if len(atomic_ids) > 1:188 logging.error('More than one Atomic Group on HQE "%s" via: %r',189 queue_entry, atomic_labels)190 return atomic_ids.pop()191 def _get_atomic_group_labels(self, atomic_group_id):192 """193 Lookup the label ids that an atomic_group is associated with.194 @param atomic_group_id - The id of the AtomicGroup to look up.195 @returns A generator yeilding Label ids for this atomic group.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 False...

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