def mk_job(job_type='run', status='new', job_template=None, inventory=None, credential=None, project=None, extra_vars={}, persisted=True): job = Job(job_type=job_type, status=status, extra_vars=json.dumps(extra_vars)) job.job_template = job_template job.inventory = inventory if persisted: job.save() job.credentials.add(credential) job.project = project return job
def spawn_bulk_jobs_simple(num): jobs = [] for _ in range(num): j = Job() j.job_template = jt j.status = "canceled" jobs.append(j) with transaction.atomic(): for i, j in enumerate(jobs): if i % 100 == 0: print(i) j.save()
def test_job_relaunch_copy_vars(self, machine_credential, inventory, deploy_jobtemplate, post, mocker, net_credential): job_with_links = Job(name='existing-job', inventory=inventory) job_with_links.job_template = deploy_jobtemplate job_with_links.limit = "my_server" job_with_links.save() job_with_links.credentials.add(machine_credential) job_with_links.credentials.add(net_credential) second_job = job_with_links.copy_unified_job() # Check that job data matches the original variables assert [c.pk for c in second_job.credentials.all()] == [machine_credential.pk, net_credential.pk] assert second_job.inventory == job_with_links.inventory assert second_job.limit == 'my_server' assert net_credential in second_job.credentials.all()
def test_job_relaunch_copy_vars(self, machine_credential, inventory, deploy_jobtemplate, post, mocker, net_credential): job_with_links = Job(name='existing-job', inventory=inventory) job_with_links.job_template = deploy_jobtemplate job_with_links.limit = "my_server" job_with_links.save() job_with_links.credentials.add(machine_credential) job_with_links.credentials.add(net_credential) with mocker.patch( 'awx.main.models.unified_jobs.UnifiedJobTemplate._get_unified_job_field_names', return_value=['inventory', 'credential', 'limit']): second_job = job_with_links.copy_unified_job() # Check that job data matches the original variables assert second_job.credential == job_with_links.credential assert second_job.inventory == job_with_links.inventory assert second_job.limit == 'my_server' assert net_credential in second_job.credentials.all()
def spawn_bulk_jobs(num): jobs = [] for i in range(num): j = Job() j.job_template = jt j.project = project j.playbook = jt.playbook j.inventory = inv j.name = "bulk_{0}".format(i) j.status = "canceled" j.extra_vars = '{"sleeptime": 60}' j.allow_simultaneous = False jobs.append(j) with transaction.atomic(): for i, j in enumerate(jobs): if i % 100 == 0: print(i) time.sleep(.5) j.save() j.credentials.add(cred)