diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py index 830cd64b..d84004bd 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py @@ -6,7 +6,7 @@ """ import logging from dataclasses import dataclass -from typing import Dict, Optional +from typing import Dict, Optional, Union from mashumaro import DataClassDictMixin from mashumaro.config import BaseConfig @@ -14,6 +14,10 @@ logger = logging.getLogger(__name__) +# Case in-sensitive values that are considered invalid +_INVALID_VALUES = ["none", "null", ""] + + @dataclass class AqMetadata(DataClassDictMixin): """ @@ -48,8 +52,33 @@ class Config(BaseConfig): def override_from_vm_meta(self, vm_meta: Dict[str, str]): """ Overrides the values in the metadata with the values from the VM's - metadata + metadata if they are present and sane """ for attr, alias in self.Config.aliases.items(): - if alias in vm_meta: - setattr(self, attr, vm_meta[alias]) + if alias not in vm_meta: + continue + + if not self._is_metadata_val_valid(vm_meta[alias]): + logger.warning( + "Invalid metadata value '%s' found for metadata property '%s', skipping", + vm_meta[alias], + alias, + ) + continue + + setattr(self, attr, vm_meta[alias]) + + @staticmethod + def _is_metadata_val_valid(val: Union[str, None]) -> bool: + """ + Tests if an individual metadata value is sane, i.e. + a str which is not null, or a blocked value. + If this is valid, it returns true + """ + if not val: + return False + + user_val = val.lower().strip() + if user_val in _INVALID_VALUES: + return False + return True diff --git a/OpenStack-Rabbit-Consumer/tests/test_aq_metadata.py b/OpenStack-Rabbit-Consumer/tests/test_aq_metadata.py index 39b109ac..a3a8c662 100644 --- a/OpenStack-Rabbit-Consumer/tests/test_aq_metadata.py +++ b/OpenStack-Rabbit-Consumer/tests/test_aq_metadata.py @@ -62,6 +62,33 @@ def test_aq_metadata_override_all(image_metadata): assert returned.aq_os_version == "osversion_mock" +def test_aq_metadata_override_with_none_values(image_metadata): + """ + Tests that any invalid values, such as none, null or + whitespace are all ignored when overriding from the image + layer + """ + returned = AqMetadata.from_dict(image_metadata) + returned.override_from_vm_meta( + { + "AQ_ARCHETYPE": "archetype_mock_override", + "AQ_DOMAIN": "None", + "AQ_PERSONALITY": "null", + "AQ_OS": "none", + "AQ_OSVERSION": " ", # Space intentionally left + "AQ_SANDBOX": None, + } + ) + + assert returned.aq_archetype == "archetype_mock_override" + + reference_metadata = AqMetadata.from_dict(image_metadata) + assert returned.aq_domain == reference_metadata.aq_domain + assert returned.aq_os == reference_metadata.aq_os + assert returned.aq_os_version == reference_metadata.aq_os_version + assert returned.aq_sandbox == reference_metadata.aq_sandbox + + def test_aq_metadata_sandbox(image_metadata): """ Tests the sandbox value in an AQ metadata object diff --git a/OpenStack-Rabbit-Consumer/version.txt b/OpenStack-Rabbit-Consumer/version.txt index cb2b00e4..fd2a0186 100644 --- a/OpenStack-Rabbit-Consumer/version.txt +++ b/OpenStack-Rabbit-Consumer/version.txt @@ -1 +1 @@ -3.0.1 +3.1.0 diff --git a/charts/rabbit-consumer/Chart.yaml b/charts/rabbit-consumer/Chart.yaml index 6b0e4c52..327b042c 100644 --- a/charts/rabbit-consumer/Chart.yaml +++ b/charts/rabbit-consumer/Chart.yaml @@ -6,10 +6,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.7.1 +version: 1.8.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v3.0.1" +appVersion: "v3.1.0"