[TEST] Basic CNF macro 77/126377/19
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Thu, 23 Dec 2021 12:40:11 +0000 (13:40 +0100)
committerMichal Jagiello <michal.jagiello@t-mobile.pl>
Wed, 12 Jan 2022 22:09:13 +0000 (22:09 +0000)
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 <lukasz.rajewski@orange.com>
Change-Id: I697857bc0c13e86b88b71c3b46e0c4b59751939c
Signed-off-by: mrichomme <morgan.richomme@orange.com>
51 files changed:
requirements.txt
run_basic_cnf_macro.py [new file with mode: 0644]
setup.cfg
src/onaptests/configuration/basic_clamp_settings.py
src/onaptests/configuration/basic_cnf_macro_settings.py [new file with mode: 0644]
src/onaptests/configuration/basic_cnf_yaml_settings.py
src/onaptests/configuration/basic_network_nomulticloud_settings.py
src/onaptests/configuration/basic_onboard_settings.py
src/onaptests/configuration/basic_vm_macro_settings.py
src/onaptests/configuration/basic_vm_macro_stability_settings.py
src/onaptests/configuration/basic_vm_multicloud_yaml_settings.py
src/onaptests/configuration/basic_vm_settings.py
src/onaptests/configuration/cba_enrichment_settings.py
src/onaptests/configuration/cds_resource_resolution_settings.py
src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
src/onaptests/configuration/multi_vnf_ubuntu_settings.py
src/onaptests/configuration/pnf_macro_settings.py
src/onaptests/scenario/basic_cnf_macro.py [new file with mode: 0644]
src/onaptests/scenario/basic_vm_macro.py
src/onaptests/scenario/multi_vnf_macro.py
src/onaptests/scenario/pnf_macro.py
src/onaptests/steps/base.py
src/onaptests/steps/cloud/customer_service_subscription_create.py
src/onaptests/steps/instantiate/k8s_profile_create.py
src/onaptests/steps/instantiate/service_ala_carte.py
src/onaptests/steps/instantiate/service_macro.py
src/onaptests/steps/instantiate/vf_module_ala_carte.py
src/onaptests/steps/instantiate/vl_ala_carte.py
src/onaptests/steps/instantiate/vnf_ala_carte.py
src/onaptests/steps/loop/clamp.py
src/onaptests/steps/onboard/cds.py
src/onaptests/steps/onboard/clamp.py
src/onaptests/steps/onboard/service.py
src/onaptests/steps/onboard/vf.py
src/onaptests/steps/onboard/vsp.py
src/onaptests/steps/reports_collection.py
src/onaptests/steps/wrapper/helm_charts.py
src/onaptests/templates/artifacts/basic_cnf_cba_enriched.zip [new file with mode: 0644]
src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip [new file with mode: 0644]
src/onaptests/templates/vnf-services/basic_clamp-service.yaml
src/onaptests/templates/vnf-services/basic_cnf-service.yaml
src/onaptests/templates/vnf-services/basic_cnf_macro-service.yaml [new file with mode: 0644]
src/onaptests/templates/vnf-services/basic_onboard-service.yaml.j2
src/onaptests/templates/vnf-services/basic_vm-service.yaml
src/onaptests/templates/vnf-services/basic_vm_macro-service.yaml
src/onaptests/templates/vnf-services/basic_vm_macro_stability-service.yaml
src/onaptests/templates/vnf-services/clearwater-ims-service.yaml
src/onaptests/templates/vnf-services/multi-vnf-ubuntu-model.yaml.j2
src/onaptests/templates/vnf-services/pnf-service.yaml
src/onaptests/utils/resources.py [moved from src/onaptests/utils/simulators.py with 67% similarity]
tox.ini

index c84e334..39ee870 100644 (file)
@@ -1,6 +1,6 @@
-xtesting
+xtesting==0.91.0
+avionix>=0.4.5
 openstacksdk
-onapsdk==9.0.0
+onapsdk==9.2.2
 jinja2
 kubernetes
