fix(configurations): LCM adapted for new configuration container in IM 28/10428/1
authorgarciaale <agarcia@whitestack.com>
Wed, 17 Feb 2021 22:09:12 +0000 (19:09 -0300)
committergarciaale <agarcia@whitestack.com>
Tue, 2 Mar 2021 14:13:27 +0000 (11:13 -0300)
Change-Id: I5511a659e257a42d6bbdb48c495f93078bd12928
Signed-off-by: agarcia <agarcia@whitestack.com>
osm_lcm/data_utils/vnfd.py
osm_lcm/ns.py
osm_lcm/tests/test_db_descriptors.py

index f312e57..16257db 100644 (file)
@@ -23,7 +23,6 @@
 ##
 
 from osm_lcm.data_utils import list_utils
-from osm_lcm.lcm_utils import get_iterable
 
 
 def get_lcm_operations_configuration(vnfd):
@@ -89,26 +88,17 @@ def get_vdu_profile(vnfd, vdu_profile_id):
         lambda vdu_profile: vdu_profile["id"] == vdu_profile_id)
 
 
-def get_vnf_configuration(vnfd):
-    if "vnf-configuration-id" not in vnfd.get("df")[0]:
+def get_configuration(vnfd, entity_id):
+    lcm_ops_config = vnfd.get("df")[0].get("lcm-operations-configuration")
+    if not lcm_ops_config:
         return None
-    vnf_config_id = vnfd.get("df")[0]["vnf-configuration-id"]
-    return list_utils.find_in_list(
-        vnfd.get("vnf-configuration", {}),
-        lambda vnf_config: vnf_config["id"] == vnf_config_id)
-
-
-def get_vdu_configuration(vnfd, vdu_id):
-    vdu_profile = get_vdu_profile(vnfd, vdu_id)
-    return list_utils.find_in_list(
-        vnfd.get("vdu-configuration", ()),
-        lambda vdu_configuration: vdu_configuration["id"] == vdu_profile["vdu-configuration-id"])
-
-
-def get_kdu_configuration(vnfd, kdu_name):
-    for kdu in get_iterable(vnfd, "kdu"):
-        if kdu_name == kdu["name"]:
-            return kdu.get("kdu-configuration")
+    ops_vnf = lcm_ops_config.get("operate-vnf-op-config")
+    if not ops_vnf:
+        return None
+    day12ops = ops_vnf.get("day1-2", [])
+    list_utils.find_in_list(
+        day12ops,
+        lambda configuration: configuration["id"] == entity_id)
 
 
 def get_virtual_link_profiles(vnfd):
index 26eed85..102d01f 100644 (file)
@@ -28,9 +28,9 @@ from osm_lcm import ROclient
 from osm_lcm.ng_ro import NgRoClient, NgRoException
 from osm_lcm.lcm_utils import LcmException, LcmExceptionNoMgmtIP, LcmBase, deep_get, get_iterable, populate_dict
 from osm_lcm.data_utils.nsd import get_vnf_profiles
-from osm_lcm.data_utils.vnfd import get_vnf_configuration, get_vdu_list, get_vdu_profile, \
+from osm_lcm.data_utils.vnfd import get_vdu_list, get_vdu_profile, \
     get_ee_sorted_initial_config_primitive_list, get_ee_sorted_terminate_config_primitive_list, \
-    get_kdu_list, get_virtual_link_profiles, get_vdu, get_vdu_configuration, get_kdu_configuration, \
+    get_kdu_list, get_virtual_link_profiles, get_vdu, get_configuration, \
     get_vdu_index, get_scaling_aspect, get_number_of_instances
 from osm_lcm.data_utils.list_utils import find_in_list
 from osm_lcm.data_utils.vnfr import get_osm_params
@@ -338,7 +338,6 @@ class NsLcm(LcmBase):
         # remove unused by RO configuration, monitoring, scaling and internal keys
         vnfd_RO.pop("_id", None)
         vnfd_RO.pop("_admin", None)
-        vnfd_RO.pop("vnf-configuration", None)
         vnfd_RO.pop("monitoring-param", None)
         vnfd_RO.pop("scaling-group-descriptor", None)
         vnfd_RO.pop("kdu", None)
