summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaofeng Wang <xiaofengw@vmware.com>2019-10-17 15:18:44 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-10-17 15:18:44 +0000
commitecb501b84338f078be18c38c68c3ce87fed3584b (patch)
tree0861c97c0fcf444b4035795055f18cef161273e8
parenta86829d32284ea4842f13035442b1a5127997018 (diff)
downloadvyos-cloud-init-ecb501b84338f078be18c38c68c3ce87fed3584b.tar.gz
vyos-cloud-init-ecb501b84338f078be18c38c68c3ce87fed3584b.zip
guestcust_util: handle special characters in config file
Handle the special characters when reading VM Tools configure file. For example, the key and value may contain _, - and . etc.
-rw-r--r--cloudinit/sources/helpers/vmware/imc/guestcust_util.py2
-rw-r--r--tests/unittests/test_vmware/test_guestcust_util.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
index eb78172e..3d369d04 100644
--- a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
+++ b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
@@ -138,7 +138,7 @@ def get_tools_config(section, key, defaultVal):
try:
(outText, _) = util.subp(cmd)
- m = re.match(r'([a-zA-Z0-9 ]+)=(.*)', outText)
+ m = re.match(r'([^=]+)=(.*)', outText)
if m:
retValue = m.group(2).strip()
logger.debug("Get tools config: [%s] %s = %s",
diff --git a/tests/unittests/test_vmware/test_guestcust_util.py b/tests/unittests/test_vmware/test_guestcust_util.py
index b8fa9942..b175a998 100644
--- a/tests/unittests/test_vmware/test_guestcust_util.py
+++ b/tests/unittests/test_vmware/test_guestcust_util.py
@@ -62,4 +62,11 @@ class TestGuestCustUtil(CiTestCase):
get_tools_config('section', 'key', 'defaultVal'),
'Bar=Wark')
+ # value contains specific characters
+ with mock.patch.object(util, 'subp',
+ return_value=('[a] b.c_d=e-f', b'')):
+ self.assertEqual(
+ get_tools_config('section', 'key', 'defaultVal'),
+ 'e-f')
+
# vi: ts=4 expandtab