How to use _get_label_hosts method in autotest

Best Python code snippet using autotest_python

query_managers.py

Source:query_managers.py Github

copy

Full Screen

...251 WHERE host_id IN (%s)252 """253 return self._get_many2many_dict(query, host_ids)254 @_host_timer.decorate255 def _get_label_hosts(self, host_ids):256 if not host_ids:257 return {}, {}258 query = """259 SELECT label_id, host_id260 FROM afe_hosts_labels261 WHERE host_id IN (%s)262 """ % self._get_sql_id_list(host_ids)263 rows = self._db.execute(query)264 labels_to_hosts = self._process_many2many_dict(rows)265 hosts_to_labels = self._process_many2many_dict(rows, flip=True)266 return labels_to_hosts, hosts_to_labels267 @classmethod268 def find_unused_healty_hosts(cls):269 """Get hosts that are currently unused and in the READY state.270 @return: A list of host objects, one for each unused healthy host.271 """272 # Avoid any host with a currently active queue entry against it.273 hqe_join = ('LEFT JOIN afe_host_queue_entries AS active_hqe '274 'ON (afe_hosts.id = active_hqe.host_id AND '275 'active_hqe.active)')276 # Avoid any host with a new special task against it. There are 2 cases277 # when an inactive but incomplete special task will not use the host278 # this tick: 1. When the host is locked 2. When an active hqe already279 # has special tasks for the same host. In both these cases this host280 # will not be in the ready hosts list anyway. In all other cases,281 # an incomplete special task will grab the host before a new job does282 # by assigning an agent to it.283 special_task_join = ('LEFT JOIN afe_special_tasks as new_tasks '284 'ON (afe_hosts.id = new_tasks.host_id AND '285 'new_tasks.is_complete=0)')286 return scheduler_models.Host.fetch(287 joins='%s %s' % (hqe_join, special_task_join),288 where="active_hqe.host_id IS NULL AND new_tasks.host_id IS NULL "289 "AND afe_hosts.leased "290 "AND NOT afe_hosts.locked "291 "AND (afe_hosts.status IS NULL "292 "OR afe_hosts.status = 'Ready')")293 @_host_timer.decorate294 def set_leased(self, leased_value, **kwargs):295 """Modify the leased bit on the hosts with ids in host_ids.296 @param leased_value: The True/False value of the leased column for297 the hosts with ids in host_ids.298 @param kwargs: The args to use in finding matching hosts.299 """300 logging.info('Setting leased = %s for the hosts that match %s',301 leased_value, kwargs)302 models.Host.objects.filter(**kwargs).update(leased=leased_value)303 @_host_timer.decorate304 def _get_labels(self, job_dependencies):305 """306 Calculate a dict mapping label id to label object so that we don't307 frequently round trip to the database every time we need a label.308 @param job_dependencies: A dict mapping an integer job id to a list of309 integer label id's. ie. {job_id: [label_id]}310 @return: A dict mapping an integer label id to a scheduler model label311 object. ie. {label_id: label_object}312 """313 id_to_label = dict()314 # Pull all the labels on hosts we might look at315 host_labels = scheduler_models.Label.fetch(316 where="id IN (SELECT label_id FROM afe_hosts_labels)")317 id_to_label.update([(label.id, label) for label in host_labels])318 # and pull all the labels on jobs we might look at.319 job_label_set = set()320 for job_deps in job_dependencies.values():321 job_label_set.update(job_deps)322 # On the rare/impossible chance that no jobs have any labels, we323 # can skip this.324 if job_label_set:325 job_string_label_list = ','.join([str(x) for x in job_label_set])326 job_labels = scheduler_models.Label.fetch(327 where="id IN (%s)" % job_string_label_list)328 id_to_label.update([(label.id, label) for label in job_labels])329 return id_to_label330 @_host_timer.decorate331 def refresh(self, pending_queue_entries):332 """Update the query manager.333 Cache information about a list of queue entries and eligible hosts334 from the database so clients can avoid expensive round trips during335 host acquisition.336 @param pending_queue_entries: A list of queue entries about which we337 need information.338 """339 self._hosts_available = self._get_ready_hosts()340 relevant_jobs = [queue_entry.job_id341 for queue_entry in pending_queue_entries]342 self._job_acls = self._get_job_acl_groups(relevant_jobs)343 self._ineligible_hosts = (self._get_job_ineligible_hosts(relevant_jobs))344 self._job_dependencies = (self._get_job_dependencies(relevant_jobs))345 host_ids = self._hosts_available.keys()346 self._host_acls = self._get_host_acls(host_ids)347 self._label_hosts, self._host_labels = (348 self._get_label_hosts(host_ids))...

Full Screen

Full Screen

host_scheduler.py

Source:host_scheduler.py Github

copy

Full Screen

...94 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.id, 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)136 def ineligible_hosts_for_entry(self, queue_entry):137 return set(self._ineligible_hosts.get(queue_entry.job_id, ()))138 def _is_acl_accessible(self, host_id, queue_entry):139 job_acls = self._job_acls.get(queue_entry.job_id, set())...

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