@@ -742,8 +741,8 @@ class NsLcm(LcmBase):
                 self.logger.debug("NS > ssh_keys > {}".format(ssh_keys_all))
 
                 if ssh_keys_all:
-                    vdu_configuration = get_vdu_configuration(vnfd, vdur["vdu-id-ref"])
-                    vnf_configuration = get_vnf_configuration(vnfd)
+                    vdu_configuration = get_configuration(vnfd, vdur["vdu-id-ref"])
+                    vnf_configuration = get_configuration(vnfd, vnfd["id"])
                     if vdu_configuration and vdu_configuration.get("config-access") and \
                        vdu_configuration.get("config-access").get("ssh-access"):
                         vdur["ssh-keys"] = ssh_keys_all
@@ -1795,7 +1794,7 @@ class NsLcm(LcmBase):
                 if db_vnfr.get("additionalParamsForVnf"):
                     deploy_params.update(parse_yaml_strings(db_vnfr["additionalParamsForVnf"].copy()))
 
-                descriptor_config = get_vnf_configuration(vnfd)
+                descriptor_config = get_configuration(vnfd, vnfd["id"])
                 if descriptor_config:
                     self._deploy_n2vc(
                         logging_text=logging_text + "member_vnf_index={} ".format(member_vnf_index),
@@ -1820,7 +1819,7 @@ class NsLcm(LcmBase):
                 # Deploy charms for each VDU that supports one.
                 for vdud in get_vdu_list(vnfd):
                     vdu_id = vdud["id"]
-                    descriptor_config = get_vdu_configuration(vnfd, vdu_id)
+                    descriptor_config = get_configuration(vnfd, vdu_id)
                     vdur = find_in_list(db_vnfr["vdur"], lambda vdu: vdu["vdu-id-ref"] == vdu_id)
 
                     if vdur.get("additionalParams"):
@@ -1859,7 +1858,7 @@ class NsLcm(LcmBase):
                             )
                 for kdud in get_kdu_list(vnfd):
                     kdu_name = kdud["name"]
-                    descriptor_config = kdud.get('kdu-configuration')
+                    descriptor_config = get_configuration(vnfd, kdu_name)
                     if descriptor_config:
                         vdu_id = None
                         vdu_index = 0
@@ -2050,7 +2049,7 @@ class NsLcm(LcmBase):
             if db_vnfd_list:
                 for vnfd in db_vnfd_list:
                     db_vnfd = self.db.get_one("vnfds", {"_id": vnfd})
-                    db_vnf_relations = deep_get(db_vnfd, ('vnf-configuration', 'relation'))
+                    db_vnf_relations = get_configuration(db_vnfd, db_vnfd["id"]).get("relation", [])
                     if db_vnf_relations:
                         for r in db_vnf_relations:
                             # check if this VCA is in the relation
@@ -3043,16 +3042,13 @@ class NsLcm(LcmBase):
                     config_descriptor = db_nsr.get("ns-configuration")
                 elif vca.get("vdu_id"):
                     db_vnfd = db_vnfds_from_member_index[vca["member-vnf-index"]]
-                    vdud = next((vdu for vdu in db_vnfd.get("vdu", ()) if vdu["id"] == vca.get("vdu_id")), None)
-                    if vdud:
-                        config_descriptor = vdud.get("vdu-configuration")
+                    config_descriptor = get_configuration(db_vnfd, vca.get("vdu_id"))
                 elif vca.get("kdu_name"):
                     db_vnfd = db_vnfds_from_member_index[vca["member-vnf-index"]]
-                    kdud = next((kdu for kdu in db_vnfd.get("kdu", ()) if kdu["name"] == vca.get("kdu_name")), None)
-                    if kdud:
-                        config_descriptor = kdud.get("kdu-configuration")
+                    config_descriptor = get_configuration(db_vnfd, vca.get("kdu_name"))
                 else:
-                    config_descriptor = db_vnfds_from_member_index[vca["member-vnf-index"]].get("vnf-configuration")
+                    db_vnfd = db_vnfds_from_member_index[vca["member-vnf-index"]]
+                    config_descriptor = get_configuration(db_vnfd, db_vnfd["id"]) 
                 vca_type = vca.get("type")
                 exec_terminate_primitives = (not operation_params.get("skip_terminate_primitives") and
                                              vca.get("needed_terminate"))
