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
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:
- 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"
"""
- 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"
"""
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)
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)