From 22664610f99038223f996ef1c1661872a92e4ee4 Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Thu, 23 Dec 2021 13:40:11 +0100 Subject: [TEST] Basic CNF macro Basic CNF macro added with refactoring that enables debugging under IDE Also SDK upgraded to 9.2 what required adaptation in existing tests Issue-ID: TEST-376 Signed-off-by: Lukasz Rajewski Change-Id: I697857bc0c13e86b88b71c3b46e0c4b59751939c Signed-off-by: mrichomme --- .../configuration/basic_clamp_settings.py | 11 +- .../configuration/basic_cnf_macro_settings.py | 78 ++++++++++++ .../configuration/basic_cnf_yaml_settings.py | 34 +++--- .../basic_network_nomulticloud_settings.py | 10 +- .../configuration/basic_onboard_settings.py | 17 ++- .../configuration/basic_vm_macro_settings.py | 15 ++- .../basic_vm_macro_stability_settings.py | 3 +- .../basic_vm_multicloud_yaml_settings.py | 4 +- src/onaptests/configuration/basic_vm_settings.py | 10 +- .../configuration/cba_enrichment_settings.py | 5 +- .../cds_resource_resolution_settings.py | 17 +-- .../clearwater_ims_nomulticloud_settings.py | 10 +- .../configuration/multi_vnf_ubuntu_settings.py | 17 ++- src/onaptests/configuration/pnf_macro_settings.py | 20 ++-- src/onaptests/scenario/basic_cnf_macro.py | 132 +++++++++++++++++++++ src/onaptests/scenario/basic_vm_macro.py | 6 +- src/onaptests/scenario/multi_vnf_macro.py | 4 +- src/onaptests/scenario/pnf_macro.py | 4 +- src/onaptests/steps/base.py | 20 ++++ .../cloud/customer_service_subscription_create.py | 2 +- .../steps/instantiate/k8s_profile_create.py | 12 +- .../steps/instantiate/service_ala_carte.py | 6 +- src/onaptests/steps/instantiate/service_macro.py | 16 ++- .../steps/instantiate/vf_module_ala_carte.py | 4 +- src/onaptests/steps/instantiate/vl_ala_carte.py | 4 +- src/onaptests/steps/instantiate/vnf_ala_carte.py | 4 +- src/onaptests/steps/loop/clamp.py | 4 +- src/onaptests/steps/onboard/cds.py | 4 +- src/onaptests/steps/onboard/clamp.py | 4 +- src/onaptests/steps/onboard/service.py | 4 +- src/onaptests/steps/onboard/vf.py | 4 +- src/onaptests/steps/onboard/vsp.py | 8 +- src/onaptests/steps/reports_collection.py | 8 +- src/onaptests/steps/wrapper/helm_charts.py | 2 +- .../templates/artifacts/basic_cnf_cba_enriched.zip | Bin 0 -> 60824 bytes .../heat-files/basic_cnf_macro/basic_cnf_macro.zip | Bin 0 -> 20627 bytes .../vnf-services/basic_clamp-service.yaml | 2 +- .../templates/vnf-services/basic_cnf-service.yaml | 2 +- .../vnf-services/basic_cnf_macro-service.yaml | 68 +++++++++++ .../vnf-services/basic_onboard-service.yaml.j2 | 2 +- .../templates/vnf-services/basic_vm-service.yaml | 2 +- .../vnf-services/basic_vm_macro-service.yaml | 2 +- .../basic_vm_macro_stability-service.yaml | 4 +- .../vnf-services/clearwater-ims-service.yaml | 2 +- .../vnf-services/multi-vnf-ubuntu-model.yaml.j2 | 2 +- .../templates/vnf-services/pnf-service.yaml | 2 +- src/onaptests/utils/resources.py | 21 ++++ src/onaptests/utils/simulators.py | 13 -- 48 files changed, 456 insertions(+), 169 deletions(-) create mode 100644 src/onaptests/configuration/basic_cnf_macro_settings.py create mode 100644 src/onaptests/scenario/basic_cnf_macro.py create mode 100644 src/onaptests/templates/artifacts/basic_cnf_cba_enriched.zip create mode 100644 src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip create mode 100644 src/onaptests/templates/vnf-services/basic_cnf_macro-service.yaml create mode 100644 src/onaptests/utils/resources.py delete mode 100644 src/onaptests/utils/simulators.py (limited to 'src') diff --git a/src/onaptests/configuration/basic_clamp_settings.py b/src/onaptests/configuration/basic_clamp_settings.py index c26c4e9..3eaad2d 100644 --- a/src/onaptests/configuration/basic_clamp_settings.py +++ b/src/onaptests/configuration/basic_clamp_settings.py @@ -1,5 +1,5 @@ -import sys -from yaml import load +from yaml import load, SafeLoader +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 @@ -39,14 +39,13 @@ OPERATIONAL_POLICIES = [ # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic_clamp-service.yaml") -CONFIGURATION_PATH = sys.path[-1] + "/onaptests/configuration/" +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic_clamp-service.yaml") +CONFIGURATION_PATH = get_resource_location("configuration/") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) VF_NAME = SERVICE_NAME except ValueError: diff --git a/src/onaptests/configuration/basic_cnf_macro_settings.py b/src/onaptests/configuration/basic_cnf_macro_settings.py new file mode 100644 index 0000000..4433bf2 --- /dev/null +++ b/src/onaptests/configuration/basic_cnf_macro_settings.py @@ -0,0 +1,78 @@ +import os +from pathlib import Path +from uuid import uuid4 +from yaml import load, SafeLoader + +from onaptests.utils.resources import get_resource_location +import onaptests.utils.exceptions as onap_test_exceptions +from .settings import * # pylint: disable=W0614 + +""" Specific basic_cnf_macro with multicloud-k8s and yaml config scenario.""" +SERVICE_DETAILS = ("Onboarding, distribution and instantiation of a Apache CNF" + + "using macro and native CNF path: cnf-adapter + K8sPlugin") +SERVICE_COMPONENTS = "SDC, DMAAP, AAI, SO, SDNC, CDS, Multicloud K8S" + +CLEANUP_FLAG = True + +# CDS_DD_FILE = Path(get_resource_location("templates/artifacts/dd.json")) +CDS_CBA_UNENRICHED = Path("no_such_file") +CDS_CBA_ENRICHED = Path(get_resource_location("templates/artifacts/basic_cnf_cba_enriched.zip")) + +# This scenario uses multicloud-k8s and not multicloud +# (no registration requested) +USE_MULTICLOUD = False +# Set ONLY_INSTANTIATE to true to run an instantiation without repeating +# onboarding and related AAI configuration (Cloud config) +ONLY_INSTANTIATE = False + +# Relative path to config file to set k8s connectivity information +K8S_CONFIG = get_resource_location("templates/artifacts/config") + +VENDOR_NAME = "basiccnf_macro_vendor" + +CLOUD_REGION_CLOUD_OWNER = "basiccnf-cloud-owner" # must not contain _ +CLOUD_REGION_ID = "k8sregion" +CLOUD_REGION_TYPE = "k8s" +CLOUD_REGION_VERSION = "1.0" +CLOUD_DOMAIN = "Default" +CLOUD_OWNER_DEFINED_TYPE = "t1" + +COMPLEX_PHYSICAL_LOCATION_ID = "lannion" +COMPLEX_DATA_CENTER_CODE = "1234-5" +AVAILABILITY_ZONE_NAME = "basiccnf-availability-zone" +AVAILABILITY_ZONE_TYPE = "nova" + +GLOBAL_CUSTOMER_ID = "basiccnf-macro-customer" + +OWNING_ENTITY = "basicnf_macro_owning_entity" +PROJECT = "basicnf_macro_project" +LINE_OF_BUSINESS = "basicnf_macro_lob" +PLATFORM = "basicnf_macro_platform" + +# The cloud Part +# Assuming a cloud.yaml is available, use the openstack client +# to retrieve cloud info and avoid data duplication +# For basic_cnf, no tenant information is required but some dummy +# information shall be provided by default +# So it is not requested to set OS_TEST_CLOUD +TEST_CLOUD = os.getenv('OS_TEST_CLOUD') +VIM_USERNAME = 'dummy' +VIM_PASSWORD = 'dummy123' +VIM_SERVICE_URL = 'http://10.12.25.2:5000/v3' +TENANT_ID = '123456' +TENANT_NAME = 'dummy_test' + + +SERVICE_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/basic_cnf_macro-service.yaml")) + +try: + # Try to retrieve the SERVICE NAME from the yaml file + with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: + yaml_config_file = load(yaml_template, SafeLoader) + SERVICE_NAME = next(iter(yaml_config_file.keys())) +except (FileNotFoundError, ValueError): + raise onap_test_exceptions.TestConfigurationException + +SERVICE_INSTANCE_NAME = f"basic_cnf_macro_{str(uuid4())}" + +MODEL_YAML_TEMPLATE = None diff --git a/src/onaptests/configuration/basic_cnf_yaml_settings.py b/src/onaptests/configuration/basic_cnf_yaml_settings.py index 38e551c..36b0c3f 100644 --- a/src/onaptests/configuration/basic_cnf_yaml_settings.py +++ b/src/onaptests/configuration/basic_cnf_yaml_settings.py @@ -1,31 +1,28 @@ import os -import openstack -import sys -from yaml import load - +from yaml import load, SafeLoader +from onaptests.utils.resources import get_resource_location import onaptests.utils.exceptions as onap_test_exceptions from .settings import * # pylint: disable=W0614 """ Specific basic_cnf with multicloud-k8s and yaml config scenario.""" SERVICE_DETAILS = ("Onboarding, distribution and instantiation of a CNF" + "using à la carte and Multicloud K8S module") -SERVICE_COMPONENTS="SDC, DMAAP, AAI, SO, SDNC, Multicloud K8S" +SERVICE_COMPONENTS = "SDC, DMAAP, AAI, SO, SDNC, Multicloud K8S" # This scenario uses multicloud-k8s and not multicloud # (no registration requested) USE_MULTICLOUD = False # Set ONLY_INSTANTIATE to true to run an instantiation without repeating # onboarding and related AAI configuration (Cloud config) -ONLY_INSTANTIATE= False +ONLY_INSTANTIATE = False # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic_cnf-service.yaml") +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic_cnf-service.yaml") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException @@ -37,15 +34,13 @@ CLEANUP_ACTIVITY_TIMER = 10 # Definition of k8s profile version K8S_PROFILE_K8S_VERSION = "1.0" # Relative path to k8s profile artifact in the python package (so under /src) -K8S_PROFILE_ARTIFACT_PATH = (sys.path[-1] + - "/onaptests/templates/artifacts/k8sprof.tar.gz") +K8S_PROFILE_ARTIFACT_PATH = get_resource_location("templates/artifacts/k8sprof.tar.gz") # Relative path to config file to set k8s connectivity information -K8S_CONFIG = (sys.path[-1] + - "/onaptests/templates/artifacts/config") +K8S_CONFIG = get_resource_location("templates/artifacts/config") VENDOR_NAME = "basicnf_vendor" -CLOUD_REGION_CLOUD_OWNER = "basicnf-owner" # must not contain _ +CLOUD_REGION_CLOUD_OWNER = "basicnf-owner" # must not contain _ CLOUD_REGION_ID = "k8sregion" CLOUD_REGION_TYPE = "k8s" CLOUD_REGION_VERSION = "1.0" @@ -73,11 +68,10 @@ SERVICE_INSTANCE_NAME = "basic_cnf_service_instance" # information shall be provided by default # So it is not requested to set OS_TEST_CLOUD TEST_CLOUD = os.getenv('OS_TEST_CLOUD') -cloud = openstack.connect(cloud=TEST_CLOUD) -VIM_USERNAME = cloud.config.auth.get('username','dummy') -VIM_PASSWORD = cloud.config.auth.get('password','dummy123') -VIM_SERVICE_URL = cloud.config.auth.get('auth_url','http://10.12.25.2:5000/v3') -TENANT_ID = cloud.config.auth.get('project_id','123456') -TENANT_NAME = cloud.config.auth.get('project_name','dummy_test') +VIM_USERNAME = 'dummy' +VIM_PASSWORD = 'dummy123' +VIM_SERVICE_URL = 'http://10.12.25.2:5000/v3' +TENANT_ID = '123456' +TENANT_NAME = 'dummy_test' MODEL_YAML_TEMPLATE = None diff --git a/src/onaptests/configuration/basic_network_nomulticloud_settings.py b/src/onaptests/configuration/basic_network_nomulticloud_settings.py index ab9e5ab..add6175 100644 --- a/src/onaptests/configuration/basic_network_nomulticloud_settings.py +++ b/src/onaptests/configuration/basic_network_nomulticloud_settings.py @@ -1,8 +1,7 @@ import os import openstack -import sys -from yaml import load - +from yaml import load, SafeLoader +from onaptests.utils.resources import get_resource_location import onaptests.utils.exceptions as onap_test_exceptions from .settings import * # pylint: disable=W0614 @@ -19,13 +18,12 @@ ONLY_INSTANTIATE= False # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic_network-service.yaml") +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic_network-service.yaml") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException diff --git a/src/onaptests/configuration/basic_onboard_settings.py b/src/onaptests/configuration/basic_onboard_settings.py index 2fa1820..8975fa8 100644 --- a/src/onaptests/configuration/basic_onboard_settings.py +++ b/src/onaptests/configuration/basic_onboard_settings.py @@ -1,14 +1,16 @@ -import sys import random import string -from yaml import load +from yaml import load, SafeLoader from jinja2 import Environment, PackageLoader + import onaptests.utils.exceptions as onap_test_exceptions +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 """ Creation of service to onboard""" + # We need to create a service file with a random service name, # to be sure that we force onboarding def generate_service_config_yaml_file(): @@ -28,10 +30,7 @@ def generate_service_config_yaml_file(): rendered_template = template.render(service_name=service_name) - file_name = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic-onboard-service.yaml") - - with open(file_name, 'w+') as file_to_write: + with open(SERVICE_YAML_TEMPLATE, 'w+') as file_to_write: file_to_write.write(rendered_template) """Basic onboard service to only onboard a service in SDC""" @@ -48,14 +47,14 @@ SERVICE_COMPONENTS="SDC" # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings + +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic-onboard-service.yaml") generate_service_config_yaml_file() -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic-onboard-service.yaml") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException diff --git a/src/onaptests/configuration/basic_vm_macro_settings.py b/src/onaptests/configuration/basic_vm_macro_settings.py index 2784f86..522c66a 100644 --- a/src/onaptests/configuration/basic_vm_macro_settings.py +++ b/src/onaptests/configuration/basic_vm_macro_settings.py @@ -2,18 +2,18 @@ import os import openstack from pathlib import Path from uuid import uuid4 - -from yaml import load +from yaml import load, SafeLoader import onaptests.utils.exceptions as onap_test_exceptions +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 CLEANUP_FLAG = True -CDS_DD_FILE = Path(Path(__file__).parent.parent, "templates/artifacts/dd.json") -CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, "templates/artifacts/basic_vm_cba.zip") -CDS_CBA_ENRICHED = "/tmp/BASIC_VM_enriched.zip" +CDS_DD_FILE = Path(get_resource_location("templates/artifacts/dd.json")) +CDS_CBA_UNENRICHED = Path(get_resource_location("templates/artifacts/basic_vm_cba.zip")) +CDS_CBA_ENRICHED = Path("/tmp/BASIC_VM_enriched.zip") ONLY_INSTANTIATE = False USE_MULTICLOUD = False @@ -47,13 +47,12 @@ PROJECT = "basicvm-project" LINE_OF_BUSINESS = "basicvm-lob" PLATFORM = "basicvm-platform" CLOUD_DOMAIN = "Default" -SERVICE_YAML_TEMPLATE = Path(Path(__file__).parent.parent, "templates/vnf-services/" + - "basic_vm_macro-service.yaml") +SERVICE_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/basic_vm_macro-service.yaml")) try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException diff --git a/src/onaptests/configuration/basic_vm_macro_stability_settings.py b/src/onaptests/configuration/basic_vm_macro_stability_settings.py index b2fe037..67a423c 100644 --- a/src/onaptests/configuration/basic_vm_macro_stability_settings.py +++ b/src/onaptests/configuration/basic_vm_macro_stability_settings.py @@ -1,5 +1,4 @@ from .basic_vm_macro_settings import * # pylint: disable=W0614 -SERVICE_YAML_TEMPLATE = Path(Path(__file__).parent.parent, "templates/vnf-services/" + - "basic_vm_macro_stability-service.yaml") +SERVICE_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/basic_vm_macro_stability-service.yaml")) MODEL_YAML_TEMPLATE = None diff --git a/src/onaptests/configuration/basic_vm_multicloud_yaml_settings.py b/src/onaptests/configuration/basic_vm_multicloud_yaml_settings.py index 51c74e5..cb16d81 100644 --- a/src/onaptests/configuration/basic_vm_multicloud_yaml_settings.py +++ b/src/onaptests/configuration/basic_vm_multicloud_yaml_settings.py @@ -1,4 +1,4 @@ -import sys +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 """ Specific Basic VM with multicloud and yaml config scenario.""" @@ -40,5 +40,5 @@ PLATFORM = "sdktests_platform" SERVICE_INSTANCE_NAME = "sdktests_service_instance_name" -SERVICE_YAML_TEMPLATE = sys.path[-1] + "/onaptests/templates/vnf-services/basic_vm-service.yaml" +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic_vm-service.yaml") MODEL_YAML_TEMPLATE = None diff --git a/src/onaptests/configuration/basic_vm_settings.py b/src/onaptests/configuration/basic_vm_settings.py index 2c7d85f..0b33ec1 100644 --- a/src/onaptests/configuration/basic_vm_settings.py +++ b/src/onaptests/configuration/basic_vm_settings.py @@ -1,8 +1,7 @@ import os import openstack -import sys -from yaml import load - +from yaml import load, SafeLoader +from onaptests.utils.resources import get_resource_location import onaptests.utils.exceptions as onap_test_exceptions from .settings import * # pylint: disable=W0614 @@ -20,13 +19,12 @@ ONLY_INSTANTIATE= False # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "basic_vm-service.yaml") +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/basic_vm-service.yaml") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException diff --git a/src/onaptests/configuration/cba_enrichment_settings.py b/src/onaptests/configuration/cba_enrichment_settings.py index 0770d8d..2d05cd2 100644 --- a/src/onaptests/configuration/cba_enrichment_settings.py +++ b/src/onaptests/configuration/cba_enrichment_settings.py @@ -1,11 +1,12 @@ from pathlib import Path +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 SERVICE_NAME = "CDS blueprint enrichment" CLEANUP_FLAG = True -CDS_DD_FILE = Path(Path(__file__).parent.parent, "templates/artifacts/dd.json") -CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, "templates/artifacts/PNF_DEMO.zip") +CDS_DD_FILE = Path(get_resource_location("templates/artifacts/dd.json")) +CDS_CBA_UNENRICHED = Path(get_resource_location("templates/artifacts/PNF_DEMO.zip")) CDS_CBA_ENRICHED = "/tmp/PNF_DEMO_enriched.zip" diff --git a/src/onaptests/configuration/cds_resource_resolution_settings.py b/src/onaptests/configuration/cds_resource_resolution_settings.py index 16e23a6..b18d2ac 100644 --- a/src/onaptests/configuration/cds_resource_resolution_settings.py +++ b/src/onaptests/configuration/cds_resource_resolution_settings.py @@ -1,6 +1,7 @@ from pathlib import Path from uuid import uuid4 +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 CLEANUP_FLAG = True @@ -12,15 +13,15 @@ CLOUD_REGION_VERSION = "1.0" CLOUD_OWNER_DEFINED_TYPE = "N/A" COMPLEX_PHYSICAL_LOCATION_ID = "sdktests" -MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH = Path(Path(__file__).parent.parent, - "templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz") +MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH = Path(get_resource_location( + "templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz")) MSB_K8S_RB_NAME = f"cds-ms-rb-{str(uuid4())}" MSB_K8S_RB_VERSION = "v1" -MSB_K8S_PROFILE_ARTIFACT_FILE_PATH = Path(Path(__file__).parent.parent, - "templates/artifacts/profile.tar.gz") +MSB_K8S_PROFILE_ARTIFACT_FILE_PATH = Path(get_resource_location( + "templates/artifacts/profile.tar.gz")) MSB_K8S_PROFILE_NAME = f"cds-ms-prof-{str(uuid4())}" K8S_VERSION = "1.0" -K8S_CONFIG = str(Path(Path(__file__).parent.parent, "templates/artifacts/config")) +K8S_CONFIG = get_resource_location("templates/artifacts/config") K8S_ADDITIONAL_RESOURCES_NAMESPACE = "onap-tests" CDS_MOCKSERVER_EXPECTATIONS = [ { @@ -55,9 +56,9 @@ CDS_MOCKSERVER_EXPECTATIONS = [ } ] -CDS_DD_FILE = Path(Path(__file__).parent.parent, "templates/artifacts/cds-resource-resolution/dd.json") -CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, "templates/artifacts/cds-resource-resolution/resource-resolution.zip") -CDS_CBA_ENRICHED = "/tmp/resource-resolution-enriched.zip" +CDS_DD_FILE = Path(get_resource_location("templates/artifacts/cds-resource-resolution/dd.json")) +CDS_CBA_UNENRICHED = Path(get_resource_location("templates/artifacts/cds-resource-resolution/resource-resolution.zip")) +CDS_CBA_ENRICHED = Path("/tmp/resource-resolution-enriched.zip") CDS_WORKFLOW_NAME = "resource-resolution" CDS_WORKFLOW_INPUT = { "template-prefix": [ diff --git a/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py index d20d9ff..5803df3 100644 --- a/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py +++ b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py @@ -1,8 +1,7 @@ import os -import sys import openstack -from yaml import load - +from yaml import load, SafeLoader +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 """ Specific clearwater IMS without multicloud.""" @@ -21,13 +20,12 @@ VF_NAME = "clearwater-ims_ubuntu_vf" VSP_NAME = "clearwater-ims_ubuntu_vsp" # if a yaml file is define, retrieve info from this yaml files # if not declare the parameters in the settings -SERVICE_YAML_TEMPLATE = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - "clearwater-ims-service.yaml") +SERVICE_YAML_TEMPLATE = get_resource_location("templates/vnf-services/clearwater-ims-service.yaml") try: # Try to retrieve the SERVICE NAME from the yaml file with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template: - yaml_config_file = load(yaml_template) + yaml_config_file = load(yaml_template, SafeLoader) SERVICE_NAME = next(iter(yaml_config_file.keys())) except ValueError: SERVICE_NAME = "" # Fill me diff --git a/src/onaptests/configuration/multi_vnf_ubuntu_settings.py b/src/onaptests/configuration/multi_vnf_ubuntu_settings.py index 47795fd..bb7b8b5 100644 --- a/src/onaptests/configuration/multi_vnf_ubuntu_settings.py +++ b/src/onaptests/configuration/multi_vnf_ubuntu_settings.py @@ -1,9 +1,9 @@ import uuid import os -import sys from pathlib import Path import openstack from jinja2 import Environment, PackageLoader +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 VNF_FILENAME_PREFIX = "multi-vnf-ubuntu" @@ -23,8 +23,7 @@ def generate_service_config_yaml_file(filename): rendered_template = template.render(service_name=SERVICE_NAME) - file_name = (sys.path[-1] + "/onaptests/templates/vnf-services/" + - f"{filename}.yaml") + file_name = get_resource_location(f"templates/vnf-services/{filename}.yaml") with open(file_name, 'w+') as file_to_write: file_to_write.write(rendered_template) @@ -32,8 +31,8 @@ def generate_service_config_yaml_file(filename): CLEANUP_FLAG = True -CDS_DD_FILE = Path(Path(__file__).parent.parent, "templates/artifacts/dd_nso_ubuntu.json") -CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, "templates/artifacts/nso_ubuntuvnf.zip") +CDS_DD_FILE = Path(get_resource_location("templates/artifacts/dd_nso_ubuntu.json")) +CDS_CBA_UNENRICHED = Path(get_resource_location("templates/artifacts/nso_ubuntuvnf.zip")) CDS_CBA_ENRICHED = "/tmp/UBUNTUVNF_enriched.zip" ONLY_INSTANTIATE = False @@ -69,11 +68,11 @@ CLOUD_DOMAIN = "Default" VENDOR_NAME = 'ubuntu_xtesting_vendor' -SERVICE_YAML_TEMPLATE = Path(Path(__file__).parent.parent, "templates/vnf-services/" + - f"{VNF_FILENAME_PREFIX}-service.yaml") +SERVICE_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/" + + f"{VNF_FILENAME_PREFIX}-service.yaml")) -MODEL_YAML_TEMPLATE = Path(Path(__file__).parent.parent, "templates/vnf-services/" + - f"{VNF_FILENAME_PREFIX}-model.yaml") +MODEL_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/" + + f"{VNF_FILENAME_PREFIX}-model.yaml")) generate_service_config_yaml_file(f"{VNF_FILENAME_PREFIX}-service") diff --git a/src/onaptests/configuration/pnf_macro_settings.py b/src/onaptests/configuration/pnf_macro_settings.py index eaca93a..5f2b98c 100644 --- a/src/onaptests/configuration/pnf_macro_settings.py +++ b/src/onaptests/configuration/pnf_macro_settings.py @@ -1,6 +1,7 @@ from pathlib import Path from uuid import uuid4 +from onaptests.utils.resources import get_resource_location from .settings import * # pylint: disable=W0614 ONLY_INSTANTIATE = False @@ -10,13 +11,10 @@ USE_MULTICLOUD = False VENDOR_NAME = "pnf_macro_vendor" SERVICE_NAME = "test_pnf_macro" SERVICE_INSTANCE_NAME = "TestPNFMacroInstantiation" -SERVICE_YAML_TEMPLATE = Path(Path(__file__).parent.parent, - "templates/vnf-services/pnf-service.yaml") +SERVICE_YAML_TEMPLATE = Path(get_resource_location("templates/vnf-services/pnf-service.yaml")) -CDS_DD_FILE = Path(Path(__file__).parent.parent, - "templates/artifacts/dd.json") -CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, - "templates/artifacts/PNF_DEMO.zip") +CDS_DD_FILE = Path(get_resource_location("templates/artifacts/dd.json")) +CDS_CBA_UNENRICHED = Path(get_resource_location("templates/artifacts/PNF_DEMO.zip")) CDS_CBA_ENRICHED = "/tmp/PNF_DEMO_enriched.zip" CLOUD_REGION_CLOUD_OWNER = "basicnf-owner" # must not contain _ @@ -33,18 +31,16 @@ PLATFORM = "pnf_macro_platform" INSTANTIATION_TIMEOUT = 600 -MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH = Path(Path(__file__).parent.parent, - "templates/artifacts/pnf-simulator.tar.gz") +MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH = Path(get_resource_location("templates/artifacts/pnf-simulator.tar.gz")) MSB_K8S_RB_NAME = f"pnf-cnf-rb-{str(uuid4())}" MSB_K8S_RB_VERSION = "v1" -MSB_K8S_PROFILE_ARTIFACT_FILE_PATH = Path(Path(__file__).parent.parent, - "templates/artifacts/profile.tar.gz") +MSB_K8S_PROFILE_ARTIFACT_FILE_PATH = Path(get_resource_location("templates/artifacts/profile.tar.gz")) MSB_K8S_PROFILE_NAME = f"pnf-cnf-profile-{str(uuid4())}" K8S_VERSION = "1.0" -K8S_CONFIG = str(Path(Path(__file__).parent.parent, "templates/artifacts/config")) +K8S_CONFIG = get_resource_location("templates/artifacts/config") K8S_ADDITIONAL_RESOURCES_NAMESPACE = "onap-tests" -SERVICE_INSTANCE_NAME = "TestPNFMacroInstantiation" +SERVICE_INSTANCE_NAME = f"TestPNFMacroInstantiation_{str(uuid4())}" DCAE_VES_COLLECTOR_POD_NAME = "dcae-ves-collector" PNF_WAIT_TIME = 60.0 diff --git a/src/onaptests/scenario/basic_cnf_macro.py b/src/onaptests/scenario/basic_cnf_macro.py new file mode 100644 index 0000000..2784782 --- /dev/null +++ b/src/onaptests/scenario/basic_cnf_macro.py @@ -0,0 +1,132 @@ +"""Instantiate basic cnf using SO macro flow.""" +import logging +import time +from yaml import load, SafeLoader + +from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException +from xtesting.core import testcase + +from onaptests.steps.base import YamlTemplateBaseStep +from onaptests.steps.onboard.cds import CbaPublishStep +from onaptests.utils.exceptions import OnapTestException +from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep + + +class BasicCnfMacroStep(YamlTemplateBaseStep): + + def __init__(self, cleanup=False): + """Initialize step. + + Substeps: + - CbaPublishStep + - YamlTemplateServiceMacroInstantiateStep. + """ + super().__init__(cleanup=cleanup) + self._yaml_template: dict = None + self.add_step(CbaPublishStep( + cleanup=cleanup + )) + self.add_step(YamlTemplateServiceMacroInstantiateStep( + cleanup=cleanup + )) + + @property + def description(self) -> str: + """Step description. + + Used for reports + + Returns: + str: Step description + + """ + return "Basic CNF macro scenario step" + + @property + def component(self) -> str: + """Component name. + + Name of component which step is related with. + Most is the name of ONAP component. + + Returns: + str: Component name + + """ + return "PythonSDK-tests" + + @property + def yaml_template(self) -> dict: + """YAML template abstract property. + + Every YAML template step need to implement that property. + + Returns: + dict: YAML template + + """ + if not self._yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + self._yaml_template: dict = load(yaml_template, SafeLoader) + return self._yaml_template + + @property + def model_yaml_template(self) -> dict: + return {} + + @property + def service_name(self) -> dict: + """Service name. + + Get from YAML template. + + Returns: + str: Service name + + """ + return next(iter(self.yaml_template.keys())) + + @property + def service_instance_name(self) -> str: + """Service instance name. + + Returns: + str: Service instance name + + """ + return settings.SERVICE_INSTANCE_NAME + + +class BasicCnfMacro(testcase.TestCase): + """Instantiate a basic cnf macro.""" + + __logger = logging.getLogger() + + def __init__(self, **kwargs): + """Init Basic Cnf Macro use case.""" + if "case_name" not in kwargs: + kwargs["case_name"] = 'basic_cnf_macro' + super().__init__(**kwargs) + self.__logger.debug("Basic Cnf macro init started") + self.test = BasicCnfMacroStep(cleanup=settings.CLEANUP_FLAG) + + def run(self): + """Run basic cnf macro test.""" + self.start_time = time.time() + try: + self.test.execute() + self.test.cleanup() + self.result = 100 + except OnapTestException as exc: + self.result = 0 + self.__logger.error(exc.error_message) + except SDKException: + self.result = 0 + self.__logger.error("SDK Exception") + finally: + self.stop_time = time.time() + + def clean(self): + """Generate report.""" + self.test.reports_collection.generate_report() diff --git a/src/onaptests/scenario/basic_vm_macro.py b/src/onaptests/scenario/basic_vm_macro.py index 8bbf0b7..b849831 100644 --- a/src/onaptests/scenario/basic_vm_macro.py +++ b/src/onaptests/scenario/basic_vm_macro.py @@ -1,7 +1,7 @@ """Instantiate basic vm using SO macro flow.""" import logging import time -from yaml import load +from yaml import load, SafeLoader from onapsdk.configuration import settings from onapsdk.exceptions import SDKException @@ -20,7 +20,7 @@ class BasicVmMacroStep(YamlTemplateBaseStep): Substeps: - CbaPublishStep - - YamlTemplateServiceAlaCarteInstantiateStep. + - YamlTemplateServiceMacroInstantiateStep. """ super().__init__(cleanup=cleanup) self._yaml_template: dict = None @@ -68,7 +68,7 @@ class BasicVmMacroStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property diff --git a/src/onaptests/scenario/multi_vnf_macro.py b/src/onaptests/scenario/multi_vnf_macro.py index 404c785..41833e6 100644 --- a/src/onaptests/scenario/multi_vnf_macro.py +++ b/src/onaptests/scenario/multi_vnf_macro.py @@ -2,7 +2,7 @@ import logging import time -from yaml import load +from yaml import load, SafeLoader from onapsdk.configuration import settings from onapsdk.exceptions import SDKException @@ -70,7 +70,7 @@ class MultiVnfUbuntuMacroStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property diff --git a/src/onaptests/scenario/pnf_macro.py b/src/onaptests/scenario/pnf_macro.py index 7b7c219..931a332 100644 --- a/src/onaptests/scenario/pnf_macro.py +++ b/src/onaptests/scenario/pnf_macro.py @@ -1,7 +1,7 @@ """Instantiate service with PNF using SO macro flow.""" import logging import time -from yaml import load +from yaml import load, SafeLoader from xtesting.core import testcase from onapsdk.configuration import settings @@ -72,7 +72,7 @@ class PnfMacroScenarioStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py index 97c9159..b7651bb 100644 --- a/src/onaptests/steps/base.py +++ b/src/onaptests/steps/base.py @@ -168,6 +168,13 @@ class BaseStep(ABC): try: if cleanup: self._start_cleanup_time = time.time() + self._logger.info("*****************************************************") + self._logger.info(f"START [{self.component}] {self.name} cleanup: {self.description}") + self._logger.info("*****************************************************") + else: + self._logger.info("*****************************************************") + self._logger.info(f"START [{self.component}] {self.name}: {self.description}") + self._logger.info("*****************************************************") execution_status: Optional[ReportStepStatus] = None ret = fun(self, *args, **kwargs) execution_status = ReportStepStatus.PASS @@ -180,12 +187,18 @@ class BaseStep(ABC): raise finally: if cleanup: + self._logger.info("*****************************************************") + self._logger.info(f"STOP [{self.component}] {self.name} cleanup: {self.description}") + self._logger.info("*****************************************************") self._cleanup_report = Report( step_description=f"[{self.component}] {self.name} cleanup: {self.description}", step_execution_status=execution_status, step_execution_duration=time.time() - self._start_cleanup_time ) else: + self._logger.info("*****************************************************") + self._logger.info(f"STOP [{self.component}] {self.name}: {self.description}") + self._logger.info("*****************************************************") if not self._start_execution_time: if execution_status != ReportStepStatus.NOT_EXECUTED: self._logger.error("No execution start time saved for %s step. Fix it by call `super.execute()` " @@ -210,6 +223,10 @@ class BaseStep(ABC): step.execute() except (OnapTestException, SDKException) as substep_err: raise SubstepExecutionException from substep_err + if self._steps: + self._logger.info("*****************************************************") + self._logger.info(f"CONTINUE [{self.component}] {self.name}: {self.description}") + self._logger.info("*****************************************************") self._start_execution_time = time.time() def cleanup(self) -> None: @@ -218,6 +235,9 @@ class BaseStep(ABC): Not all steps has to have cleanup method """ + self._logger.info("*****************************") + self._logger.info("Start Cleanup step: " + self.name) + self._logger.info("*****************************") if self._cleanup: for step in self._steps: try: diff --git a/src/onaptests/steps/cloud/customer_service_subscription_create.py b/src/onaptests/steps/cloud/customer_service_subscription_create.py index b318dc7..67de141 100644 --- a/src/onaptests/steps/cloud/customer_service_subscription_create.py +++ b/src/onaptests/steps/cloud/customer_service_subscription_create.py @@ -39,4 +39,4 @@ class CustomerServiceSubscriptionCreateStep(BaseStep): super().execute() service = Service(name=settings.SERVICE_NAME) customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID) - customer.subscribe_service(service) + customer.subscribe_service(service.name) diff --git a/src/onaptests/steps/instantiate/k8s_profile_create.py b/src/onaptests/steps/instantiate/k8s_profile_create.py index d09d924..a5c8552 100644 --- a/src/onaptests/steps/instantiate/k8s_profile_create.py +++ b/src/onaptests/steps/instantiate/k8s_profile_create.py @@ -1,6 +1,6 @@ from typing import Iterable from uuid import uuid4 -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription from onapsdk.configuration import settings @@ -48,7 +48,7 @@ class K8SProfileStep(BaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template @@ -124,8 +124,8 @@ class K8SProfileStep(BaseStep): for vf_module in vnf_instance.vnf.vf_modules: # Define profile (rb_profile) for resource bundle definition # Retrieve resource bundle definition (rbdef) corresponding to vf module - rbdef_name = vf_module.metadata["vfModuleModelInvariantUUID"] - rbdef_version = vf_module.metadata["vfModuleModelCustomizationUUID"] + rbdef_name = vf_module.model_invariant_uuid + rbdef_version = vf_module.model_customization_id rbdef = Definition.get_definition_by_name_version(rbdef_name, rbdef_version) # Get k8s profile name from yaml service template vnf_parameters = self.get_vnf_parameters(vnf_instance.vnf.name) @@ -160,8 +160,8 @@ class K8SProfileStep(BaseStep): # possible to have several modules for 1 VNF for vf_module in vnf_instance.vnf.vf_modules: # Retrieve resource bundle definition (rbdef) corresponding to vf module - rbdef_name = vf_module.metadata["vfModuleModelInvariantUUID"] - rbdef_version = vf_module.metadata["vfModuleModelCustomizationUUID"] + rbdef_name = vf_module.model_invariant_uuid + rbdef_version = vf_module.model_customization_id rbdef = Definition.get_definition_by_name_version(rbdef_name, rbdef_version) # Get k8s profile name from yaml service template vnf_parameters = self.get_vnf_parameters(vnf_instance.vnf.name) diff --git a/src/onaptests/steps/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py index 3407e8e..a2e1812 100644 --- a/src/onaptests/steps/instantiate/service_ala_carte.py +++ b/src/onaptests/steps/instantiate/service_ala_carte.py @@ -1,6 +1,6 @@ import time from uuid import uuid4 -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription @@ -130,7 +130,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template @@ -188,6 +188,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep): super().execute() service = Service(self.service_name) customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID) + service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(service.name) cloud_region: CloudRegion = CloudRegion.get_by_id( cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, cloud_region_id=settings.CLOUD_REGION_ID, @@ -230,6 +231,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep): customer, owning_entity, settings.PROJECT, + service_subscription, service_instance_name=self.service_instance_name ) try: diff --git a/src/onaptests/steps/instantiate/service_macro.py b/src/onaptests/steps/instantiate/service_macro.py index b169049..dc2ce89 100644 --- a/src/onaptests/steps/instantiate/service_macro.py +++ b/src/onaptests/steps/instantiate/service_macro.py @@ -3,7 +3,7 @@ import time from typing import List from uuid import uuid4 from onapsdk.aai.business.service import ServiceInstance -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.business.customer import Customer, ServiceSubscription from onapsdk.aai.business.owning_entity import OwningEntity @@ -13,7 +13,6 @@ from onapsdk.configuration import settings from onapsdk.exceptions import ResourceNotFound from onapsdk.sdc.service import Service from onapsdk.so.instantiation import InstantiationParameter, ServiceInstantiation, VfmoduleParameters, VnfParameters, SoService -from onapsdk.vid import LineOfBusiness, Platform, Project from onaptests.steps.cloud.customer_service_subscription_create import CustomerServiceSubscriptionCreateStep import onaptests.utils.exceptions as onap_test_exceptions @@ -73,7 +72,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template @@ -144,6 +143,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): super().execute() service = Service(self.service_name) customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID) + service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(service.name) if any( filter(lambda x: x in self.yaml_template[self.service_name].keys(), ["vnfs", "networks"])): @@ -161,9 +161,6 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): except ResourceNotFound: self._logger.info("Owning entity not found, create it") owning_entity = OwningEntity.create(settings.OWNING_ENTITY) - vid_project: Project = Project(settings.PROJECT) - line_of_business: LineOfBusiness = LineOfBusiness(settings.LINE_OF_BUSINESS) - platform: Platform = Platform(settings.PLATFORM) # Before instantiating, be sure that the service has been distributed self._logger.info("******** Check Service Distribution *******") @@ -210,11 +207,12 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): sdc_service=service, customer=customer, owning_entity=owning_entity, - project=vid_project, - line_of_business=line_of_business, - platform=platform, + project=settings.PROJECT, + line_of_business=settings.LINE_OF_BUSINESS, + platform=settings.PLATFORM, cloud_region=cloud_region, tenant=tenant, + service_subscription=service_subscription, service_instance_name=self.service_instance_name, vnf_parameters=vnf_params_list, enable_multicloud=settings.USE_MULTICLOUD, diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py index af569fe..38bdee9 100644 --- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py +++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py @@ -1,6 +1,6 @@ from typing import Iterable from uuid import uuid4 -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription @@ -56,7 +56,7 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/instantiate/vl_ala_carte.py b/src/onaptests/steps/instantiate/vl_ala_carte.py index 3f81228..7186c24 100644 --- a/src/onaptests/steps/instantiate/vl_ala_carte.py +++ b/src/onaptests/steps/instantiate/vl_ala_carte.py @@ -1,7 +1,7 @@ import re from typing import Iterable from uuid import uuid4 -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription from onapsdk.configuration import settings @@ -51,7 +51,7 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py index 8dbec78..eb9896f 100644 --- a/src/onaptests/steps/instantiate/vnf_ala_carte.py +++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py @@ -1,5 +1,5 @@ from uuid import uuid4 -from yaml import load +from yaml import load, SafeLoader from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription @@ -49,7 +49,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/loop/clamp.py b/src/onaptests/steps/loop/clamp.py index 9a705f2..c614857 100644 --- a/src/onaptests/steps/loop/clamp.py +++ b/src/onaptests/steps/loop/clamp.py @@ -6,7 +6,7 @@ # # http://www.apache.org/licenses/LICENSE-2.0 """Clamp Scenario class.""" -from yaml import load +from yaml import load, SafeLoader import random import string import time @@ -57,7 +57,7 @@ class ClampStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py index 7f91d56..d6645ef 100644 --- a/src/onaptests/steps/onboard/cds.py +++ b/src/onaptests/steps/onboard/cds.py @@ -214,7 +214,9 @@ class CbaPublishStep(CDSBaseStep): def __init__(self, cleanup=False) -> None: """Initialize CBA publish step.""" super().__init__(cleanup=cleanup) - self.add_step(CbaEnrichStep(cleanup=cleanup)) + """Let's skip enrichment if enriched CBA is already present""" + if Path.is_file(settings.CDS_CBA_UNENRICHED): + self.add_step(CbaEnrichStep(cleanup=cleanup)) @property def description(self) -> str: diff --git a/src/onaptests/steps/onboard/clamp.py b/src/onaptests/steps/onboard/clamp.py index 9d73a8e..72daba2 100644 --- a/src/onaptests/steps/onboard/clamp.py +++ b/src/onaptests/steps/onboard/clamp.py @@ -1,7 +1,7 @@ #!/usr/bin/python # http://www.apache.org/licenses/LICENSE-2.0 """Clamp Onboard service class.""" -from yaml import load +from yaml import load, SafeLoader from onapsdk.sdc.service import Service from onapsdk.sdc.vf import Vf @@ -49,7 +49,7 @@ class OnboardClampStep(YamlTemplateBaseStep): if self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/onboard/service.py b/src/onaptests/steps/onboard/service.py index db1b330..6f1e69f 100644 --- a/src/onaptests/steps/onboard/service.py +++ b/src/onaptests/steps/onboard/service.py @@ -1,6 +1,6 @@ import time from typing import Any, Dict -from yaml import load +from yaml import load, SafeLoader from onapsdk.configuration import settings from onapsdk.exceptions import APIError, ResourceNotFound @@ -117,7 +117,7 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): elif self.is_root: if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template return self.parent.yaml_template diff --git a/src/onaptests/steps/onboard/vf.py b/src/onaptests/steps/onboard/vf.py index 44c3749..852cb82 100644 --- a/src/onaptests/steps/onboard/vf.py +++ b/src/onaptests/steps/onboard/vf.py @@ -1,10 +1,10 @@ from pathlib import Path -import sys import time from onapsdk.configuration import settings from onapsdk.sdc.vf import Vf from onapsdk.sdc.vsp import Vsp +from onaptests.utils.resources import get_resource_location from ..base import BaseStep, YamlTemplateBaseStep from .vsp import VspOnboardStep, YamlTemplateVspOnboardStep @@ -113,7 +113,7 @@ class YamlTemplateVfOnboardStep(YamlTemplateBaseStep): vf.create() artifact_file_path: Path = Path(vnf["vnf_artifact_file_path"]) if not artifact_file_path.exists(): - artifact_file_path = Path(sys.path[-1], artifact_file_path) + artifact_file_path = Path(get_resource_location(artifact_file_path)) vf.add_deployment_artifact( artifact_type=vnf["vnf_artifact_type"], artifact_name=vnf["vnf_artifact_name"], diff --git a/src/onaptests/steps/onboard/vsp.py b/src/onaptests/steps/onboard/vsp.py index 5462c55..f898268 100644 --- a/src/onaptests/steps/onboard/vsp.py +++ b/src/onaptests/steps/onboard/vsp.py @@ -1,7 +1,7 @@ -import sys from onapsdk.configuration import settings from onapsdk.sdc.vendor import Vendor from onapsdk.sdc.vsp import Vsp +from onaptests.utils.resources import get_resource_location from ..base import BaseStep, YamlTemplateBaseStep from .vendor import VendorOnboardStep @@ -105,8 +105,7 @@ class YamlTemplateVspOnboardStep(YamlTemplateBaseStep): vendor: Vendor = Vendor(name=settings.VENDOR_NAME) if "vnfs" in self.yaml_template: for vnf in self.yaml_template["vnfs"]: - with open( - sys.path[-1] + "/" + vnf["heat_files_to_upload"], "rb") as package: + with open(get_resource_location(vnf["heat_files_to_upload"]), "rb") as package: vsp: Vsp = Vsp(name=f"{vnf['vnf_name']}_VSP", vendor=vendor, package=package) @@ -114,8 +113,7 @@ class YamlTemplateVspOnboardStep(YamlTemplateBaseStep): elif "pnfs" in self.yaml_template: for pnf in self.yaml_template["pnfs"]: if "heat_files_to_upload" in pnf: - with open( - sys.path[-1] + "/" + pnf["heat_files_to_upload"], "rb") as package: + with open(get_resource_location(pnf["heat_files_to_upload"]), "rb") as package: vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP", vendor=vendor, package=package) diff --git a/src/onaptests/steps/reports_collection.py b/src/onaptests/steps/reports_collection.py index 52a0fec..4b7f79b 100644 --- a/src/onaptests/steps/reports_collection.py +++ b/src/onaptests/steps/reports_collection.py @@ -1,10 +1,10 @@ -import sys from dataclasses import dataclass from enum import Enum from typing import List from jinja2 import Environment, FileSystemLoader, select_autoescape from onapsdk.configuration import settings from onapsdk.exceptions import SettingsError +from onaptests.utils.resources import get_resource_location class ReportStepStatus(Enum): @@ -58,8 +58,8 @@ class ReportsCollection: int: How many steps failed """ - return sum((1 for step_report in self.report if \ - step_report.step_execution_status == ReportStepStatus.FAIL)) + return sum((1 for step_report in self.report if + step_report.step_execution_status == ReportStepStatus.FAIL)) def generate_report(self) -> None: usecase = settings.SERVICE_NAME @@ -75,7 +75,7 @@ class ReportsCollection: jinja_env = Environment( autoescape=select_autoescape(['html']), - loader=FileSystemLoader(sys.path[-1] + '/onaptests/templates/reporting')) + loader=FileSystemLoader(get_resource_location('templates/reporting'))) jinja_env.get_template('reporting.html.j2').stream( report=self, diff --git a/src/onaptests/steps/wrapper/helm_charts.py b/src/onaptests/steps/wrapper/helm_charts.py index 4482683..b8a6b21 100644 --- a/src/onaptests/steps/wrapper/helm_charts.py +++ b/src/onaptests/steps/wrapper/helm_charts.py @@ -3,7 +3,7 @@ import yaml from avionix import ChartBuilder, ChartDependency, ChartInfo from avionix.errors import HelmError from onaptests.steps.base import BaseStep -from onaptests.utils.simulators import get_local_dir +from onaptests.utils.resources import get_local_dir from onaptests.utils.exceptions import ( EnvironmentPreparationException, EnvironmentCleanupException) diff --git a/src/onaptests/templates/artifacts/basic_cnf_cba_enriched.zip b/src/onaptests/templates/artifacts/basic_cnf_cba_enriched.zip new file mode 100644 index 0000000..825160c Binary files /dev/null and b/src/onaptests/templates/artifacts/basic_cnf_cba_enriched.zip differ diff --git a/src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip b/src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip new file mode 100644 index 0000000..e9f5b4c Binary files /dev/null and b/src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip differ diff --git a/src/onaptests/templates/vnf-services/basic_clamp-service.yaml b/src/onaptests/templates/vnf-services/basic_clamp-service.yaml index f5fe653..f3ea53b 100644 --- a/src/onaptests/templates/vnf-services/basic_clamp-service.yaml +++ b/src/onaptests/templates/vnf-services/basic_clamp-service.yaml @@ -2,7 +2,7 @@ basicclamp: vnfs: - vnf_name: basicclamp - heat_files_to_upload: onaptests/templates/heat-files/ubuntu18/ubuntu18agent.zip + heat_files_to_upload: templates/heat-files/ubuntu18/ubuntu18agent.zip vnf_parameters: [ {"name": "ubuntu18_image_name", "value": "ubuntu-agent" diff --git a/src/onaptests/templates/vnf-services/basic_cnf-service.yaml b/src/onaptests/templates/vnf-services/basic_cnf-service.yaml index c3c701f..047a244 100644 --- a/src/onaptests/templates/vnf-services/basic_cnf-service.yaml +++ b/src/onaptests/templates/vnf-services/basic_cnf-service.yaml @@ -5,7 +5,7 @@ basic_cnf: subscription_type: "basic_cnf" vnfs: - vnf_name: basic_cnf - heat_files_to_upload: onaptests/templates/heat-files/basic_cnf/basic_cnf.zip + heat_files_to_upload: templates/heat-files/basic_cnf/basic_cnf.zip vnf_parameters: [ {"name": "dummy_name_0", "value": "dummy_name" diff --git a/src/onaptests/templates/vnf-services/basic_cnf_macro-service.yaml b/src/onaptests/templates/vnf-services/basic_cnf_macro-service.yaml new file mode 100644 index 0000000..3660e2b --- /dev/null +++ b/src/onaptests/templates/vnf-services/basic_cnf_macro-service.yaml @@ -0,0 +1,68 @@ +--- +basic_cnf_macro: + tosca_file_from_SDC: service-basic_cnf_macro-template + version: "1.0" + subscription_type: "basic_cnf_macro" + vnfs: + - vnf_name: basic_cnf_macro + properties: + controller_actor: "CDS" + skip_post_instantiation_configuration: False + sdnc_artifact_name: "vnf" + sdnc_model_version: "1.0.0" + sdnc_model_name: "APACHE" + vnf_artifact_type: "CONTROLLER_BLUEPRINT_ARCHIVE" + vnf_artifact_name: "basic_cnf_cba_enriched.zip" + vnf_artifact_label: "vnfcba" + vnf_artifact_file_path: templates/artifacts/basic_cnf_cba_enriched.zip + heat_files_to_upload: templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip + vnf_parameters: [ + { + "name": "k8s-rb-profile-namespace", + "value": "apache" + }, + { + "name": "k8s-rb-profile-k8s-version", + "value": "1.19.0" + } + ] + vf_module_parameters: + - vf_module_name: helm_apache + parameters: [ + { + "name": "vf_module_label", + "value": "helm_apache" + }, + { + "name": "k8s-rb-profile-name", + "value": "node-port-profile" + }, + { + "name": "k8s-rb-profile-source", + "value": "node-port-profile" + }, + { + "name": "k8s-rb-profile-namespace", + "value": "apache" + }, + { + "name": "k8s-rb-instance-release-name", + "value": "rel-1-apache" + }, + { + "name": "k8s-rb-config-template-name", + "value": "replica-count-template" + }, + { + "name": "k8s-rb-config-template-source", + "value": "deployment-config" + }, + { + "name": "k8s-rb-config-name", + "value": "replica-count-change" + }, + { + "name": "k8s-rb-config-value-source", + "value": "custom-values" + } + ] diff --git a/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 b/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 index db84783..8cc4fe5 100644 --- a/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 +++ b/src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2 @@ -2,7 +2,7 @@ {{ service_name }}: vnfs: - vnf_name: {{ service_name }} - heat_files_to_upload: onaptests/templates/heat-files/ubuntu18/ubuntu18agent.zip + heat_files_to_upload: templates/heat-files/ubuntu18/ubuntu18agent.zip vnf_parameters: [ {"name": "ubuntu18_image_name", "value": "ubuntu-agent" diff --git a/src/onaptests/templates/vnf-services/basic_vm-service.yaml b/src/onaptests/templates/vnf-services/basic_vm-service.yaml index 227ec48..eb4522a 100644 --- a/src/onaptests/templates/vnf-services/basic_vm-service.yaml +++ b/src/onaptests/templates/vnf-services/basic_vm-service.yaml @@ -2,7 +2,7 @@ basic_vm: vnfs: - vnf_name: basic_vm - heat_files_to_upload: onaptests/templates/heat-files/ubuntu20/ubuntu20agent.zip + heat_files_to_upload: templates/heat-files/ubuntu20/ubuntu20agent.zip vnf_parameters: [ {"name": "ubuntu20_image_name", "value": "ubuntu-20.04" diff --git a/src/onaptests/templates/vnf-services/basic_vm_macro-service.yaml b/src/onaptests/templates/vnf-services/basic_vm_macro-service.yaml index 00f66d5..2a616a5 100644 --- a/src/onaptests/templates/vnf-services/basic_vm_macro-service.yaml +++ b/src/onaptests/templates/vnf-services/basic_vm_macro-service.yaml @@ -13,7 +13,7 @@ basic_vm_macro: vnf_artifact_name: "BASIC_VM_enriched.zip" vnf_artifact_label: "vnfcds" vnf_artifact_file_path: "/tmp/BASIC_VM_enriched.zip" - heat_files_to_upload: onaptests/templates/heat-files/ubuntu20/ubuntu20agent.zip + heat_files_to_upload: templates/heat-files/ubuntu20/ubuntu20agent.zip vf_module_parameters: - vf_module_name: base_ubuntu20 parameters: [ diff --git a/src/onaptests/templates/vnf-services/basic_vm_macro_stability-service.yaml b/src/onaptests/templates/vnf-services/basic_vm_macro_stability-service.yaml index 62170bd..d9454c3 100644 --- a/src/onaptests/templates/vnf-services/basic_vm_macro_stability-service.yaml +++ b/src/onaptests/templates/vnf-services/basic_vm_macro_stability-service.yaml @@ -12,8 +12,8 @@ basic_vm_macro: vnf_artifact_type: "CONTROLLER_BLUEPRINT_ARCHIVE" vnf_artifact_name: "BASIC_VM_enriched.zip" vnf_artifact_label: "vnfcds" - vnf_artifact_file_path: onaptests/templates/artifacts/basic_vm_cba_enriched.zip - heat_files_to_upload: onaptests/templates/heat-files/ubuntu20/ubuntu20agent.zip + vnf_artifact_file_path: templates/artifacts/basic_vm_cba_enriched.zip + heat_files_to_upload: templates/heat-files/ubuntu20/ubuntu20agent.zip vf_module_parameters: - vf_module_name: base_ubuntu20 parameters: [ diff --git a/src/onaptests/templates/vnf-services/clearwater-ims-service.yaml b/src/onaptests/templates/vnf-services/clearwater-ims-service.yaml index d720b2c..49824c1 100644 --- a/src/onaptests/templates/vnf-services/clearwater-ims-service.yaml +++ b/src/onaptests/templates/vnf-services/clearwater-ims-service.yaml @@ -2,7 +2,7 @@ clearwater_ims: vnfs: - vnf_name: clearwater_ims_vnf - heat_files_to_upload: onaptests/templates/heat-files/clearwater_ims/clearwater_ims.zip + heat_files_to_upload: templates/heat-files/clearwater_ims/clearwater_ims.zip vnf_parameters: [ {"name": "public_net_id", "value": "FILL ME"}, diff --git a/src/onaptests/templates/vnf-services/multi-vnf-ubuntu-model.yaml.j2 b/src/onaptests/templates/vnf-services/multi-vnf-ubuntu-model.yaml.j2 index 96037c9..7a701e5 100644 --- a/src/onaptests/templates/vnf-services/multi-vnf-ubuntu-model.yaml.j2 +++ b/src/onaptests/templates/vnf-services/multi-vnf-ubuntu-model.yaml.j2 @@ -13,4 +13,4 @@ vnf_artifact_name: "UBUNTUVNF_enriched.zip" vnf_artifact_label: "UbuntuVNF" vnf_artifact_file_path: "/tmp/UBUNTUVNF_enriched.zip" - heat_files_to_upload: onaptests/templates/heat-files/nso_ubuntu/nso_ubuntu.zip + heat_files_to_upload: templates/heat-files/nso_ubuntu/nso_ubuntu.zip diff --git a/src/onaptests/templates/vnf-services/pnf-service.yaml b/src/onaptests/templates/vnf-services/pnf-service.yaml index 2dcdfbb..e9ca513 100644 --- a/src/onaptests/templates/vnf-services/pnf-service.yaml +++ b/src/onaptests/templates/vnf-services/pnf-service.yaml @@ -6,7 +6,7 @@ test_pnf_macro: instantiation_type: "Macro" pnfs: - pnf_name: "test-pnf" - heat_files_to_upload: onaptests/templates/artifacts/pNF.csar + heat_files_to_upload: templates/artifacts/pNF.csar pnf_artifact_type: "CONTROLLER_BLUEPRINT_ARCHIVE" pnf_artifact_name: "CBA_enriched.zip" pnf_artifact_label: "cbapnf" diff --git a/src/onaptests/utils/resources.py b/src/onaptests/utils/resources.py new file mode 100644 index 0000000..46c6c6e --- /dev/null +++ b/src/onaptests/utils/resources.py @@ -0,0 +1,21 @@ +"""Standard functions for the simulator wrapper.""" +import os +from importlib.resources import path +import onaptests + + +def get_resource_location(relative_path: str): + return os.path.join(os.path.dirname(os.path.realpath(onaptests.__file__)), + relative_path) + + +def get_local_dir(): + """Get the default path for helm charts. + + Returns: + chart_directory (Path): + local helm chart folder relative to the package. + """ + with path('onaptests', 'templates') as templates: + chart_directory = templates / 'helm_charts' + return chart_directory diff --git a/src/onaptests/utils/simulators.py b/src/onaptests/utils/simulators.py deleted file mode 100644 index 08acdbd..0000000 --- a/src/onaptests/utils/simulators.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Standard functions for the simulator wrapper.""" -from importlib.resources import path - -def get_local_dir(): - """Get the default path for helm charts. - - Returns: - chart_directory (Path): - local helm chart folder relative to the package. - """ - with path('onaptests', 'templates') as templates: - chart_directory = templates / 'helm_charts' - return chart_directory -- cgit 1.2.3-korg