From c3ef82f489b915095b7464fb119daf43b84f67f8 Mon Sep 17 00:00:00 2001 From: Julien Fontaine Date: Wed, 4 Aug 2021 15:52:02 -0400 Subject: [TEST] Added support for multi-vnf macro instantiation Decoupled service YAML template into a model YAML template and a (SO) service YAML template. Model YAML template will be used during the onboarding steps and service YAML template will be used to generate payload when sending instantiation request to SO. Service YAML template reference model name to use for its VNF/VF-Modules using "model_name" field. This provide more flexibility to design the testcase and enables to setup more complex testcases like instantiating several VNF/VF-MOdules using the same SDC model infos. This patch aims to provide backward compatibility for existing testcases based on YAML template. Issue-ID: TEST-358 Signed-off-by: Julien Fontaine Change-Id: I69d370eff4d383d5af135206476c65e4a56e4ee5 --- .../steps/instantiate/service_ala_carte.py | 4 ++ src/onaptests/steps/instantiate/service_macro.py | 65 ++++++++++++++++------ .../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 ++ 5 files changed, 64 insertions(+), 17 deletions(-) (limited to 'src/onaptests/steps/instantiate') diff --git a/src/onaptests/steps/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py index dd62f52..3407e8e 100644 --- a/src/onaptests/steps/instantiate/service_ala_carte.py +++ b/src/onaptests/steps/instantiate/service_ala_carte.py @@ -134,6 +134,10 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep): return self._yaml_template return self.parent.yaml_template + @property + def model_yaml_template(self) -> dict: + return {} + @property def service_name(self) -> str: """Service name. diff --git a/src/onaptests/steps/instantiate/service_macro.py b/src/onaptests/steps/instantiate/service_macro.py index d83d2fe..b169049 100644 --- a/src/onaptests/steps/instantiate/service_macro.py +++ b/src/onaptests/steps/instantiate/service_macro.py @@ -12,7 +12,8 @@ from onapsdk.aai.cloud_infrastructure.tenant import Tenant 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 +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 @@ -34,6 +35,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): """ super().__init__(cleanup=cleanup) self._yaml_template: dict = None + self._model_yaml_template: dict = None self._service_instance_name: str = None self._service_instance: str = None if not settings.ONLY_INSTANTIATE: @@ -75,6 +77,23 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): return self._yaml_template return self.parent.yaml_template + @property + def model_yaml_template(self) -> dict: + """Step Model YAML template. + + Load from file if it's a root step, get from parent otherwise. + + Returns: + dict: Step YAML template + + """ + if self.is_root: + if not self._model_yaml_template: + with open(settings.MODEL_YAML_TEMPLATE, "r") as model_yaml_template: + self._model_yaml_template: dict = load(model_yaml_template) + return self._model_yaml_template + return self.parent.model_yaml_template + @property def service_name(self) -> str: """Service name. @@ -142,6 +161,9 @@ 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 *******") @@ -163,31 +185,40 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): if distribution_completed is False: self._logger.error( - "Service Distribution for %s failed !!",service.name) + "Service Distribution for %s failed !!", service.name) raise onap_test_exceptions.ServiceDistributionException + so_service = None vnf_params_list: List[VnfParameters] = [] - for vnf_data in self.yaml_template[self.service_name].get("vnfs", []): - vnf_params_list.append(VnfParameters( - vnf_data["vnf_name"], - [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for parameter in vnf_data.get("vnf_parameters", [])], - [VfmoduleParameters(vf_module_data["vf_module_name"], - [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for parameter in vf_module_data.get("parameters", [])]) \ + if settings.MODEL_YAML_TEMPLATE: + so_data = self.yaml_template[self.service_name] + so_service = SoService(vnfs=so_data.get("vnfs", []), + subscription_service_type=so_data.get('subscription_service_type')) + else: + for vnf_data in self.yaml_template[self.service_name].get("vnfs", []): + vnf_params_list.append(VnfParameters( + vnf_data["vnf_name"], + [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for parameter in + vnf_data.get("vnf_parameters", [])], + [VfmoduleParameters(vf_module_data["vf_module_name"], + [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for + parameter in vf_module_data.get("parameters", [])]) \ for vf_module_data in vnf_data.get("vf_module_parameters", [])] - )) + )) service_instantiation = ServiceInstantiation.instantiate_macro( - service, + sdc_service=service, customer=customer, owning_entity=owning_entity, - project=settings.PROJECT, - line_of_business=settings.LINE_OF_BUSINESS, - platform=settings.PLATFORM, + project=vid_project, + line_of_business=line_of_business, + platform=platform, cloud_region=cloud_region, tenant=tenant, service_instance_name=self.service_instance_name, vnf_parameters=vnf_params_list, - enable_multicloud=settings.USE_MULTICLOUD + enable_multicloud=settings.USE_MULTICLOUD, + so_service=so_service ) try: service_instantiation.wait_for_finish(timeout=settings.ORCHESTRATION_REQUEST_TIMEOUT) @@ -197,9 +228,9 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): if service_instantiation.failed: self._logger.error("Service instantiation %s failed", self.service_instance_name) raise onap_test_exceptions.ServiceInstantiateException - else: - service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name) - self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name) + + service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name) + self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name) @YamlTemplateBaseStep.store_state(cleanup=True) def cleanup(self) -> None: diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py index aacecc3..af569fe 100644 --- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py +++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py @@ -60,6 +60,10 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep): return self._yaml_template return self.parent.yaml_template + @property + def model_yaml_template(self) -> dict: + return {} + @property def service_name(self) -> str: """Service name. diff --git a/src/onaptests/steps/instantiate/vl_ala_carte.py b/src/onaptests/steps/instantiate/vl_ala_carte.py index 3bb293a..158e437 100644 --- a/src/onaptests/steps/instantiate/vl_ala_carte.py +++ b/src/onaptests/steps/instantiate/vl_ala_carte.py @@ -55,6 +55,10 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep): return self._yaml_template return self.parent.yaml_template + @property + def model_yaml_template(self) -> dict: + return {} + @property def service_name(self) -> str: """Service name. diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py index b02c7ea..8dbec78 100644 --- a/src/onaptests/steps/instantiate/vnf_ala_carte.py +++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py @@ -53,6 +53,10 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep): return self._yaml_template return self.parent.yaml_template + @property + def model_yaml_template(self) -> dict: + return {} + @property def service_name(self) -> str: """Service name. -- cgit 1.2.3-korg