diff --git a/python/lib/cloudutils/configFileOps.py b/python/lib/cloudutils/configFileOps.py index c061071b96e..f4d704af783 100644 --- a/python/lib/cloudutils/configFileOps.py +++ b/python/lib/cloudutils/configFileOps.py @@ -68,14 +68,14 @@ class configFileOps: for entry in self.entries: if entry.op == "add": if entry.separator == "=": - matchString = "^\ *" + entry.name + ".*" + matchString = r"^\ *" + entry.name + ".*" elif entry.separator == " ": - matchString = "^\ *" + entry.name + "\ *" + entry.value + matchString = r"^\ *" + entry.name + r"\ *" + entry.value else: if entry.separator == "=": - matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value + matchString = r"^\ *" + entry.name + r"\ *=\ *" + entry.value else: - matchString = "^\ *" + entry.name + "\ *" + entry.value + matchString = r"^\ *" + entry.name + r"\ *" + entry.value match = re.match(matchString, line) if match is not None: diff --git a/python/lib/cloudutils/networkConfig.py b/python/lib/cloudutils/networkConfig.py index ac51f92aa58..827664bbc73 100644 --- a/python/lib/cloudutils/networkConfig.py +++ b/python/lib/cloudutils/networkConfig.py @@ -45,8 +45,11 @@ class networkConfig: if not cmd.isSuccess(): logging.debug("Failed to get default route") raise CloudRuntimeException("Failed to get default route") - - result = cmd.getStdout().split(" ") + output = cmd.getStdout().strip() + result = output.split(" ") + if len(result) < 2: + logging.debug("Output for the default route incomplete: %s. It should have been ' '" % output) + raise CloudRuntimeException("Output for the default route incomplete") gateway = result[0] dev = result[1] @@ -150,10 +153,10 @@ class networkConfig: if line.find("HWaddr") != -1: macAddr = line.split("HWaddr ")[1].strip(" ") elif line.find("inet ") != -1: - m = re.search("addr:(.*)\ *Bcast:(.*)\ *Mask:(.*)", line) + m = re.search(r"addr:([^\s]+)\s*Bcast:([^\s]+)\s*Mask:([^\s]+)", line) if m is not None: - ipAddr = m.group(1).rstrip(" ") - netmask = m.group(3).rstrip(" ") + ipAddr = m.group(1).strip() + netmask = m.group(3).strip() if networkConfig.isBridgePort(dev): type = "brport" diff --git a/python/lib/cloudutils/utilities.py b/python/lib/cloudutils/utilities.py index ce50516193e..95044de5558 100755 --- a/python/lib/cloudutils/utilities.py +++ b/python/lib/cloudutils/utilities.py @@ -63,7 +63,7 @@ class bash: return self.stdout.decode('utf-8').strip('\n') def getLines(self): - return self.stdout.decode('utf-8').strip('\n') + return self.stdout.decode('utf-8').strip('\n').split('\n') def getStderr(self): return self.stderr.decode('utf-8').strip('\n')