-avionix==0.4.4
\ No newline at end of file
diff --git a/run_basic_cnf_macro.py b/run_basic_cnf_macro.py
new file mode 100644 (file)
index 0000000..e6c1823
--- /dev/null
@@ -0,0 +1,32 @@
+import logging.config
+import time
+import onaptests.utils.exceptions as onap_test_exceptions
+from onapsdk.configuration import settings
+from onaptests.scenario.basic_cnf_macro import BasicCnfMacro
+
+if __name__ == "__main__":
+    # logging configuration for onapsdk, it is not requested for onaptests
+    # Correction requested in onapsdk to avoid having this duplicate code
+    logging.config.dictConfig(settings.LOG_CONFIG)
+    logger = logging.getLogger("Instantiate Apache CNF with macro procedure")
+    step = BasicCnfMacro(cleanup=settings.CLEANUP_FLAG)
+    try:
+        step.execute()
+        if settings.CLEANUP_FLAG:
+            logger.info("Starting to clean up in {} seconds".format(settings.CLEANUP_ACTIVITY_TIMER))
+            time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
+            step.cleanup()
+    except onap_test_exceptions.TestConfigurationException:
+        logger.error("Ubuntu NSO VM configuration error")
+    except onap_test_exceptions.ServiceInstantiateException:
+        logger.error("Ubuntu NSO VM instantiation error")
+    except onap_test_exceptions.ServiceCleanupException:
+        logger.error("Ubuntu NSO VM instance cleanup error")
+    except onap_test_exceptions.VnfInstantiateException:
+        logger.error("Ubuntu NSO VM Vnf instantiation error")
+    except onap_test_exceptions.VnfCleanupException:
+        logger.error("Ubuntu NSO VM Vnf instance cleanup error")
+    except onap_test_exceptions.VfModuleInstantiateException:
+        logger.error("Ubuntu NSO VM Module instantiation error")
+    except onap_test_exceptions.VfModuleCleanupException:
+        logger.error("Ubuntu NSO VM Module cleanup error")
index 63444b6..7362a35 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -56,3 +56,4 @@ xtesting.testcase =
   basic_clamp = onaptests.scenario.basic_clamp:BasicClamp
   cds_resource_resolution = onaptests.scenario.cds_resource_resolution:CDSResourceResolution
   multi_vnf_ubuntu_macro = onaptests.scenario.multi_vnf_macro:MultiVnfUbuntuMacro
+  basic_cnf_macro = onaptests.scenario.basic_cnf_macro:BasicCnfMacro
index c26c4e9..3eaad2d 100644 (file)
@@ -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 (file)
index 0000000..4433bf2
--- /dev/null
@@ -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
index 38e551c..36b0c3f 100644 (file)
@@ -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
index ab9e5ab..add6175 100644 (file)
@@ -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
index 2fa1820..8975fa8 100644 (file)
@@ -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
index 2784f86..522c66a 100644 (file)
@@ -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
index b2fe037..67a423c 100644 (file)
@@ -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
index 51c74e5..cb16d81 100644 (file)
@@ -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
index 2c7d85f..0b33ec1 100644 (file)
@@ -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
index 0770d8d..2d05cd2 100644 (file)
@@ -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"
index 16e23a6..b18d2ac 100644 (file)
@@ -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": [
index d20d9ff..5803df3 100644 (file)
@@ -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
index 47795fd..bb7b8b5 100644 (file)
@@ -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")
index eaca93a..5f2b98c 100644 (file)
@@ -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 (file)
index 0000000..2784782
--- /dev/null
@@ -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()
index 8bbf0b7..b849831 100644 (file)
@@ -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
index 404c785..41833e6 100644 (file)
@@ -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
index 7b7c219..931a332 100644 (file)
@@ -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
index 97c9159..b7651bb 100644 (file)
@@ -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:
index b318dc7..67de141 100644 (file)
@@ -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)
index d09d924..a5c8552 100644 (file)
@@ -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)
index 3407e8e..a2e1812 100644 (file)
@@ -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:
index b169049..dc2ce89 100644 (file)
@@ -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,
index af569fe..38bdee9 100644 (file)
@@ -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
 
index 3f81228..7186c24 100644 (file)
@@ -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
 
index 8dbec78..eb9896f 100644 (file)
@@ -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
 
index 9a705f2..c614857 100644 (file)
@@ -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
 
index 7f91d56..d6645ef 100644 (file)
@@ -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:
index 9d73a8e..72daba2 100644 (file)
@@ -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
 
index db1b330..6f1e69f 100644 (file)
@@ -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
 
index 44c3749..852cb82 100644 (file)
@@ -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"],
index 5462c55..f898268 100644 (file)
@@ -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)
index 52a0fec..4b7f79b 100644 (file)
@@ -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,
index 4482683..b8a6b21 100644 (file)
@@ -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 (file)
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 (file)
index 0000000..e9f5b4c
Binary files /dev/null and b/src/onaptests/templates/heat-files/basic_cnf_macro/basic_cnf_macro.zip differ
index f5fe653..f3ea53b 100644 (file)
@@ -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"
index c3c701f..047a244 100644 (file)
@@ -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 (file)
index 0000000..3660e2b
--- /dev/null
@@ -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"
+                    }
+                ]
index db84783..8cc4fe5 100644 (file)
@@ -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"
index 227ec48..eb4522a 100644 (file)
@@ -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"
index 00f66d5..2a616a5 100644 (file)
@@ -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: [
index 62170bd..d9454c3 100644 (file)
@@ -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: [
index d720b2c..49824c1 100644 (file)
@@ -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"},
index 96037c9..7a701e5 100644 (file)
@@ -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
index 2dcdfbb..e9ca513 100644 (file)
@@ -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"
similarity index 67%
rename from src/onaptests/utils/simulators.py
rename to src/onaptests/utils/resources.py
index 08acdbd..46c6c6e 100644 (file)
@@ -1,5 +1,13 @@
 """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.
diff --git a/tox.ini b/tox.ini
index ee2b4c0..50e841e 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -10,6 +10,8 @@ whitelist_externals =
   git
   bash
 deps =
+  pyyaml == 3.13
+  bandit == 1.3
   coala-bears
   nodeenv