def show(cmd, test_id, run_id=None, wait=False, poll_interval=3, base_url=None): final_statuses = [ Status.failed.value, Status.completed.value, Status.cancelled.value, ] ap = AICSProvider(cmd, base_url) if run_id: response = ap.show_test_run(test_id=test_id, run_id=run_id) else: response = ap.show_test_run_latest(test_id=test_id) if not response: error = "No test run found for test ID '{}'".format(test_id) if run_id: error = error + " with run ID '{}'".format(run_id) raise CLIError(error) status = response.status run_id = response.id while all([wait, status, run_id]) and status not in final_statuses: sleep(poll_interval) response = ap.show_test_run(test_id=test_id, run_id=run_id) status = response.status return response
def show(cmd, test_id, task_id=None, running=False, base_url=None): ap = AICSProvider(cmd, base_url) if task_id: return ap.show_test_task(test_id=test_id, task_id=task_id) elif running: return ap.show_running_test_task(test_id=test_id) raise CLIError( "Please provide a task-id for individual task details, or use the --running argument to list all running tasks" )
def update(cmd, test_id, configuration_file, base_url=None): import os if not os.path.exists(configuration_file): raise CLIError("Specified configuration file does not exist") ap = AICSProvider(cmd, base_url) return ap.update_test_cases( test_id=test_id, patch=process_json_arg(configuration_file, "configuration_file"), )
def search( cmd, product_id=None, registration_id=None, certificate_name=None, base_url=None ): if not any([product_id or registration_id or certificate_name]): raise CLIError("At least one search criteria must be specified") ap = AICSProvider(cmd, base_url) searchOptions = DeviceTestSearchOptions( product_id=product_id, dps_registration_id=registration_id, dps_x509_certificate_common_name=certificate_name, ) return ap.search_test(searchOptions)
def create(cmd, test_id, task_type=TaskType.QueueTestRun.value, wait=False, poll_interval=3, base_url=None): ap = AICSProvider(cmd, base_url) final_statuses = [ Status.failed.value, Status.completed.value, Status.cancelled.value, ] response = ap.create_test_task(test_id=test_id, task_type=task_type, wait=wait, poll_interval=poll_interval) if not response: raise CLIError( "Failed to create device test task - please ensure a device test exists with Id {}" .format(test_id)) if isinstance(response, dict): raise CLIError(response) status = response.status task_id = response.id while all([wait, status, task_id]) and status not in final_statuses: sleep(poll_interval) response = ap.show_test_task(test_id=test_id, task_id=task_id) status = response.status # if a task of 'queueTestRun' is awaited, return the run result if all([ wait, status in final_statuses, task_type == TaskType.QueueTestRun.value, response.result_link, ]): run_id = response.result_link.split("/")[-1] return ap.show_test_run(test_id=test_id, run_id=run_id) if run_id else response return response
def update( cmd, test_id, configuration_file=None, attestation_type=None, certificate_path=None, connection_string=None, endorsement_key=None, badge_type=None, models=None, base_url=None, ): provisioning = False # verify required parameters for various options if attestation_type == AttestationType.x509.value and not certificate_path: raise CLIError( "If attestation type is x509, certificate path is required") if attestation_type == AttestationType.tpm.value and not endorsement_key: raise CLIError( "If attestation type is tpm, endorsement key is required") if badge_type == BadgeType.Pnp.value and not models: raise CLIError("If badge type is Pnp, models is required") if badge_type == BadgeType.IotEdgeCompatible.value and not all([ connection_string, attestation_type == AttestationType.connectionString.value ]): raise CLIError( "Connection string is required for Edge Compatible modules testing" ) if badge_type != BadgeType.IotEdgeCompatible.value and ( connection_string or attestation_type == AttestationType.connectionString.value): raise CLIError( "Connection string is only available for Edge Compatible modules testing" ) ap = AICSProvider(cmd, base_url) if configuration_file: test_configuration = _create_from_file(configuration_file) return ap.update_test( test_id=test_id, test_configuration=test_configuration, provisioning=provisioning, ) if not any([attestation_type, badge_type, models]): raise CLIError( "Configuration file, attestation information, or device configuration must be specified" ) test_configuration = ap.show_test(test_id=test_id) provisioning_configuration = test_configuration[ "provisioningConfiguration"] registration_id = provisioning_configuration["dpsRegistrationId"] # change attestation if attestation_type: # reset the provisioningConfiguration test_configuration["provisioningConfiguration"] = { "type": attestation_type, "dpsRegistrationId": registration_id, } provisioning = True if attestation_type == AttestationType.symmetricKey.value: test_configuration["provisioningConfiguration"][ "symmetricKeyEnrollmentInformation"] = {} elif attestation_type == AttestationType.tpm.value: test_configuration["provisioningConfiguration"][ "tpmEnrollmentInformation"] = { "endorsementKey": endorsement_key } elif attestation_type == AttestationType.x509.value: test_configuration["provisioningConfiguration"][ "x509EnrollmentInformation"] = { "base64EncodedX509Certificate": _read_certificate_from_file(certificate_path) } elif attestation_type == AttestationType.connectionString.value: test_configuration["provisioningConfiguration"][ "deviceConnectionString"] = connection_string # reset PnP models badge_config = test_configuration["certificationBadgeConfigurations"] if (badge_type == BadgeType.Pnp.value or badge_config[0]["type"].lower() == BadgeType.Pnp.value.lower()) and models: models_array = _process_models_directory(models) test_configuration["certificationBadgeConfigurations"] = [{ "type": BadgeType.Pnp.value, "digitalTwinModelDefinitions": models_array }] elif badge_type: test_configuration["certificationBadgeConfigurations"] = [{ "type": badge_type }] return ap.update_test( test_id=test_id, test_configuration=test_configuration, provisioning=provisioning, )
def show(cmd, test_id, base_url=None): ap = AICSProvider(cmd, base_url) return ap.show_test(test_id)
def create( cmd, configuration_file=None, product_id=None, device_type=None, attestation_type=None, certificate_path=None, connection_string=None, endorsement_key=None, badge_type=BadgeType.IotDevice.value, validation_type=ValidationType.test.value, models=None, skip_provisioning=False, base_url=None, ): if attestation_type == AttestationType.x509.value and not certificate_path: raise CLIError( "If attestation type is x509, certificate path is required") if attestation_type == AttestationType.tpm.value and not endorsement_key: raise CLIError( "If attestation type is TPM, endorsement key is required") if badge_type == BadgeType.Pnp.value and not models: raise CLIError("If badge type is Pnp, models is required") if badge_type == BadgeType.IotEdgeCompatible.value and not all([ connection_string, attestation_type == AttestationType.connectionString.value ]): raise CLIError( "Connection string is required for Edge Compatible modules testing" ) if badge_type != BadgeType.IotEdgeCompatible.value and ( connection_string or attestation_type == AttestationType.connectionString.value): raise CLIError( "Connection string is only available for Edge Compatible modules testing" ) if validation_type != ValidationType.test.value and not product_id: raise CLIError("Product Id is required for validation type {}".format( validation_type)) if not any([ configuration_file, all([device_type, attestation_type, badge_type]), ]): raise CLIError( "If configuration file is not specified, attestation and device definition parameters must be specified" ) test_configuration = (_create_from_file(configuration_file) if configuration_file else _build_test_configuration( product_id=product_id, device_type=device_type, attestation_type=attestation_type, certificate_path=certificate_path, endorsement_key=endorsement_key, badge_type=badge_type, connection_string=connection_string, models=models, validation_type=validation_type)) ap = AICSProvider(cmd, base_url) provisioning = not skip_provisioning test_data = ap.create_test(test_configuration=test_configuration, provisioning=provisioning) return test_data
def submit(cmd, test_id, run_id, base_url=None): ap = AICSProvider(cmd, base_url) return ap.submit_test_run(test_id=test_id, run_id=run_id)
def list(cmd, badge_type=BadgeType.IotDevice.value, base_url=None): ap = AICSProvider(cmd, base_url) return ap.list_requirements(badge_type=badge_type)
def list(cmd, test_id, base_url=None): ap = AICSProvider(cmd, base_url) return ap.show_test_cases(test_id=test_id)
def delete(cmd, test_id, task_id, base_url=None): ap = AICSProvider(cmd, base_url) return ap.delete_test_task(test_id=test_id, task_id=task_id)