diff --git a/cloudbaseinit/metadata/services/opennebulaservice.py b/cloudbaseinit/metadata/services/opennebulaservice.py index 9c8b8e78..f182288c 100644 --- a/cloudbaseinit/metadata/services/opennebulaservice.py +++ b/cloudbaseinit/metadata/services/opennebulaservice.py @@ -88,12 +88,14 @@ class OpenNebulaService(base.BaseMetadataService): new_content = sep.join(lines) # get pairs pairs = {} - pattern = (br"(?P\w+)=(['\"](?P[\s\S]+?)['\"]|" - br"(?P\d+))(?=\s+\w+=)") + pattern = (br"(?P\w+)=((?P\d+)|" + br"['\"](?P[\s\S]*?)['\"])(?=\s+\w+=)") for match in re.finditer(pattern, new_content): key = encoding.get_as_string(match.group("key")) - pairs[key] = (match.group("str_value") or - int(match.group("int_value"))) + val = match.group("str_value") + if match.group("int_value"): + val = int(match.group("int_value")) + pairs[key] = val return pairs @staticmethod diff --git a/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py b/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py index 5d3e96ba..d35a855f 100644 --- a/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py +++ b/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py @@ -145,6 +145,8 @@ class TestOpenNebulaService(_TestOpenNebulaService): d: e ' ivar=10 + TESTEMPTY='' + TESTEMPTY2="" """) if comment: content += "# A simple comment\n" @@ -152,6 +154,8 @@ class TestOpenNebulaService(_TestOpenNebulaService): content = content.replace("\n", "\r\n") pairs = self._service._parse_shell_variables(content.encode()) _pairs = { + "TESTEMPTY": b"", + "TESTEMPTY2": b"", "VAR1": b"1", "var2": b"abcdef", "VAR_VAR3": b"aaa.bbb.123.ccc",