def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), login=dict(required=False, type='str'), password=dict(required=False, type='str'), path=dict(type='str'), name=dict(required=False, type='str'), mime=dict(default='text/plain', type='str'), job_id=dict(type='str'), url=dict(required=False, type='str'), ), ) if not requests_found: module.fail_json(msg='The python requests 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') name = module.params['path'] if module.params['name']: name = module.params['name'] dci_file.create(ctx, name=name, content=open(module.params['path'], 'r').read(), mime=module.params['mime'], job_id=module.params['job_id']) module.exit_json(changed=True)
def main(): module = AnsibleModule(argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), login=dict(required=False, type='str'), password=dict(required=False, type='str'), topic=dict(required=False, type='str'), remoteci=dict(type='str'), url=dict(required=False, type='str'), ), ) if not requests_found: module.fail_json(msg='The python requests module is required') topic_list = [module.params['topic'], os.getenv('DCI_TOPIC')] topic = next((item for item in topic_list if item is not None), None) 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') topic_id = dci_topic.get(ctx, topic).json()['topic']['id'] remoteci = dci_remoteci.get(ctx, module.params['remoteci']).json() remoteci_id = remoteci['remoteci']['id'] dci_job.schedule(ctx, remoteci_id, topic_id=topic_id) jb = dci_job.get_full_data(ctx, ctx.last_job_id) jb['job_id'] = ctx.last_job_id module.exit_json(**jb)
def get_values(job): context = build_dci_context() values = [] values.append("https://www.distributed-ci.io/jobs/" + job["id"]) values.append(job["id"]) values.append(job["content"]) values.append(job["stage_of_failure"]) if job["is_user_text"]: values.append("1") else: values.append("0") if job["is_sut"]: values.append("1") else: values.append("0") if job["is_install"]: values.append("1") else: values.append("0") if job["is_logs"]: values.append("1") else: values.append("0") if job["is_dci_rhel_cki"]: values.append("1") else: values.append("0") if job["error_type"]: values.append(job["error_type"]) else: values.append("None") return values
def change_content_to_wait_system_to_be_installed( job, files_for_jobstate_before_failure): context = build_dci_context() for file in files_for_jobstate_before_failure: if file['name'] == "Wait system to be installed": job["content"] = get_content_for_file(file["id"]) return job["content"] return None
def main(dci_login, dci_password, dci_cs_url, dci_topic_id): dci_context = context.build_dci_context(dci_cs_url, dci_login, dci_password) components = get_components(dci_context, CANDIDATES_URL, dci_topic_id) test_id = helper.get_test_id(dci_context, 'scenario01', dci_topic_id) helper.create_jobdefinition(dci_context, components, [test_id], dci_topic_id)
def main(dci_login, dci_password, dci_cs_url, dci_topic_id, github_url): dci_context = context.build_dci_context(dci_cs_url, dci_login, dci_password) components = get_components(dci_topic_id, github_url) test_id = helper.get_test_id(dci_context, components[0]['name'], dci_topic_id) helper.create_jobdefinition(dci_context, components, [test_id], dci_topic_id)
def main(dci_login, dci_password, dci_cs_url, topic_id, partner_token): dci_context = context.build_dci_context(dci_cs_url, dci_login, dci_password) # Create Khaleesi-tempest test test_id = helper.get_test_id(dci_context, 'tempest', topic_id) server = 'partners.redhat.com' base_dir = '/' + partner_token + '/OpenStack/8.0' ftp = ftplib.FTP(server) ftp.login() ftp.cwd(base_dir) beta = {} repo_file_mapping = { 'OSP-8': 'RH7-RHOS-8.0.repo', 'OSP-8-director': 'RH7-RHOS-8.0-director.repo', } for i in ftp.nlst(): m = re.search('(OSP-8-director|OSP-8)-Beta-(\d+)', i) if not m: continue directory = m.group(0) repo_type = m.group(1) # OSP-8 / OSP-8-director version = int(m.group(2)) # 8 if version not in beta: beta[version] = {} beta[version][repo_type] = directory cur = {} for v in sorted(beta, reverse=True): cur.update(beta[v]) components = [] for repo_type, directory in cur.items(): repo_file = repo_file_mapping[repo_type] lines = [] ftp.retrlines( 'retr ' + base_dir + '/' + directory + '/' + repo_file, lines.append) repo_file_raw_content = '\n'.join(lines) c = get_puddle_component( repo_file_raw_content, topic_id) components.append(c) tmp = [] for c in components: tmp.append(c['data']['repo_name'] + ' ' + c['data']['version']) jobdef_name = 'OSP 8 - ' + '+'.join(tmp) helper.create_jobdefinition(dci_context, components, [test_id], topic_id, jobdef_name=jobdef_name) break
def add_clasification(job_id, result): context = build_dci_context() print("Updating Label after ML engine run") r = dci_analytics.create( context, job_id=job_id, name="", type="", url="http://example.com", data=result, )
def get_failed_jobs_for_product(product_id): context = build_dci_context() num_of_jobs = dci_job.list(context, where=f"product_id:{product_id},status:failure", limit=1, offset=0).json()["_meta"]["count"] offset = 0 limit = 100 jobs = [] while offset < num_of_jobs: jobs_list = dci_job.list( context, where=f"product_id:{product_id},status:failure", limit=limit, offset=offset, embed="remoteci,jobstates", ).json()["jobs"] jobs = jobs + jobs_list offset += limit return jobs
def enhance_job(job, first_jobstate_failure, files): context = build_dci_context() files_sorted = sort_by_created_at(files) first_file = files_sorted[0] content = get_content_for_file(first_file["id"]) job["content"] = content jobstate_before_failure = get_jobstate_before_failure( get_jobstates_with_files(job["id"])) files_for_jobstate_before_failure = get_files_for_jobstate( jobstate_before_failure["id"]) job["stage_of_failure"] = first_jobstate_failure["comment"] if job["stage_of_failure"] == "Gathering Facts": job["content"] = change_content_to_wait_system_to_be_installed( job, files_for_jobstate_before_failure) if job["content"] is None: job["content"] = content job["is_user_text"] = check_if_file_is_in_files( files_for_jobstate_before_failure, "/hooks/user-tests.yml", ) job["is_sut"] = check_if_file_is_in_files( files_for_jobstate_before_failure, "include_tasks: sut.yml") job["is_install"] = check_if_file_is_in_files( files_for_jobstate_before_failure, "include_tasks: install.yml") job["is_logs"] = check_if_file_is_in_files( files_for_jobstate_before_failure, "include_tasks: logs.yml") if "dci-rhel-cki" in files_sorted[0]["name"]: job["is_dci_rhel_cki"] = True else: job["is_dci_rhel_cki"] = False try: job["error_type"] = job["analytics"][0]["data"]["error_type"] except Exception: job["error_type"] = None return job
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), dci_login=dict(required=False, type='str'), dci_password=dict(required=False, type='str'), dci_cs_url=dict(required=False, type='str'), undercloud_ip=dict(type='str'), undercloud_user=dict(required=False, default='stack', type='str'), remoteci=dict(type='str'), job_id=dict(type='str'), key_filename=dict(default='text/plain', type='str'), stack_name=dict(required=False, default='overcloud', type='str'), ), ) if not requests_found: module.fail_json(msg='The python requests 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') last_js = dci_job.list_jobstates(ctx, module.params['job_id']).json()['jobstates'][0] ctx.last_job_id = last_js['job_id'] ctx.last_jobstate_id = last_js['id'] dci_tripleo_helper.run_tests( ctx, undercloud_ip=module.params['undercloud_ip'], key_filename=module.params['key_filename'], remoteci_id=module.params['remoteci'], stack_name=module.params['stack_name'], user=module.params['undercloud_user']) module.exit_json(changed=True)
def test_data(job_id): context = build_dci_context() csv_file_name = create_csv_file_name() create_csv_file_with_headers(csv_file_name, headers) try: r = dci_job.get(context, id=job_id, limit=1, offset=0, embed="remoteci,jobstates") job = r.json()["job"] first_jobstate_failure = get_first_jobstate_failure(job["jobstates"]) first_jobstate_failure_id = first_jobstate_failure["id"] files = get_files_for_jobstate(first_jobstate_failure_id) job = enhance_job(job, first_jobstate_failure, files) job_values = get_values(job) append_job_to_csv(csv_file_name, job_values) except Exception: return 0, False data = pd.read_csv(csv_file_name) return data, True
def main(): args = parse_arguments(sys.argv[1:], os.environ) dci_cs_url = args.dci_cs_url dci_login = args.dci_login dci_password = args.dci_password context = None if dci_login is not None and dci_password is not None: context = dci_context.build_dci_context(dci_login=dci_login, dci_password=dci_password, dci_cs_url=dci_cs_url) sso_url = args.sso_url sso_username = args.sso_username sso_password = args.sso_password sso_token = args.sso_token refresh_sso_token = args.refresh_sso_token if (sso_url is not None and sso_username is not None and sso_password is not None) or sso_token is not None: context = dci_context.build_sso_context( dci_cs_url, sso_url, sso_username, sso_password, sso_token, refresh=refresh_sso_token, ) dci_client_id = args.dci_client_id dci_api_secret = args.dci_api_secret if dci_client_id is not None and dci_api_secret is not None: context = dci_context.build_signature_context( dci_cs_url=dci_cs_url, dci_client_id=dci_client_id, dci_api_secret=dci_api_secret, ) if not context: print("No credentials provided.") sys.exit(1) response = run(context, args) print_response(response, args.format, args.verbose)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), dest=dict(type='str'), export_control=dict(type='bool'), #title=dict(type='str'), #message=dict(type='str'), #canonical_project_name=dict(type='str'), #component_url=dict(type='str'), #type=dict(type='str'), #active=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: 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, 422]: 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: # TODO module.fail_json(msg='Not implemented yet') # kwargs = {} # if module.params['export_control']: # kwargs['export_control'] = module.params['export_control'] #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 in [400, 401, 422]: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), priority=dict(type='int'), topic_id=dict(type='str'), active=dict(type='bool'), comment=dict(type='str'), component_types=dict(type='list'), ), ) 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 jobdefinition matching jobdefinition id # Endpoint called: /jobdefinitions/<jobdefinition_id> DELETE via dci_jobdefinition.delete() # # If the jobdefinition exists and it has been succesfully deleted the changed is # set to true, else if the jobdefinition 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_jobdefinition.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['jobdefinition']['etag'] } res = dci_jobdefinition.delete(ctx, **kwargs) # Action required: Retrieve jobdefinition informations # Endpoint called: /jobdefinitions/<jobdefinition_id> GET via dci_jobdefinition.get() # # Get jobdefinition informations elif module.params[ 'id'] and not module.params['comment'] and not module.params[ 'component_types'] and module.params['active'] is None: res = dci_jobdefinition.get(ctx, module.params['id']) # Action required: Update an existing jobdefinition # Endpoint called: /jobdefinitions/<jobdefinition_id> PUT via dci_jobdefinition.update() # # Update the jobdefinition with the specified characteristics. elif module.params['id']: res = dci_jobdefinition.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['jobdefinition']['etag'] } if module.params['comment']: kwargs['comment'] = module.params['comment'] if module.params['component_types']: kwargs['component_types'] = module.params['component_types'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_jobdefinition.update(ctx, **kwargs) # Action required: Creat a jobdefinition with the specified content # Endpoint called: /jobdefinitions POST via dci_jobdefinition.create() # # Create the new jobdefinition. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['topic_id']: module.fail_json(msg='topic_id parameter must be specified') kwargs = { 'name': module.params['name'], 'topic_id': module.params['topic_id'] } if module.params['priority']: kwargs['priority'] = module.params['priority'] if module.params['comment']: kwargs['comment'] = module.params['comment'] if module.params['component_types']: kwargs['component_types'] = module.params['component_types'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_jobdefinition.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 == 422: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
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'), content=dict(type='str'), path=dict(type='str'), name=dict(type='str'), job_id=dict(type='str'), jobstate_id=dict(type='str'), mime=dict(default='text/plain', 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: List all files # Endpoint called: /files GET via dci_file.list() # # List all files if module_params_empty(module.params): res = dci_file.list(ctx) # Action required: Delete the file matchin file id # Endpoint called: /files/<file_id> DELETE via dci_file.delete() # # If the file 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 elif module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_file.delete(ctx, module.params['id']) # Action required: Retrieve file informations # Endpoint called: /files/<file_id> GET via dci_job.file() # # Get file informations elif module.params['id']: res = dci_file.get(ctx, module.params['id']) # Action required: Creat a file with the specified content # Endpoint called: /files POST via dci_file.create() # # Create the file and attach it where it belongs (either jobstate or job) # with the specified content/content of path provided. # # NOTE: /files endpoint does not support PUT method, hence no update can # be accomplished. else: if not module.params['job_id'] and not module.params['jobstate_id']: module.fail_json(msg='Either job_id or jobstate_id must be specified') if (not module.params['content'] and not module.params['path']) or \ (module.params['content'] and module.params['path']): module.fail_json(msg='Either content or path must be specified') if module.params['content'] and not module.params['name']: module.fail_json(msg='name parameter must be specified when content has been specified') if module.params['path'] and not module.params['name']: name = module.params['path'] else: name = module.params['name'] if module.params['path']: try: content = open(module.params['path'], 'r').read() except IOError as e: module.fail_json(msg='The path specified cannot be read') else: content = module.params['content'] kwargs = {'name': name, 'content': content, 'mime': module.params['mime']} if module.params['job_id']: kwargs['job_id'] = module.params['job_id'] if module.params['jobstate_id']: kwargs['jobstate_id'] = module.params['jobstate_id'] res = dci_file.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['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
options.connection = 'local' # Need a connection type "smart" or "ssh" options.become = False runner = helper_ansible.Runner( playbook = './ansible/site.yml', inventory_file = "./ansible/inventory", options = options ) result, stats = runner.run() return result # Our DCI connection dci_context = dci_context.build_dci_context( 'http://127.0.0.1', 'remoteci_1', 'welcome') # RemoteCI id and Topic id -- probably better to be dynamically passed in dci_context.remoteci_id = 'fd6c285c-fa57-4aa8-a8b3-c68a4acdfa9c' dci_context.topic_id = 'fe145e49-992a-4843-a44f-b058c7a05261' # schedule the job and pull down data dci_context.job_id = dci_job.schedule(dci_context, remoteci_id=dci_context.remoteci_id, topic_id=dci_context.topic_id).json()['job']['id'] job_full_data = dci_job.get_full_data(dci_context, dci_context.job_id) # create initial jobstate of pre-run jobstate = dci_jobstate.create(dci_context, 'pre-run', 'Initializing the environment', dci_context.job_id)
def get_content_for_file(file_id): context = build_dci_context() r = dci_file.content(context, id=file_id) r.raise_for_status() return r.text
def get_jobstates_with_files(job_id): context = build_dci_context() r = dci_job.list_jobstates(context, id=job_id, embed="files") r.raise_for_status() return r.json()["jobstates"]
def get_product_id_by_name(product_name): context = build_dci_context() r = dci_product.list(context, where=f"name:{product_name}") product_id = r.json()["products"][0]["id"] return product_id
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'), name=dict(type='str'), data=dict(type='dict'), team_id=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 test matching test id # Endpoint called: /tests/<test_id> DELETE via dci_test.delete() # # If the test exists and it has been succesfully deleted the changed is # set to true, else if the test 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_test.delete(ctx, module.params['id']) # Action required: Retrieve test informations # Endpoint called: /tests/<test_id> GET via dci_test.get() # # Get test informations elif module.params['id']: res = dci_test.get(ctx, module.params['id']) # Action required: Create a test with the specified content # Endpoint called: /tests POST via dci_test.create() # # Create the new test. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['team_id']: module.fail_json(msg='team_id parameter must be specified') kwargs = { 'name': module.params['name'], 'team_id': module.params['team_id'], } if module.params['data']: kwargs['data'] = module.params['data'] res = dci_test.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['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def cli(os_auth_url, os_username, os_password, os_tenant_name, host0_ip, undercloud_ip, config_file): config = yaml.load(config_file) ssh = config['ssh'] host0 = None vm_undercloud = None dci_context = dcicontext.build_dci_context( config['dci']['control_server_url'], config['dci']['login'], config['dci']['password']) logger.setup_logging(dci_context) status = 'pre-run' job = dcijob.schedule(dci_context, remoteci_id=config['dci']['remoteci_id']).json() job_id = job['job']['id'] try: if host0_ip: dcijobstate.create(dci_context, status, 'Reusing existing host0', job_id) host0 = rdomhelper.host0.Host0( hostname=host0_ip, user=config['provisioner']['image'].get('user', 'root'), key_filename=ssh['private_key']) if undercloud_ip: dcijobstate.create(dci_context, status, 'Reusing existing undercloud', job_id) vm_undercloud = undercloud.Undercloud( undercloud_ip, user='******', via_ip=host0_ip, key_filename=ssh['private_key']) if not host0: dcijobstate.create(dci_context, status, 'Creating the host0', job_id) host0 = deploy_host0(os_auth_url, os_username, os_password, os_tenant_name, config) if not vm_undercloud: dcijobstate.create(dci_context, status, 'Creating the undercloud', job_id) host0.enable_repositories(config['provisioner']['repositories']) host0.install_nosync() host0.create_stack_user() host0.deploy_hypervisor() vm_undercloud = host0.instack_virt_setup( config['undercloud']['guest_image_path'], config['undercloud']['guest_image_checksum'], rhsm_login=config['rhsm']['login'], rhsm_password=config['rhsm'].get('password', os.environ.get('RHN_PW'))) status = 'running' dcijobstate.create(dci_context, status, 'Configuring the undercloud', job_id) vm_undercloud.enable_repositories(config['undercloud']['repositories']) vm_undercloud.install_nosync() vm_undercloud.create_stack_user() vm_undercloud.install_base_packages() vm_undercloud.clean_system() vm_undercloud.update_packages() vm_undercloud.install_osp() vm_undercloud.start_overcloud() dcijobstate.create(dci_context, 'success', 'Job succeed :-)', job_id) except Exception as e: LOG.error(traceback.format_exc()) dcijobstate.create(dci_context, 'failure', 'Job failed :-(', job_id) raise e
def get_dci_context(**args): args['user_agent'] = 'dci-agent-' + version return dci_context.build_dci_context(**args)
def get_files_for_jobstate(jobstate_id): context = build_dci_context() r = dci_jobstate.get(context, id=jobstate_id, embed="files") r.raise_for_status() return r.json()["jobstate"]["files"]
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), topic=dict(required=False, type='str'), remoteci=dict(type='str'), comment=dict(type='str'), status=dict(type='str'), configuration=dict(type='dict'), ), ) if not dciclient_found: module.fail_json(msg='The python dciclient module is required') topic_list = [module.params['topic'], os.getenv('DCI_TOPIC')] topic = next((item for item in topic_list if item is not None), None) 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 job matching the job id # Endpoint called: /jobs/<job_id> DELETE via dci_job.delete() # # If the job 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_job.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['job']['etag'] } res = dci_job.delete(ctx, **kwargs) # Action required: Retrieve job informations # Endpoint called: /jobs/<job_id> GET via dci_job.get() # # Get job informations elif module.params[ 'id'] and not module.params['comment'] and not module.params[ 'status'] and not module.params['configuration']: res = dci_job.get(ctx, module.params['id']) # Action required: Update an existing job # Endpoint called: /jobs/<job_id> PUT via dci_job.update() # # Update the job with the specified characteristics. elif module.params['id']: res = dci_job.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['job']['etag'] } if module.params['comment']: kwargs['comment'] = module.params['comment'] if module.params['status']: kwargs['status'] = module.params['status'] if module.params['configuration']: kwargs['configuration'] = module.params['configuration'] res = dci_job.update(ctx, **kwargs) # Action required: Schedule a new job # Endpoint called: /jobs/schedule POST via dci_job.schedule() # # Schedule a new job against the DCI Control-Server else: topic_id = dci_topic.get(ctx, topic).json()['topic']['id'] remoteci = dci_remoteci.get(ctx, module.params['remoteci']).json() remoteci_id = remoteci['remoteci']['id'] res = dci_job.schedule(ctx, remoteci_id, topic_id=topic_id) if res.status_code not in [400, 401, 404, 422]: res = dci_job.get_full_data(ctx, ctx.last_job_id) try: result = res.json() if res.status_code == 404: module.fail_json(msg='The resource does not exist') if res.status_code in [400, 401, 422]: result['changed'] = False else: result['changed'] = True except AttributeError: # Enter here if new job has been schedule, return of get_full_data is already json. result = res result['changed'] = True result['job_id'] = ctx.last_job_id except: result = {} result['changed'] = True module.exit_json(**result)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), label=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: List all topics # Endpoint called: /topics GET via dci_topic.list() # # List all topics if module_params_empty(module.params): res = dci_topic.list(ctx) # Action required: Delete the topic matching topic id # Endpoint called: /topics/<topic_id> DELETE via dci_topic.delete() # # If the topic exists and it has been succesfully deleted the changed is # set to true, else if the topic does not exist changed is set to False elif module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_topic.delete(ctx, module.params['id']) # Action required: Retrieve topic informations # Endpoint called: /topic/<topic_id> GET via dci_topic.get() # # Get topic informations elif module.params[ 'id'] and not module.params['name'] and not module.params['label']: res = dci_topic.get(ctx, module.params['id']) # Action required: Update an existing topic # Endpoint called: /topics/<topic_id> PUT via dci_topic.update() # # Update the topic with the specified characteristics. elif module.params['id']: res = dci_topic.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['topic']['etag'] } if module.params['name']: kwargs['name'] = module.params['name'] if module.params['label']: kwargs['label'] = module.params['label'] res = dci_topic.update(ctx, **kwargs) # Action required: Creat a topic with the specified content # Endpoint called: /topics POST via dci_topic.create() # # Create the new topic. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') kwargs = {'name': module.params['name']} if module.params['label']: kwargs['label'] = module.params['label'] res = dci_topic.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_topic.get(ctx, module.params['name']).json() result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def cli(os_auth_url, os_username, os_password, os_tenant_name, host0_ip, undercloud_ip, config_file): config = yaml.load(config_file) ssh = config['ssh'] host0 = None vm_undercloud = None dci_context = dcicontext.build_dci_context( config['dci']['control_server_url'], config['dci']['login'], config['dci']['password']) logger.setup_logging(dci_context) status = 'pre-run' job = dcijob.schedule(dci_context, remoteci_id=config['dci']['remoteci_id']).json() job_id = job['job']['id'] try: if host0_ip: dcijobstate.create(dci_context, status, 'Reusing existing host0', job_id) host0 = rdomhelper.host0.Host0(hostname=host0_ip, user=config['provisioner']['image'].get('user', 'root'), key_filename=ssh['private_key']) if undercloud_ip: dcijobstate.create(dci_context, status, 'Reusing existing undercloud', job_id) vm_undercloud = undercloud.Undercloud(undercloud_ip, user='******', via_ip=host0_ip, key_filename=ssh['private_key']) if not host0: dcijobstate.create(dci_context, status, 'Creating the host0', job_id) host0 = deploy_host0(os_auth_url, os_username, os_password, os_tenant_name, config) if not vm_undercloud: dcijobstate.create(dci_context, status, 'Creating the undercloud', job_id) host0.enable_repositories(config['provisioner']['repositories']) host0.install_nosync() host0.create_stack_user() host0.deploy_hypervisor() vm_undercloud = host0.instack_virt_setup( config['undercloud']['guest_image_path'], config['undercloud']['guest_image_checksum'], rhsm_login=config['rhsm']['login'], rhsm_password=config['rhsm'].get('password', os.environ.get('RHN_PW'))) status = 'running' dcijobstate.create(dci_context, status, 'Configuring the undercloud', job_id) vm_undercloud.enable_repositories(config['undercloud']['repositories']) vm_undercloud.install_nosync() vm_undercloud.create_stack_user() vm_undercloud.install_base_packages() vm_undercloud.clean_system() vm_undercloud.update_packages() vm_undercloud.install_osp() vm_undercloud.start_overcloud() dcijobstate.create(dci_context, 'success', 'Job succeed :-)', job_id) except Exception as e: LOG.error(traceback.format_exc()) dcijobstate.create(dci_context, 'failure', 'Job failed :-(', job_id) raise e
def cli(ctx, dci_login, dci_password, dci_cs_url, format): context = dci_context.build_dci_context(dci_login=dci_login, dci_password=dci_password, dci_cs_url=dci_cs_url) context.format = format ctx.obj = context
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), passwd=dict(type='str'), role=dict(choices=['user', 'admin'], type='str'), team_id=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 user matching user id # Endpoint called: /users/<user_id> DELETE via dci_user.delete() # # If the user exists and it has been succesfully deleted the changed is # set to true, else if the user 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_user.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['user']['etag'] } res = dci_user.delete(ctx, **kwargs) # Action required: Retrieve user informations # Endpoint called: /user/<user_id> GET via dci_user.get() # # Get user informations elif module.params['id'] and not module.params[ 'name'] and not module.params['passwd'] and not module.params[ 'role'] and not module.params['team_id']: res = dci_user.get(ctx, module.params['id']) # Action required: Update an user # Endpoint called: /users/<user_id> PUT via dci_user.update() # # Update the user with the specified characteristics. elif module.params['id']: res = dci_user.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['user']['etag'] } if module.params['name']: kwargs['name'] = module.params['name'] if module.params['password']: kwargs['password'] = module.params['passwd'] if module.params['role']: kwargs['role'] = module.params['role'] if module.params['team_id']: kwargs['team_id'] = module.params['team_id'] res = dci_user.update(ctx, **kwargs) # Action required: Create a user with the specified content # Endpoint called: /users POST via dci_user.create() # # Create the new user. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['passwd']: module.fail_json(msg='passwd parameter must be specified') if not module.params['team_id']: module.fail_json(msg='team_id parameter must be specified') if not module.params['role']: role = 'user' kwargs = { 'name': module.params['name'], 'password': module.params['passwd'], 'role': role, 'team_id': module.params['team_id'], } res = dci_user.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 == 422: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def _build_dci_context(self): return dci_context.build_dci_context(os.getenv('DCI_CS_URL'), os.getenv('DCI_LOGIN'), os.getenv('DCI_PASSWORD'), 'ansible')
def main(dci_login, dci_password, dci_cs_url): ctx = dci_context.build_dci_context(dci_cs_url, dci_login, dci_password) refresh_puddles(ctx)
print("Missing environment variables DCI_CS_URL=%s, DCI_LOGIN=%s," "DCI_PASSWORD=%s" % (dci_cs_url, dci_login, dci_password)) sys.exit(1) gfilter = {"black_teams": [], "white_topics": []} if len(sys.argv) > 1: filter_file_path = sys.argv[1] if not os.path.exists(filter_file_path): print("File %s does not exists." % filter_file_path) sys.exit(1) # get the filtering rules gfilter = json.loads(open('./%s' % filter_file_path).read()) gcontext = dci_context.build_dci_context(dci_cs_url=dci_cs_url, dci_login=dci_login, dci_password=dci_password) # to get the last job of a remoteci, we loop over all job sorted by date # and get the first status to have the last status of a remoteci. print("[*] Get all jobs") ljobs = [ r for r in base.iter(gcontext, 'jobs', sort='-created_at', embed='components,jobdefinition', limit=128) ] # get all topics to get the association topic_id -> topic_name # which will be used below
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'), name=dict(type='str'), data=dict(type='dict'), active=dict(type='bool'), team_id=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: List all remotecis # Endpoint called: /remotecis GET via dci_remoteci.list() # # List all remotecis if module_params_empty(module.params): res = dci_remoteci.list(ctx) # Action required: Delete the remoteci matching remoteci id # Endpoint called: /remotecis/<remoteci_id> DELETE via dci_remoteci.delete() # # If the remoteci exists and it has been succesfully deleted the changed is # set to true, else if the remoteci does not exist changed is set to False elif module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_remoteci.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['remoteci']['etag'] } res = dci_remoteci.delete(ctx, **kwargs) # Action required: Retrieve remoteci informations # Endpoint called: /remotecis/<remoteci_id> GET via dci_remoteci.get() # # Get remoteci informations elif module.params['id'] and not module.params[ 'name'] and not module.params['data'] and not module.params[ 'team_id'] and module.params['active'] is None: res = dci_remoteci.get(ctx, module.params['id']) # Action required: Update an existing remoteci # Endpoint called: /remotecis/<remoteci_id> PUT via dci_remoteci.update() # # Update the remoteci with the specified characteristics. elif module.params['id']: res = dci_remoteci.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['remoteci']['etag'] } if module.params['name']: kwargs['name'] = module.params['name'] if module.params['data']: kwargs['data'] = module.params['data'] if module.params['team_id']: kwargs['team_id'] = module.params['team_id'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] open('/tmp/tuiti', 'w').write(str(kwargs.keys())) res = dci_remoteci.update(ctx, **kwargs) # Action required: Create a remoteci with the specified content # Endpoint called: /remotecis POST via dci_remoteci.create() # # Create the new remoteci. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['team_id']: module.fail_json(msg='team_id parameter must be specified') kwargs = { 'name': module.params['name'], 'team_id': module.params['team_id'] } if module.params['data']: kwargs['data'] = module.params['data'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_remoteci.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['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
'2015-12-03.1' } } } return khaleesi_puddle_component def get_test_id(dci_context, name): print("Use test '%s'" % name) test.create(dci_context, name) return test.get(dci_context, name).json()['test']['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:
from jobstates import get_first_jobstate_failure, get_jobstate_before_failure from csv_manipulations import ( remove_current_csv, create_csv_file_name, create_csv_file_with_headers, append_job_to_csv, ) from file_is_in_files import check_if_file_is_in_files headers = [ "Job_link", "Job_ID", "Error_Message", "Stage_of_Failure", "Is_user_text.yml", "Is_SUT.yml", "Is_install.yml", "Is_logs.yml", "Is_dci-rhel-cki", "Error_Type" ] context = build_dci_context() LOG = logging.getLogger(__name__) logging.getLogger().setLevel(logging.INFO) def get_product_id_by_name(product_name): r = dci_product.list(context, where=f"name:{product_name}") product_id = r.json()["products"][0]["id"] return product_id def get_files_for_jobstate(jobstate_id): r = dci_jobstate.get(context, id=jobstate_id, embed="files") r.raise_for_status() return r.json()["jobstate"]["files"]