-
Notifications
You must be signed in to change notification settings - Fork 1.2k
cloudutils: fix warning, error during kvm agent installation #11318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,8 +45,11 @@ def getDefaultNetwork(): | |||||
| 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") | ||||||
|
||||||
| raise CloudRuntimeException("Output for the default route incomplete") | |
| raise CloudRuntimeException("Output for the default route incomplete: '%s' (expected '<GATEWAY> <DEVICE>')" % output) |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting by a literal space can yield empty tokens when the output contains multiple spaces or tabs (common in shell output), causing dev to become an empty string despite len(result) >= 2. Use whitespace splitting to normalize tokens, e.g., parts = output.split(), then gateway = parts[0], dev = parts[1], or use a regex like m = re.match(r'(\S+)\s+(\S+)', output).
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not work on either ubuntu or rocky/ol
the line looks like
inet 10.0.34.xxx netmask 255.255.240.0 broadcast 10.0.47.255
we can fix it later
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -63,7 +63,7 @@ def getStdout(self): | |||||
| 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') | ||||||
|
||||||
| return self.stdout.decode('utf-8').strip('\n').split('\n') | |
| return self.stdout.decode('utf-8').splitlines() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These regexes should use \s* (or \s+) for whitespace and escape dynamic components to prevent unintended regex metacharacter interpretation. Example: name = re.escape(entry.name); value = re.escape(entry.value); then build patterns with r'^\s*' + name + r'\s*=\s*' + value (or r'^\s*' + name + r'\s+' + value). Also, r'\ *' is unusual; prefer clear whitespace classes.