aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/onboard/cds.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/onaptests/steps/onboard/cds.py')
-rw-r--r--src/onaptests/steps/onboard/cds.py66
1 files changed, 61 insertions, 5 deletions
diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py
index 6ee0ae1..f137adb 100644
--- a/src/onaptests/steps/onboard/cds.py
+++ b/src/onaptests/steps/onboard/cds.py
@@ -3,6 +3,7 @@
from abc import ABC
from pathlib import Path
+from typing import Optional
from kubernetes import client, config
from onapsdk.cds import Blueprint, DataDictionarySet
@@ -24,6 +25,12 @@ class CDSBaseStep(BaseStep, ABC):
class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep):
"""Expose CDS blueprintsprocessor port."""
+ def __init__(self, cleanup: bool) -> None:
+ """Initialize step."""
+ super().__init__(cleanup=cleanup)
+ self.service_name: str = "cds-blueprints-processor-http"
+ self.client: Optional[client.CoreV1Api] = None
+
@property
def description(self) -> str:
"""Step description."""
@@ -40,13 +47,36 @@ class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep):
"""
super().execute()
config.load_kube_config(settings.K8S_CONFIG)
- k8s_client = client.CoreV1Api()
- k8s_client.patch_namespaced_service(
- "cds-blueprints-processor-http",
+ self.k8s_client = client.CoreV1Api()
+ self.k8s_client.patch_namespaced_service(
+ self.service_name,
settings.K8S_NAMESPACE,
{"spec": {"ports": [{"port": 8080, "nodePort": 30449}], "type": "NodePort"}}
)
+ def cleanup(self) -> None:
+ """Step cleanup.
+
+ Restore CDS blueprintprocessor service.
+
+ """
+ self.k8s_client.patch_namespaced_service(
+ self.service_name,
+ settings.K8S_NAMESPACE,
+ [
+ {
+ "op": "remove",
+ "path": "/spec/ports/0/nodePort"
+ },
+ {
+ "op": "replace",
+ "path": "/spec/type",
+ "value": "ClusterIP"
+ }
+ ]
+ )
+ return super().cleanup()
+
class BootstrapBlueprintprocessor(CDSBaseStep):
"""Bootstrap blueprintsprocessor."""
@@ -121,8 +151,8 @@ class CbaEnrichStep(CDSBaseStep):
"""
super().execute()
blueprint: Blueprint = Blueprint.load_from_file(settings.CDS_CBA_UNENRICHED)
- blueprint.enrich()
- blueprint.save(settings.CDS_CBA_ENRICHED)
+ enriched: Blueprint = blueprint.enrich()
+ enriched.save(settings.CDS_CBA_ENRICHED)
@BaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -133,3 +163,29 @@ class CbaEnrichStep(CDSBaseStep):
"""
super().cleanup()
Path(settings.CDS_CBA_ENRICHED).unlink()
+
+
+class CbaPublishStep(CDSBaseStep):
+ """Publish CBA file step."""
+
+ def __init__(self, cleanup=False) -> None:
+ """Initialize CBA publish step."""
+ super().__init__(cleanup=cleanup)
+ self.add_step(CbaEnrichStep(cleanup=cleanup))
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Publish CBA file."
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ """Enrich CBA file.
+
+ Use settings values:
+ - CDS_DD_FILE.
+
+ """
+ super().execute()
+ blueprint: Blueprint = Blueprint.load_from_file(settings.CDS_CBA_ENRICHED)
+ blueprint.publish()