diff options
Diffstat (limited to 'src/onaptests/steps/onboard/vendor.py')
-rw-r--r-- | src/onaptests/steps/onboard/vendor.py | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/src/onaptests/steps/onboard/vendor.py b/src/onaptests/steps/onboard/vendor.py index ae93738..5be358b 100644 --- a/src/onaptests/steps/onboard/vendor.py +++ b/src/onaptests/steps/onboard/vendor.py @@ -1,7 +1,7 @@ from onapsdk.configuration import settings from onapsdk.sdc.vendor import Vendor -from ..base import BaseStep +from ..base import BaseStep, YamlTemplateBaseStep class VendorOnboardStep(BaseStep): @@ -47,3 +47,87 @@ class VendorOnboardStep(BaseStep): vendor.archive() vendor.delete() super().cleanup() + + +class YamlTemplateVendorOnboardStep(YamlTemplateBaseStep): + """Vendor onboard using YAML template step.""" + + def __init__(self): + """Initialize step. """ + super().__init__(cleanup=settings.CLEANUP_FLAG) + + @property + def description(self) -> str: + """Step description.""" + return "Onboard vendor described in YAML file in SDC." + + @property + def component(self) -> str: + """Component name.""" + return "SDC" + + def check_preconditions(self, cleanup=False) -> bool: + if not super().check_preconditions(cleanup): + return False + if cleanup: + return settings.SDC_CLEANUP + return True + + @property + def yaml_template(self) -> dict: + """YAML template. + + Get YAML template from parent. + + Returns: + dict: YAML template + + """ + if settings.MODEL_YAML_TEMPLATE: + return self.model_yaml_template + return self.parent.yaml_template + + @property + def model_yaml_template(self) -> dict: + """Model YAML template. + + Get model YAML template from parent. + + Returns: + dict: YAML template + + """ + return self.parent.model_yaml_template + + @YamlTemplateBaseStep.store_state + def execute(self): + """Onboard Vsps from YAML template. + + Use settings values: + - VENDOR_NAME. + """ + super().execute() + if "vnfs" in self.yaml_template: + for vnf in self.yaml_template["vnfs"]: + vendor: Vendor = Vendor(name=f"{vnf['vnf_name']}") + vendor.onboard() + elif "pnfs" in self.yaml_template: + for pnf in self.yaml_template["pnfs"]: + vendor: Vendor = Vendor(name=f"{pnf['pnf_name']}") + vendor.onboard() + + @YamlTemplateBaseStep.store_state(cleanup=True) + def cleanup(self) -> None: + if "vnfs" in self.yaml_template: + for vnf in self.yaml_template["vnfs"]: + vendor: Vendor = Vendor(name=f"{vnf['vnf_name']}") + if vendor.exists(): + vendor.archive() + vendor.delete() + elif "pnfs" in self.yaml_template: + for pnf in self.yaml_template["pnfs"]: + vendor: Vendor = Vendor(name=f"{pnf['pnf_name']}") + if vendor.exists(): + vendor.archive() + vendor.delete() + super().cleanup() |