def create(cls, project_uuid, sut_tosca_location, sut_inputs_location, ti_tosca_location, ti_inputs_location): linked_project = Project.get_by_uuid(project_uuid) # Create temporary directory to collect all the artifacts (SUT, TI, inputs), as they might come from URL or path artifact_dir = tempfile.mkdtemp(prefix="radon-ctt") sut_file_path = os.path.join(artifact_dir, TestArtifact.sut_default_file_name) TestArtifact.process_resource(sut_tosca_location, sut_file_path, linked_project.fq_storage_path) ti_file_path = os.path.join(artifact_dir, TestArtifact.ti_default_file_name) TestArtifact.process_resource(ti_tosca_location, ti_file_path, linked_project.fq_storage_path) if sut_inputs_location: sut_inputs_path = os.path.join(artifact_dir, TestArtifact.sut_inputs_default_file_name) TestArtifact.process_resource(sut_inputs_location, sut_inputs_path, linked_project.fq_storage_path, inputs_file=True) else: sut_inputs_path = None if ti_inputs_location: ti_inputs_path = os.path.join(artifact_dir, TestArtifact.ti_inputs_default_file_name) TestArtifact.process_resource(ti_inputs_location, ti_inputs_path, linked_project.fq_storage_path, inputs_file=True) else: ti_inputs_path = None test_artifact_list = [] sut_policy_list = TestArtifact.parse_policies(sut_file_path) ti_blueprint = TestArtifact.parse_ti_metadata(ti_file_path) plugin_list = ModuleLoader().load('plugins') # Collect all available plugins plugins_available = [] for plugin in plugin_list: plugins_available.append(plugin.plugin_type) current_app.logger.info(f'Plugin \'{plugin.plugin_type}\' found.') # Check which policies match the available plugins and which TI blueprint is present for policy_map in sut_policy_list: for policy in policy_map: current_policy = policy_map[policy] if current_policy['type'] in plugins_available: if current_policy['properties']['ti_blueprint'] == ti_blueprint: # sut_file_path_relative = os.path.relpath(sut_file_path, start=linked_project.fq_storage_path) # ti_file_path_relative = os.path.relpath(ti_file_path, start=linked_project.fq_storage_path) # Policy matches existing TI blueprint, so test artifact will be created. test_artifact_list.append(TestArtifact(linked_project, sut_file_path, sut_inputs_path, ti_file_path, ti_inputs_path, artifact_dir, yaml.dump(current_policy), current_policy['type'])) current_app.logger.info(f'Created test artifact for {ti_blueprint}.') else: # No matching TI blueprint, so nothing to be done with this policy. current_app.logger.info(f"The policy-defined TI blueprint " f"({current_policy['properties']['ti_blueprint']}) " f"does not match the TI model ({ti_blueprint}).") else: current_app.logger.info(f"Could not find matching plugin for {sut_policy_list[policy]['type']}.") return test_artifact_list
def get_project_by_uuid(project_uuid): # noqa: E501 """Retrieve a project # noqa: E501 :param project_uuid: UUID of the project to return :type project_uuid: str :rtype: Project """ project = ProjectImpl.get_by_uuid(project_uuid) return project_schema.dump(project)
def create(cls, project_uuid, sut_tosca_path, ti_tosca_path): linked_project = Project.get_by_uuid(project_uuid) sut_file_path = os.path.join(linked_project.fq_storage_path, sut_tosca_path) ti_file_path = os.path.join(linked_project.fq_storage_path, ti_tosca_path) test_artifact_list = [] sut_policy_list = TestArtifact.parse_policies(sut_file_path) ti_blueprint = TestArtifact.parse_ti_metadata(ti_file_path) plugin_list = ModuleLoader().load('plugins') # Collect all available plugins plugins_available = [] for plugin in plugin_list: plugins_available.append(plugin.plugin_type) current_app.logger.info(f'Plugin \'{plugin.plugin_type}\' found.') # Check which policies match the available plugins and which TI blueprint is present for policy in sut_policy_list: current_policy = sut_policy_list[policy] if current_policy['type'] in plugins_available: if current_policy['properties'][ 'ti_blueprint'] == ti_blueprint: # Policy matches existing TI blueprint, so test artifact will be created. test_artifact_list.append( TestArtifact(linked_project, sut_tosca_path, ti_tosca_path, yaml.dump(current_policy), current_policy['type'])) current_app.logger.info( f'Created test artifact for {ti_blueprint}.') else: # No matching TI blueprint, so nothing to be done with this policy. current_app.logger.info( f"The policy-defined TI blueprint " f"({current_policy['properties']['ti_blueprint']}) " f"does not match the TI model ({ti_blueprint}).") else: current_app.logger.info( f"Could not find matching plugin for {sut_policy_list[policy]['type']}." ) return test_artifact_list
def create(cls, project_uuid, sut_tosca_path, ti_tosca_path): linked_project = Project.get_by_uuid(project_uuid) return TestArtifact(linked_project, sut_tosca_path, ti_tosca_path)
def create(cls, project_uuid, sut_tosca_location, ti_tosca_location): linked_project = Project.get_by_uuid(project_uuid) # Read property csar_as_url_env = os.getenv('CSAR_URL') # If present and set to "1" if csar_as_url_env and csar_as_url_env == "1": csar_as_url = True current_app.logger.info('CSAR as URL mode enabled.') else: csar_as_url = False current_app.logger.info('CSAR as URL mode disabled.') if csar_as_url: # Define default paths artifact_dir = os.path.join(linked_project.fq_storage_path, 'radon-ctt') sut_file_path = os.path.join(artifact_dir, 'sut.csar') ti_file_path = os.path.join(artifact_dir, 'ti.csar') # Create directory if it does not exist os.makedirs(artifact_dir, exist_ok=True) if TestArtifact.url_exists(sut_tosca_location): sut_file = requests.get(sut_tosca_location, allow_redirects=True) with open(sut_file_path, 'wb') as sut_csar_dl: sut_csar_dl.write(sut_file.content) current_app.logger.info( f'Obtained SUT CSAR from "${sut_tosca_location}"') if TestArtifact.url_exists(ti_tosca_location): ti_file = requests.get(ti_tosca_location, allow_redirects=True) with open(ti_file_path, 'wb') as ti_csar_dl: ti_csar_dl.write(ti_file.content) current_app.logger.info( f'Obtained TI CSAR from "${ti_tosca_location}"') else: sut_file_path = os.path.join(linked_project.fq_storage_path, sut_tosca_location) ti_file_path = os.path.join(linked_project.fq_storage_path, ti_tosca_location) test_artifact_list = [] sut_policy_list = TestArtifact.parse_policies(sut_file_path) ti_blueprint = TestArtifact.parse_ti_metadata(ti_file_path) plugin_list = ModuleLoader().load('plugins') # Collect all available plugins plugins_available = [] for plugin in plugin_list: plugins_available.append(plugin.plugin_type) current_app.logger.info(f'Plugin \'{plugin.plugin_type}\' found.') # Check which policies match the available plugins and which TI blueprint is present for policy in sut_policy_list: current_policy = sut_policy_list[policy] if current_policy['type'] in plugins_available: if current_policy['properties'][ 'ti_blueprint'] == ti_blueprint: sut_file_path_relative = os.path.relpath( sut_file_path, start=linked_project.fq_storage_path) ti_file_path_relative = os.path.relpath( ti_file_path, start=linked_project.fq_storage_path) # Policy matches existing TI blueprint, so test artifact will be created. test_artifact_list.append( TestArtifact(linked_project, sut_file_path_relative, ti_file_path_relative, yaml.dump(current_policy), current_policy['type'])) current_app.logger.info( f'Created test artifact for {ti_blueprint}.') else: # No matching TI blueprint, so nothing to be done with this policy. current_app.logger.info( f"The policy-defined TI blueprint " f"({current_policy['properties']['ti_blueprint']}) " f"does not match the TI model ({ti_blueprint}).") else: current_app.logger.info( f"Could not find matching plugin for {sut_policy_list[policy]['type']}." ) return test_artifact_list