How to use check_atomic_group_create_job method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...195 {'' : 'You cannot abort part of a synchronous job execution '196 '(%d/%s), %d included, %d expected'197 % (, queue_entry.execution_subdir,198 execution_count, queue_entry.job.synch_count)})199def check_atomic_group_create_job(synch_count, host_objects, metahost_objects,200 dependencies, atomic_group, labels_by_name):201 """202 Attempt to reject create_job requests with an atomic group that203 will be impossible to schedule. The checks are not perfect but204 should catch the most obvious issues.205 @param synch_count - The job's minimum synch count.206 @param host_objects - A list of models.Host instances.207 @param metahost_objects - A list of models.Label instances.208 @param dependencies - A list of job dependency label names.209 @param atomic_group - The models.AtomicGroup instance.210 @param labels_by_name - A dictionary mapping label names to models.Label211 instance. Used to look up instances for dependencies.212 @raises model_logic.ValidationError - When an issue is found.213 """214 # If specific host objects were supplied with an atomic group, verify215 # that there are enough to satisfy the synch_count.216 minimum_required = synch_count or 1217 if (host_objects and not metahost_objects and218 len(host_objects) < minimum_required):219 raise model_logic.ValidationError(220 {'hosts':221 'only %d hosts provided for job with synch_count = %d' %222 (len(host_objects), synch_count)})223 # Check that the atomic group has a hope of running this job224 # given any supplied metahosts and dependancies that may limit.225 # Get a set of hostnames in the atomic group.226 possible_hosts = set()227 for label in atomic_group.label_set.all():228 possible_hosts.update(h.hostname for h in label.host_set.all())229 # Filter out hosts that don't match all of the job dependency labels.230 for label_name in set(dependencies):231 label = labels_by_name[label_name]232 hosts_in_label = (h.hostname for h in label.host_set.all())233 possible_hosts.intersection_update(hosts_in_label)234 if not host_objects and not metahost_objects:235 # No hosts or metahosts are required to queue an atomic group Job.236 # However, if they are given, we respect them below.237 host_set = possible_hosts238 else:239 host_set = set(host.hostname for host in host_objects)240 unusable_host_set = host_set.difference(possible_hosts)241 if unusable_host_set:242 raise model_logic.ValidationError(243 {'hosts': 'Hosts "%s" are not in Atomic Group "%s"' %244 (', '.join(sorted(unusable_host_set)),})245 # Lookup hosts provided by each meta host and merge them into the246 # host_set for final counting.247 for meta_host in metahost_objects:248 meta_possible = possible_hosts.copy()249 hosts_in_meta_host = (h.hostname for h in meta_host.host_set.all())250 meta_possible.intersection_update(hosts_in_meta_host)251 # Count all hosts that this meta_host will provide.252 host_set.update(meta_possible)253 if len(host_set) < minimum_required:254 raise model_logic.ValidationError(255 {'atomic_group_name':256 'Insufficient hosts in Atomic Group "%s" with the'257 ' supplied dependencies and meta_hosts.' %258 (,)})259def get_motd():260 dirname = os.path.dirname(__file__)261 filename = os.path.join(dirname, "..", "..", "motd.txt")262 text = ''263 try:264 fp = open(filename, "r")265 try:266 text = finally:268 fp.close()269 except:270 pass271 return text272def _get_metahost_counts(metahost_objects):273 metahost_counts = {}274 for metahost in metahost_objects:275 metahost_counts.setdefault(metahost, 0)276 metahost_counts[metahost] += 1277 return metahost_counts278def get_job_info(job, preserve_metahosts=False, queue_entry_filter_data=None):279 hosts = []280 one_time_hosts = []281 meta_hosts = []282 atomic_group = None283 queue_entries = job.hostqueueentry_set.all()284 if queue_entry_filter_data:285 queue_entries = models.HostQueueEntry.query_objects(286 queue_entry_filter_data, initial_query=queue_entries)287 for queue_entry in queue_entries:288 if ( and (preserve_metahosts or289 not queue_entry.meta_host)):290 if queue_entry.deleted:291 continue292 if one_time_hosts.append( else:295 hosts.append( else:297 meta_hosts.append(queue_entry.meta_host)298 if atomic_group is None:299 if queue_entry.atomic_group is not None:300 atomic_group = queue_entry.atomic_group301 else:302 assert ==, (303 'DB inconsistency. HostQueueEntries with multiple atomic'304 ' groups on job %s: %s != %s' % (305 id,, meta_host_counts = _get_metahost_counts(meta_hosts)307 info = dict(dependencies=[ for label308 in job.dependency_labels.all()],309 hosts=hosts,310 meta_hosts=meta_hosts,311 meta_host_counts=meta_host_counts,312 one_time_hosts=one_time_hosts,313 atomic_group=atomic_group)314 return info315def create_new_job(owner, options, host_objects, metahost_objects,316 atomic_group=None):317 labels_by_name = dict((, label)318 for label in models.Label.objects.all())319 all_host_objects = host_objects + metahost_objects320 metahost_counts = _get_metahost_counts(metahost_objects)321 dependencies = options.get('dependencies', [])322 synch_count = options.get('synch_count')323 # check that each metahost request has enough hosts under the label324 for label, requested_count in metahost_counts.iteritems():325 available_count = label.host_set.count()326 if requested_count > available_count:327 error = ("You have requested %d %s's, but there are only %d."328 % (requested_count,, available_count))329 raise model_logic.ValidationError({'meta_hosts' : error})330 if atomic_group:331 check_atomic_group_create_job(332 synch_count, host_objects, metahost_objects,333 dependencies, atomic_group, labels_by_name)334 else:335 if synch_count is not None and synch_count > len(all_host_objects):336 raise model_logic.ValidationError(337 {'hosts':338 'only %d hosts provided for job with synch_count = %d' %339 (len(all_host_objects), synch_count)})340 atomic_hosts = models.Host.objects.filter(341 id__in=[ for host in host_objects],342 labels__atomic_group=True)343 unusable_host_names = [host.hostname for host in atomic_hosts]344 if unusable_host_names:345 raise model_logic.ValidationError(...

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?