Change channel/track from config property to sw image 66/13266/2
authorPatricia Reinoso <patricia.reinoso@canonical.com>
Tue, 25 Apr 2023 09:22:00 +0000 (09:22 +0000)
committerbeierlm <mark.beierl@canonical.com>
Tue, 25 Apr 2023 22:50:35 +0000 (00:50 +0200)
channel corresponds to the "version" field in sw-image-desc

Change-Id: I2e14bd4bc0742ee3b5fa413a009a08359a168ad2
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
osm_lcm/temporal/juju_paas_activities.py
osm_lcm/tests/test_charm_info_utils.py

index a22122d..f2b9a16 100644 (file)
@@ -307,47 +307,27 @@ class CharmInfoUtils:
             CharmInfo  (object)
         """
         app_name = vdu.get("id")
-        channel = CharmInfoUtils._get_property_value(
-            "channel", vdu.get("configurable-properties")
-        )
-        entity_url = CharmInfoUtils._get_entity_url(
+        entity_url, channel = CharmInfoUtils._get_entity_url_and_channel(
             vdu.get("sw-image-desc"), sw_image_descs
         )
         return CharmInfo(app_name, channel, entity_url)
 
     @staticmethod
-    def _get_property_value(wanted_property: str, configurable_properties: list) -> str:
-        """Extract the value corresponding to a given key-value pairs in
-            vdu.configurable-properties
-
-        Args:
-            wanted_property (str): property used as key.
-            configurable_properties (list): list of configurable-properties in VDU.
-
-        Returns:
-            value of the wanted property  (str)
-        """
-        filtered_property = next(
-            filter(
-                lambda property: property.get("key") == wanted_property,
-                configurable_properties,
-            ),
-            None,
-        )
-        return filtered_property.get("value") if filtered_property else None
-
-    @staticmethod
-    def _get_entity_url(sw_image_desc_id: str, sw_image_descs: list) -> str:
+    def _get_entity_url_and_channel(
+        sw_image_desc_id: str, sw_image_descs: list
+    ) -> tuple:
         """Extract the image field for a given image_id
         Args:
             sw_image_desc_id (str): ID of the image used by a VDU.
             sw_image_descs (list): information of available images in the VNF.
 
         Returns:
-            image of the sw_image_desc_id (str)
+            image and version of the sw_image_desc_id (str)
         """
         filtered_image = next(
             filter(lambda image: image.get("id") == sw_image_desc_id, sw_image_descs),
             None,
         )
-        return filtered_image.get("image") if filtered_image else None
+        if filtered_image:
+            return filtered_image.get("image"), filtered_image.get("version")
+        return None, None
index fd1cd9b..8aca9dc 100644 (file)
@@ -17,10 +17,6 @@ from osm_lcm.temporal.juju_paas_activities import CharmInfoUtils
 from osm_common.dataclasses.temporal_dataclasses import CharmInfo
 import yaml
 
-nsr_id = "ea958ba5-4e58-4405-bf42-6e3be15d4c3a"
-vim_id = "70b47595-fafa-4f63-904b-fc3ada60eebb"
-expected_default_ns_model = "6e3be15d4c3a-fc3ada60eebb"
-
 vdu_nominal = """
 ---
 vdu:
@@ -35,29 +31,9 @@ vdu:
        - storage-id
      sw-image-desc: image-test2
      configurable-properties:
-       - key: "track"
+       - key: "property1"
          value: "latest"
-       - key: "channel"
-         value: "edge"
-"""
-
-vdu_no_channel = """
----
-vdu:
-   - id: test-vdu-id
-     name: test-vdu-name
-     int-cpd:
-       - id: internal
-         int-virtual-link-desc: network1
-       - id: mgmt
-     virtual-compute-desc: compute-id
-     virtual-storage-desc:
-       - storage-id
-     sw-image-desc: image-test2
-     configurable-properties:
-       - key: "track"
-         value: "latest"
-       - key: "key"
+       - key: "property2"
          value: "edge"
 """
 
@@ -75,43 +51,34 @@ vdu:
        - storage-id
      sw-image-desc: invalid_image
      configurable-properties:
-       - key: "track"
+       - key: "property1"
          value: "latest"
-       - key: "key"
+       - key: "property2"
          value: "edge"
 """
 
