diff options
author | Julien Fontaine <julien.fontaine@bell.ca> | 2021-08-04 15:52:02 -0400 |
---|---|---|
committer | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2021-10-19 06:44:23 -0400 |
commit | c3ef82f489b915095b7464fb119daf43b84f67f8 (patch) | |
tree | 5d6ce5b4896e4b0b0844dfccb0ebd59f2c72f244 /src/onaptests/steps/instantiate/service_macro.py | |
parent | 062f7ed7f73ed61dc3990c3a23403fd544ae6261 (diff) |
[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 <julien.fontaine@bell.ca>
Change-Id: I69d370eff4d383d5af135206476c65e4a56e4ee5
Diffstat (limited to 'src/onaptests/steps/instantiate/service_macro.py')
-rw-r--r-- | src/onaptests/steps/instantiate/service_macro.py | 65 |
1 files changed, 48 insertions, 17 deletions
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: @@ -76,6 +78,23 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): 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: |