def refresh_puddles(ctx): versions = [ { 'name': '10.0', 'urls': [ 'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/10.0-RHEL-7/latest/RH7-RHOS-10.0.repo', # noqa ], 'topic_id': dci_topic.get(ctx, 'OSP10').json()['topic']['id'] }, { 'name': '9.0', 'urls': [ 'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/9.0-RHEL-7/latest/RH7-RHOS-9.0.repo', # noqa 'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/9.0-RHEL-7-director/latest/RH7-RHOS-9.0-director.repo'], # noqa 'topic_id': dci_topic.get(ctx, 'OSP9').json()['topic']['id'] }, { 'name': '8.0', 'urls': [ 'http://download.eng.bos.redhat.com/rel-eng/OpenStack/8.0-RHEL-7/latest/RH7-RHOS-8.0.repo', # noqa 'http://download.eng.bos.redhat.com/rel-eng/OpenStack/8.0-RHEL-7-director/latest/RH7-RHOS-8.0-director.repo'], # noqa 'topic_id': dci_topic.get(ctx, 'OSP8').json()['topic']['id'] } ] for v in versions: components = get_components(v['urls'], v['topic_id']) for c in components: dci_component.create(ctx, **c) r = dci_component.get(ctx, c['name'], embed='file') if r.status_code == 401: continue if r.status_code == 404: print('Component %s not found' % c['name']) exit(1) component = r.json()['component'] r_current_components = dci_component.file_list( ctx, id=component['id']) if len(r_current_components.json()['component_files']): print('%s already has its data. Skipped.' % component['name']) continue clean_up(component) prepare_archive(component) print('Uploading bits...') r = dci_component.file_upload( ctx, id=component['id'], file_path='archive.tar') if r.status_code != 201: print(( ' Upload of archive.tar has ' 'failed for component %s: %s') % ( component['name'], r.text)) exit(1) else: print(' success: %s' % r.json()) clean_up(component)
def test_job_upgraded(dci_context, job_id, topic_id, product_id): old = topic.get(dci_context, id=topic_id).json()["topic"] new = topic.create(dci_context, "bar_topic", ["type_1"], product_id=product_id) t = new.json()["topic"] component.create(dci_context, "bar_component", "type_1", t["id"]) topic.update(dci_context, id=topic_id, etag=old["etag"], next_topic_id=t["id"]) r = job.upgrade(dci_context, job_id=job_id) assert r.status_code == 201 assert r.json()["job"]["previous_job_id"] == job_id
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 create(context, name, type, canonical_project_name, data, title, message, url, topic_id, export_control): """create(context, name, type, canonical_project_name, data, title, message, url, topic_id, export_control) # noqa Create a component. >>> dcictl component-create [OPTIONS] :param string name: Name of the component [required] :param string type: Type of the component [required] :param string topic_id: ID of the topic to associate with [required] :param string canonical_project_name: Project name :param json data: JSON to pass to the component :param string title: Title of the component :param string message: Message for the component :param string url: URL resource to monitor :parma bool export_control: Set the component visible for users """ data = json.loads(data) result = component.create( context, name=name, type=type, canonical_project_name=canonical_project_name, data=data, title=title, message=message, url=url, topic_id=topic_id, export_control=export_control ) utils.format_output(result, context.format, None, component.TABLE_HEADERS)
def components_ids(dci_context, topic_id): ids = [] kwargs = { "name": "component1", "type": "type_1", "data": { "component": "component" }, "topic_id": topic_id, } component = api_component.create(dci_context, **kwargs).json() ids.append(component["component"]["id"]) kwargs["name"] = "component2" kwargs["type"] = "type_2" component = api_component.create(dci_context, **kwargs).json() ids.append(component["component"]["id"]) return ids
def create(context, name, type, canonical_project_name, data, sha, title, message, url, git, ref): data = json.loads(data) result = component.create( context, name=name, type=type, canonical_project_name=canonical_project_name, data=data, sha=sha, title=title, message=message, url=url, git=git, ref=ref ).json() utils.format_output(result, context.format, component.RESOURCE[:-1])
def component_id(dci_context, topic_id): kwargs = { "name": "component1", "type": "git_review", "data": { "component": "component" }, "topic_id": topic_id, } component = api_component.create(dci_context, **kwargs).json() return component["component"]["id"]
def create(context, args): params = { k: getattr(args, k) for k in [ "name", "type", "canonical_project_name", "title", "message", "url", "topic_id", "state", "data", ] } params["data"] = validate_json(context, "data", params["data"]) params["state"] = active_string(params["state"]) return component.create(context, **params)
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']
if __name__ == '__main__': dci_context = context.build_dci_context() # Create Khaleesi-tempest test khaleesi_tempest_test_id = get_test_id(dci_context, 'Khaleesi-tempest') 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)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # dci_login=dict(required=False, type='str'), dci_password=dict(required=False, type='str'), dci_cs_url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), dest=dict(type='str'), export_control=dict(type='bool'), name=dict(type='str'), type=dict(type='str'), canonical_project_name=dict(type='str'), url=dict(type='str'), data=dict(type='dict'), topic_id=dict(type='str'), path=dict(type='str'), ), ) if not dciclient_found: module.fail_json(msg='The python dciclient module is required') login, password, url = get_details(module) if not login or not password: module.fail_json(msg='login and/or password have not been specified') ctx = dci_context.build_dci_context(url, login, password, 'Ansible') # Action required: Delete the component matching the component id # Endpoint called: /components/<component_id> DELETE via dci_component.delete() # # If the component exist and it has been succesfully deleted the changed is # set to true, else if the file does not exist changed is set to False if module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_component.delete(ctx, module.params['id']) # Action required: Attach a file to a component # Endpoint called: /components/<component_id>/files/ POST via dci_component.file_upload() # # Attach file to a component elif module.params['path']: res = dci_component.file_upload(ctx, module.params['id'], module.params['path']) # Action required: Download a component # Endpoint called: /components/<component_id>/files/<file_id>/content GET via dci_component.file_download() # # Download the component elif module.params['dest']: component_file = dci_component.file_list( ctx, module.params['id']).json()['component_files'][0] res = dci_component.file_download(ctx, module.params['id'], component_file['id'], module.params['dest']) # Action required: Get component informations # Endpoint called: /components/<component_id> GET via dci_component.get() # # Get component informations elif module.params['id'] and module.params['export_control'] is None: res = dci_component.get(ctx, module.params['id']) # Action required: Update an existing component # Endpoint called: /components/<component_id> PUT via dci_component.update() # # Update the component with the specified parameters. elif module.params['id']: res = dci_component.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: updated_kwargs = { 'id': module.params['id'], 'etag': res.json()['component']['etag'] } if module.params['export_control'] is not None: updated_kwargs['export_control'] = module.params[ 'export_control'] res = dci_component.update(ctx, **updated_kwargs) # Action required: Create a new component # Endpoint called: /component POST via dci_component.create() # # Create a new component else: if not module.params['name']: module.fail_json(msg='name parameter must be speficied') if not module.params['type']: module.fail_json(msg='type parameter must be speficied') kwargs = { 'name': module.params['name'], 'type': module.params['type'], } if module.params['canonical_project_name']: kwargs['canonical_project_name'] = module.params[ 'canonical_project_name'] if module.params['url']: kwargs['url'] = module.params['url'] if module.params['data']: kwargs['data'] = module.params['data'] if module.params['topic_id']: kwargs['topic_id'] = module.params['topic_id'] res = dci_component.create(ctx, **kwargs) try: result = res.json() if res.status_code == 404: module.fail_json(msg='The resource does not exist') if res.status_code == 409: result = dci_component.get(ctx, module.params['name']).json() if res.status_code in [400, 401, 409]: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)