-vdu_no_sw_image_desc = """
+sw_image_desc_nominal = """
 ---
-vdu:
-   - id: test-vdu-id
-     name: test-vdu-name
-     int-cpd:
-       - id: internal
-         int-virtual-link-desc: network1
-       - id: mgmt
-     virtual-compute-desc: compute-id
-     virtual-storage-desc:
-       - storage-id
-     sw-image-desc: invalid_image
-     configurable-properties:
-       - key: "track"
-         value: "latest"
-       - key: "key"
-         value: "edge"
+sw-image-desc:
+  - id: image-test1
+    name: charm-name1
+    image: ch:mysql
+    version: lastest/edge
+  - id: image-test2
+    name: charm-name2
+    image: ch:my-charm
+    version: 8.0/stable
 """
 
-sw_image_desc = """
+sw_image_desc_no_channel = """
 ---
 sw-image-desc:
   - id: image-test1
     name: charm-name1
     image: ch:mysql
-    version: "1.0"
   - id: image-test2
     name: charm-name2
     image: ch:my-charm
-    version: "1.0"
 """
 
 
@@ -124,28 +91,27 @@ class TestCharmInfoUtils(TestCase):
 
     def test_get_charm_info_nominal_case(self):
         vdu_descriptor = self.get_loaded_descriptor(vdu_nominal).get("vdu")
-        sw_image_descs = self.get_loaded_descriptor(sw_image_desc).get("sw-image-desc")
+        sw_image_descs = self.get_loaded_descriptor(sw_image_desc_nominal).get(
+            "sw-image-desc"
+        )
         result = self.charm_info_utils.get_charm_info(vdu_descriptor[0], sw_image_descs)
-        expected = CharmInfo("test-vdu-id", "edge", "ch:my-charm")
+        expected = CharmInfo("test-vdu-id", "8.0/stable", "ch:my-charm")
         self.assertEqual(result, expected)
 
     def test_get_charm_info_no_channel(self):
-        vdu_descriptor = self.get_loaded_descriptor(vdu_no_channel).get("vdu")
-        sw_image_descs = self.get_loaded_descriptor(sw_image_desc).get("sw-image-desc")
+        vdu_descriptor = self.get_loaded_descriptor(vdu_nominal).get("vdu")
+        sw_image_descs = self.get_loaded_descriptor(sw_image_desc_no_channel).get(
+            "sw-image-desc"
+        )
         result = self.charm_info_utils.get_charm_info(vdu_descriptor[0], sw_image_descs)
         expected = CharmInfo("test-vdu-id", None, "ch:my-charm")
         self.assertEqual(result, expected)
 
     def test_get_charm_info_invalid_image(self):
         vdu_descriptor = self.get_loaded_descriptor(vdu_invalid_image).get("vdu")
-        sw_image_descs = self.get_loaded_descriptor(sw_image_desc).get("sw-image-desc")
-        result = self.charm_info_utils.get_charm_info(vdu_descriptor[0], sw_image_descs)
-        expected = CharmInfo("test-vdu-id", None, None)
-        self.assertEqual(result, expected)
-
-    def test_get_charm_info_no_sw_image_desc(self):
-        vdu_descriptor = self.get_loaded_descriptor(vdu_no_sw_image_desc).get("vdu")
-        sw_image_descs = self.get_loaded_descriptor(sw_image_desc).get("sw-image-desc")
+        sw_image_descs = self.get_loaded_descriptor(sw_image_desc_nominal).get(
+            "sw-image-desc"
+        )
         result = self.charm_info_utils.get_charm_info(vdu_descriptor[0], sw_image_descs)
         expected = CharmInfo("test-vdu-id", None, None)
         self.assertEqual(result, expected)
@@ -154,5 +120,5 @@ class TestCharmInfoUtils(TestCase):
         vdu_descriptor = self.get_loaded_descriptor(vdu_nominal).get("vdu")
         sw_image_descs = []
         result = self.charm_info_utils.get_charm_info(vdu_descriptor[0], sw_image_descs)
-        expected = CharmInfo("test-vdu-id", "edge", None)
+        expected = CharmInfo("test-vdu-id", None, None)
         self.assertEqual(result, expected)