From 18642f67fcd7268a914fb6632f0f755336e8ba24 Mon Sep 17 00:00:00 2001 From: amine ezziati Date: Fri, 24 Jul 2020 09:08:42 +0200 Subject: Add CLAMP E2E tests Issue-ID: TEST-240 Signed-off-by: amine ezziati Change-Id: Ib612f1670aca10d9ac9f15fadb9cab58a7d8e5a8 Signed-off-by: mrichomme --- src/onaptests/steps/onboard/clamp.py | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/onaptests/steps/onboard/clamp.py (limited to 'src/onaptests/steps/onboard/clamp.py') diff --git a/src/onaptests/steps/onboard/clamp.py b/src/onaptests/steps/onboard/clamp.py new file mode 100644 index 0000000..8f6b6bf --- /dev/null +++ b/src/onaptests/steps/onboard/clamp.py @@ -0,0 +1,91 @@ +#!/usr/bin/python +# http://www.apache.org/licenses/LICENSE-2.0 +"""Clamp Onboard service class.""" +from yaml import load +from onapsdk.sdc.service import Service +from onapsdk.sdc.vf import Vf + +from onapsdk.configuration import settings + +from ..base import YamlTemplateBaseStep +from .service import YamlTemplateVfOnboardStep + +class OnboardClampStep(YamlTemplateBaseStep): + """Onboard class to create CLAMP templates.""" + + def __init__(self, cleanup=False): + """Initialize Clamp Onboard object.""" + super().__init__(cleanup=cleanup) + self._yaml_template: dict = None + self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup)) + # if "service_name" in kwargs: + # self.service_name = kwargs['service_name'] + # else: + # raise ValueError("Service Name to define") + # self.vf_list = [] + # self.vsp_list = [] + # self.set_logger() + + @property + def yaml_template(self) -> dict: + """Step 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._yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + self._yaml_template: dict = load(yaml_template) + return self._yaml_template + return self.parent.yaml_template + + @property + def service_name(self) -> str: + """Service name. + + Get from YAML template if it's a root step, get from parent otherwise. + + Returns: + str: Service name + + """ + if self.is_root: + return next(iter(self.yaml_template.keys())) + else: + return self.parent.service_name + + @YamlTemplateBaseStep.store_state + def execute(self): + """Onboard service.""" + super().execute() + # retrieve the Vf + vf = None + for sdc_vf in Vf.get_all(): + if sdc_vf.name == settings.VF_NAME: + vf = sdc_vf + self._logger.debug("Vf retrieved %s", vf) + + service: Service = Service(name=self.service_name, + resources=[vf]) + service.create() + self._logger.info(" Service %s created", service) + + service.add_resource(vf) + + # we add the artifact to the first VNF + self._logger.info("Try to add blueprint to %s", vf.name) + payload_file = open(settings.CONFIGURATION_PATH + 'clampnode.yaml', 'rb') + data = payload_file.read() + self._logger.info("DCAE INVENTORY BLUEPRINT file retrieved") + service.add_artifact_to_vf(vnf_name=vf.name, + artifact_type="DCAE_INVENTORY_BLUEPRINT", + artifact_name="clampnode.yaml", + artifact=data) + payload_file.close() + service.checkin() + service.onboard() + self._logger.info("DCAE INVENTORY BLUEPRINT ADDED") -- cgit 1.2.3-korg