cloudutils: fix warning, error during kvm agent installation (#11318)

* cloudutils: fix warning, error during kvm agent installation

Fixes #10379

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* fix

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* Update utilities.py

---------

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2025-10-16 00:01:00 +05:30 committed by GitHub
parent b82369c241
commit eee43e534f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 10 deletions

View File

@ -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:

View File

@ -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 '<GATEWAY> <DEVICE>'" % 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"

View File

@ -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')