Best Python code snippet using autotest_python
rpc_utils.py
Source:rpc_utils.py  
...373                one_time_hosts=one_time_hosts,374                atomic_group=atomic_group,375                hostless=hostless)376    return info377def check_for_duplicate_hosts(host_objects):378    host_ids = set()379    duplicate_hostnames = set()380    for host in host_objects:381        if host.id in host_ids:382            duplicate_hostnames.add(host.hostname)383        host_ids.add(host.id)384    if duplicate_hostnames:385        raise model_logic.ValidationError(386            {'hosts': 'Duplicate hosts: %s'387             % ', '.join(duplicate_hostnames)})388def create_new_job(owner, options, host_objects, profiles, metahost_objects,389                   metahost_profiles, atomic_group=None):390    '''391    Create a new job392    :param owner:393    :type owner394    :param options:395    :type options:396    :param host_objects:397    :type host_objects:398    :param profiles:399    :type profiles:400    :param metahost_objects:401    :type metahost_objects:402    :param metahost_profiles:403    :type metahost_profiles:404    :param atomic_group:405    :type atomic_group:406    '''407    labels_by_name = dict((label.name, label)408                          for label in models.Label.objects.all())409    all_host_objects = host_objects + metahost_objects410    all_profiles = profiles + metahost_profiles411    metahost_counts = _get_metahost_counts(metahost_objects)412    dependencies = options.get('dependencies', [])413    synch_count = options.get('synch_count')414    if atomic_group:415        check_atomic_group_create_job(416            synch_count, host_objects, metahost_objects,417            dependencies, atomic_group, labels_by_name)418    else:419        if synch_count is not None and synch_count > len(all_host_objects):420            raise model_logic.ValidationError(421                {'hosts':422                 'only %d hosts provided for job with synch_count = %d' %423                                             (len(all_host_objects), synch_count)})424        atomic_hosts = models.Host.objects.filter(425            id__in=[host.id for host in host_objects],426            labels__atomic_group=True)427        unusable_host_names = [host.hostname for host in atomic_hosts]428        if unusable_host_names:429            raise model_logic.ValidationError(430                {'hosts':431                 'Host(s) "%s" are atomic group hosts but no '432                 'atomic group was specified for this job.' %433                                             (', '.join(unusable_host_names),)})434    check_for_duplicate_hosts(host_objects)435    check_job_dependencies(host_objects, dependencies)436    options['dependencies'] = [labels_by_name[label_name]437                               for label_name in dependencies]438    for label in metahost_objects + options['dependencies']:439        if label.atomic_group and not atomic_group:440            raise model_logic.ValidationError(441                {'atomic_group_name':442                 'Dependency %r requires an atomic group but no '443                 'atomic_group_name or meta_host in an atomic group was '444                 'specified for this job.' % label.name})445        elif (label.atomic_group and446              label.atomic_group.name != atomic_group.name):447            raise model_logic.ValidationError(448                {'atomic_group_name':...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
