opennebula: fix shell variables parsing
Fix parsing of the empty values written as: KEY="" KEY='' Change-Id: I56ea03da5d78c01af2647444b825bf63d5146137
This commit is contained in:
parent
28f4fbbd45
commit
27d6fd01d6
@ -88,12 +88,14 @@ class OpenNebulaService(base.BaseMetadataService):
|
||||
new_content = sep.join(lines)
|
||||
# get pairs
|
||||
pairs = {}
|
||||
pattern = (br"(?P<key>\w+)=(['\"](?P<str_value>[\s\S]+?)['\"]|"
|
||||
br"(?P<int_value>\d+))(?=\s+\w+=)")
|
||||
pattern = (br"(?P<key>\w+)=((?P<int_value>\d+)|"
|
||||
br"['\"](?P<str_value>[\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
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user