How to use _get_job_ineligible_hosts method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...232 afe_acl_groups_users.user_id = afe_users.id233 WHERE IN (%s)234 """235 return self._get_many2many_dict(query, job_ids)236 def _get_job_ineligible_hosts(self, job_ids):237 query = """238 SELECT job_id, host_id239 FROM afe_ineligible_host_queues240 WHERE job_id IN (%s)241 """242 return self._get_many2many_dict(query, job_ids)243 @metrics.SecondsTimerDecorator(_host_timer_name % 'get_job_dependencies')244 def _get_job_dependencies(self, job_ids):245 query = """246 SELECT job_id, label_id247 FROM afe_jobs_dependency_labels248 WHERE job_id IN (%s)249 """250 return self._get_many2many_dict(query, job_ids)251 @classmethod252 def find_unused_healty_hosts(cls):253 """Get hosts that are currently unused and in the READY state.254 @return: A list of host objects, one for each unused healthy host.255 """256 # Avoid any host with a currently active queue entry against it.257 hqe_join = ('LEFT JOIN afe_host_queue_entries AS active_hqe '258 'ON ( = active_hqe.host_id AND '259 '')260 # Avoid any host with a new special task against it. There are 2 cases261 # when an inactive but incomplete special task will not use the host262 # this tick: 1. When the host is locked 2. When an active hqe already263 # has special tasks for the same host. In both these cases this host264 # will not be in the ready hosts list anyway. In all other cases,265 # an incomplete special task will grab the host before a new job does266 # by assigning an agent to it.267 special_task_join = ('LEFT JOIN afe_special_tasks as new_tasks '268 'ON ( = new_tasks.host_id AND '269 'new_tasks.is_complete=0)')270 return scheduler_models.Host.fetch(271 joins='%s %s' % (hqe_join, special_task_join),272 where="active_hqe.host_id IS NULL AND new_tasks.host_id IS NULL "273 "AND afe_hosts.leased "274 "AND NOT afe_hosts.locked "275 "AND (afe_hosts.status IS NULL "276 "OR afe_hosts.status = 'Ready')")277 @metrics.SecondsTimerDecorator(_host_timer_name % 'set_leased')278 def set_leased(self, leased_value, **kwargs):279 """Modify the leased bit on the hosts with ids in host_ids.280 @param leased_value: The True/False value of the leased column for281 the hosts with ids in host_ids.282 @param kwargs: The args to use in finding matching hosts.283 """284'Setting leased = %s for the hosts that match %s',285 leased_value, kwargs)286 models.Host.objects.filter(**kwargs).update(leased=leased_value)287 @metrics.SecondsTimerDecorator(_host_timer_name % 'get_labels')288 def _get_labels(self, job_dependencies):289 """290 Calculate a dict mapping label id to label object so that we don't291 frequently round trip to the database every time we need a label.292 @param job_dependencies: A dict mapping an integer job id to a list of293 integer label id's. ie. {job_id: [label_id]}294 @return: A dict mapping an integer label id to a scheduler model label295 object. ie. {label_id: label_object}296 """297 id_to_label = dict()298 # Pull all the labels on hosts we might look at299 host_labels = scheduler_models.Label.fetch(300 where="id IN (SELECT label_id FROM afe_hosts_labels)")301 id_to_label.update([(, label) for label in host_labels])302 # and pull all the labels on jobs we might look at.303 job_label_set = set()304 for job_deps in job_dependencies.values():305 job_label_set.update(job_deps)306 # On the rare/impossible chance that no jobs have any labels, we307 # can skip this.308 if job_label_set:309 job_string_label_list = ','.join([str(x) for x in job_label_set])310 job_labels = scheduler_models.Label.fetch(311 where="id IN (%s)" % job_string_label_list)312 id_to_label.update([(, label) for label in job_labels])313 return id_to_label314 def refresh(self, pending_queue_entries):315 """Update the query manager.316 Cache information about a list of queue entries and eligible hosts317 from the database so clients can avoid expensive round trips during318 host acquisition.319 @param pending_queue_entries: A list of queue entries about which we320 need information.321 """322 self._hosts_available = self._get_ready_hosts()323 relevant_jobs = [queue_entry.job_id324 for queue_entry in pending_queue_entries]325 self._job_acls = self._get_job_acl_groups(relevant_jobs)326 self._ineligible_hosts = (self._get_job_ineligible_hosts(relevant_jobs))327 self._job_dependencies = (self._get_job_dependencies(relevant_jobs))328 host_ids = self._hosts_available.keys()...

Full Screen

Full Screen Github


Full Screen

...73 afe_acl_groups_users.user_id = afe_users.id74 WHERE IN (%s)75 """76 return self._get_many2many_dict(query, job_ids)77 def _get_job_ineligible_hosts(self, job_ids):78 query = """79 SELECT job_id, host_id80 FROM afe_ineligible_host_queues81 WHERE job_id IN (%s)82 """83 return self._get_many2many_dict(query, job_ids)84 def _get_job_dependencies(self, job_ids):85 query = """86 SELECT job_id, label_id87 FROM afe_jobs_dependency_labels88 WHERE job_id IN (%s)89 """90 return self._get_many2many_dict(query, job_ids)91 def _get_host_acls(self, host_ids):92 query = """93 SELECT host_id, aclgroup_id94 FROM afe_acl_groups_hosts95 WHERE host_id IN (%s)96 """97 return self._get_many2many_dict(query, host_ids)98 def _get_label_hosts(self, host_ids):99 if not host_ids:100 return {}, {}101 query = """102 SELECT label_id, host_id103 FROM afe_hosts_labels104 WHERE host_id IN (%s)105 """ % self._get_sql_id_list(host_ids)106 rows = self._db.execute(query)107 labels_to_hosts = self._process_many2many_dict(rows)108 hosts_to_labels = self._process_many2many_dict(rows, flip=True)109 return labels_to_hosts, hosts_to_labels110 def _get_labels(self):111 return dict((, label) for label112 in scheduler_models.Label.fetch())113 def recovery_on_startup(self):114 for metahost_scheduler in self._metahost_schedulers:115 metahost_scheduler.recovery_on_startup()116 def refresh(self, pending_queue_entries):117 self._hosts_available = self._get_ready_hosts()118 relevant_jobs = [queue_entry.job_id119 for queue_entry in pending_queue_entries]120 self._job_acls = self._get_job_acl_groups(relevant_jobs)121 self._ineligible_hosts = self._get_job_ineligible_hosts(relevant_jobs)122 self._job_dependencies = self._get_job_dependencies(relevant_jobs)123 host_ids = self._hosts_available.keys()124 self._host_acls = self._get_host_acls(host_ids)125 self._label_hosts, self._host_labels = self._get_label_hosts(host_ids)126 self._labels = self._get_labels()127 def tick(self):128 for metahost_scheduler in self._metahost_schedulers:129 metahost_scheduler.tick()130 def hosts_in_label(self, label_id):131 return set(self._label_hosts.get(label_id, ()))132 def remove_host_from_label(self, host_id, label_id):133 self._label_hosts[label_id].remove(host_id)134 def pop_host(self, host_id):135 return self._hosts_available.pop(host_id)...

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:


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?