def create_jobdefinition(dci_context, components, test_ids, topic_id, jobdef_name=None): # If at least one component doesn't exist in the database then a new # jobdefinition must be created. at_least_one = False component_ids = [] names = [] for cmpt in components: names.append(cmpt['name']) created_cmpt = component.create(dci_context, **cmpt) if created_cmpt.status_code == 201: at_least_one = True elif created_cmpt.status_code == 422: created_cmpt = component.get(dci_context, cmpt['name']) created_cmpt_name = created_cmpt.json()['component']['name'] component_ids.append(created_cmpt.json()['component']['id']) if at_least_one: if jobdef_name is None: jobdef_name = created_cmpt_name jobdef = jobdefinition.create(dci_context, jobdef_name, topic_id) if jobdef.status_code == 201: jobdef_id = jobdef.json()['jobdefinition']['id'] for cmpt_id in component_ids: jobdefinition.add_component(dci_context, jobdef_id, cmpt_id) for test_id in test_ids: jobdefinition.add_test(dci_context, jobdef_id, test_id) print("Jobdefinition '%s' created." % jobdef_name) else: print("Error on jobdefinition creation: '%s'", jobdef.json()) else: print("No jobdefinition created.")
def job_id(dci_context): my_team = team.create(dci_context, name='tname').json()['team'] my_remoteci = remoteci.create(dci_context, name='tname', team_id=my_team['id'], data={'remoteci': 'remoteci'}).json() my_remoteci_id = my_remoteci['remoteci']['id'] my_test = test.create( dci_context, name='tname', data={'test': 'test'}).json() my_test_id = my_test['test']['id'] my_jobdefinition = jobdefinition.create( dci_context, name='tname', test_id=my_test_id).json() my_component = component.create( dci_context, name='hihi', type='git_review', data={'component': 'component'}).json() my_component_id = my_component['component']['id'] jobdefinition.add_component(dci_context, my_jobdefinition['jobdefinition']['id'], my_component_id) my_job = job.schedule(dci_context, my_remoteci_id).json() return my_job['job']['id']
components = [get_khaleesi_component(), get_khaleesi_settings_component(), get_khaleesi_installer_component(), get_khaleesi_puddle_component()] # If at least one component doesn't exist in the database then a new # jobdefinition must be created. at_least_one = False component_ids = [] for cmpt in components: created_cmpt = component.create(dci_context, **cmpt) if created_cmpt.status_code == 201: print("Create component '%s', type '%s'" % (cmpt['name'], cmpt['type'])) component_ids.append(created_cmpt.json()['component']['id']) at_least_one = True if at_least_one: jobdef_name = "Khaleesi - OSP 8 - FV2" jobdef = jobdefinition.create(dci_context, jobdef_name, khaleesi_tempest_test_id) if jobdef.status_code == 201: jobdef_id = jobdef.json()['jobdefinition']['id'] for cmpt_id in component_ids: jobdefinition.add_component(dci_context, jobdef_id, cmpt_id) print("Jobdefinition '%s' created." % jobdef_name) else: print("Error on jobdefinition creation: '%s'", jobdef.json()) else: print("No jobdefinition created.")