@@ -3431,11 +3427,11 @@ class NsLcm(LcmBase):
             # look for primitive
             config_primitive_desc = descriptor_configuration = None
             if vdu_id:
-                descriptor_configuration = get_vdu_configuration(db_vnfd, vdu_id)
+                descriptor_configuration = get_configuration(db_vnfd, vdu_id)
             elif kdu_name:
-                descriptor_configuration = get_kdu_configuration(db_vnfd, kdu_name)
+                descriptor_configuration = get_configuration(db_vnfd, kdu_name)
             elif vnf_index:
-                descriptor_configuration = get_vnf_configuration(db_vnfd)
+                descriptor_configuration = get_configuration(db_vnfd, db_vnfd["id"])
             else:
                 descriptor_configuration = db_nsd.get("ns-configuration")
 
@@ -3466,8 +3462,8 @@ class NsLcm(LcmBase):
                     desc_params = parse_yaml_strings(db_vnfr.get("additionalParamsForVnf"))
             else:
                 desc_params = parse_yaml_strings(db_nsr.get("additionalParamsForNs"))
-            if kdu_name and get_kdu_configuration(db_vnfd, kdu_name):
-                kdu_configuration = get_kdu_configuration(db_vnfd, kdu_name)
+            if kdu_name and get_configuration(db_vnfd, kdu_name):
+                kdu_configuration = get_configuration(db_vnfd, kdu_name)
                 actions = set()
                 for primitive in kdu_configuration.get("initial-config-primitive", []):
                     actions.add(primitive["name"])
@@ -3819,7 +3815,9 @@ class NsLcm(LcmBase):
                             "executing pre-scale scaling-config-action '{}'".format(vnf_config_primitive)
 
                         # look for primitive
-                        for config_primitive in db_vnfd.get("vnf-configuration", {}).get("config-primitive", ()):
+                        for config_primitive in (get_configuration(
+                            db_vnfd, db_vnfd["id"]
+                        ) or {}).get("config-primitive", ()):
                             if config_primitive["name"] == vnf_config_primitive:
                                 break
                         else:
index 080d88d..9b12feb 100644 (file)
@@ -953,14 +953,12 @@ db_vnfds_text = """
 
     df:
       - id: hackfest_default
-        vnf-configuration-id: vnf-configuration-example
         vdu-profile:
           - id: mgmtVM
             min-number-of-instances: 1
           - id: dataVM
             min-number-of-instances: 1
             max-number-of-instances: 10
-            vdu-configuration-id: vdu-configuration-example
         instantiation-level:
           - id: default
             vdu-level:
@@ -996,32 +994,34 @@ db_vnfds_text = """
                 vnf-config-primitive-name-ref: touch
               - trigger: pre-scale-in
                 vnf-config-primitive-name-ref: touch
+        lcm-operations-configuration:
+          operate-vnf-op-config:
+            day1-2:
+            - id: hackfest3charmed-vnf
+              initial-config-primitive:
+                - seq: "1"
+                  name: config
+                  parameter:
+                    - name: ssh-hostname
+                      value: <rw_mgmt_ip>
+                    - name: ssh-username
+                      value: ubuntu
+                    - name: ssh-password
+                      value: osm4u
+                - seq: "2"
+                  name: touch
+                  parameter:
+                    - name: filename
+                      value: <touch_filename>
+              config-primitive:
+                - name: touch
+                  parameter:
+                    - data-type: STRING
+                      default-value: <touch_filename2>
+                      name: filename
+              juju:
+                charm: simple
 
-    vnf-configuration:
-      - id: vnf-configuration-example
-        initial-config-primitive:
-          - seq: "1"
-            name: config
-            parameter:
-              - name: ssh-hostname
-                value: <rw_mgmt_ip>
-              - name: ssh-username
-                value: ubuntu
-              - name: ssh-password
-                value: osm4u
-          - seq: "2"
-            name: touch
-            parameter:
-              - name: filename
-                value: <touch_filename>
-        config-primitive:
-          - name: touch
-            parameter:
-              - data-type: STRING
-                default-value: <touch_filename2>
-                name: filename
-        juju:
-          charm: simple
 -   _admin:
         created: 1575031727.5383403
         modified: 1575031727.5383403