Skip to content

Conversation

@shwstppr
Copy link
Contributor

Description

Fixes #10379

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@boring-cyborg boring-cyborg bot added the Python Warning... Python code Ahead! label Jul 29, 2025
@codecov
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.17%. Comparing base (4d95f08) to head (da0dc45).
⚠️ Report is 5 commits behind head on 4.20.

Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #11318   +/-   ##
=========================================
  Coverage     16.17%   16.17%           
- Complexity    13297    13299    +2     
=========================================
  Files          5656     5656           
  Lines        498331   498349   +18     
  Branches      60476    60480    +4     
=========================================
+ Hits          80591    80597    +6     
- Misses       408767   408779   +12     
  Partials       8973     8973           
Flag Coverage Δ
uitests 4.00% <ø> (ø)
unittests 17.02% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pearl1594
Copy link
Contributor

should this be targeted towards 4.20?

@weizhouapache weizhouapache added this to the 4.20.2 milestone Sep 3, 2025
@weizhouapache weizhouapache self-assigned this Sep 8, 2025
@weizhouapache weizhouapache changed the base branch from main to 4.20 September 8, 2025 07:36
@weizhouapache weizhouapache changed the base branch from 4.20 to main September 8, 2025 07:36
@weizhouapache
Copy link
Member

should this be targeted towards 4.20?

+1

@shwstppr can you maybe rebase it with 4.20 ?

@shwstppr
Copy link
Contributor Author

shwstppr commented Sep 8, 2025

@weizhouapache will do

@shwstppr
Copy link
Contributor Author

shwstppr commented Sep 8, 2025

@blueorangutan package

@blueorangutan
Copy link

@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@weizhouapache
Copy link
Member

thanks @shwstppr
I will test it

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 14903

@weizhouapache
Copy link
Member

@blueorangutan test ubuntu24 kvm-ubuntu24 keepEnv

@blueorangutan
Copy link

@weizhouapache a [SL] Trillian-Jenkins test job (ubuntu24 mgmt + kvm-ubuntu24) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-14246)

@weizhouapache
Copy link
Member

@blueorangutan test ubuntu24 kvm-ubuntu24

@blueorangutan
Copy link

@weizhouapache a [SL] Trillian-Jenkins test job (ubuntu24 mgmt + kvm-ubuntu24) has been kicked to run smoke tests

@weizhouapache
Copy link
Member

there is only a warning now

Compiling '/usr/lib/python3/dist-packages/cloudutils/networkConfig.py'...\r\n/usr/lib/python3/dist-packages/cloudutils/networkConfig.py:156: SyntaxWarning: invalid escape sequence '\\ '\r\n  m = re.search(\"addr:(.*)\\ *Bcast:(.*)\\ *Mask:(.*)\", line)\r\n

@shwstppr
can you fix it as well ? thanks

@weizhouapache weizhouapache removed this from the 4.20.2 milestone Sep 12, 2025
@weizhouapache weizhouapache added this to the 4.20.3 milestone Sep 12, 2025
@shwstppr
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15426

@DaanHoogland
Copy link
Contributor

@blueorangutan test ubuntu24 kvm-ubuntu24

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ubuntu24 mgmt + kvm-ubuntu24) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-14644)
Environment: kvm-ubuntu24 (x2), zone: Advanced Networking with Mgmt server u24
Total time taken: 63022 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr11318-t14644-kvm-ubuntu24.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@shwstppr shwstppr marked this pull request as ready for review October 14, 2025 13:20
@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-14670)

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-14672)

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-14674)

@weizhouapache
Copy link
Member

looks good

4.21.0.0

Setting up cloudstack-common (4.21.0.0-shapeblue0) ...
Listing '/usr/lib/python3/dist-packages/cloudutils'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/__init__.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/cloudException.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/configFileOps.py'...
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:71: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + ".*"
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:73: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *" + entry.value
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:73: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *" + entry.value
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:76: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:76: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:78: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *" + entry.value
/usr/lib/python3/dist-packages/cloudutils/configFileOps.py:78: SyntaxWarning: invalid escape sequence '\ '
  matchString = "^\ *" + entry.name + "\ *" + entry.value
Compiling '/usr/lib/python3/dist-packages/cloudutils/db.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/globalEnv.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/networkConfig.py'...
/usr/lib/python3/dist-packages/cloudutils/networkConfig.py:153: SyntaxWarning: invalid escape sequence '\ '
  m = re.search("addr:(.*)\ *Bcast:(.*)\ *Mask:(.*)", line)
Compiling '/usr/lib/python3/dist-packages/cloudutils/serviceConfig.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/serviceConfigServer.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/syscfg.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/utilities.py'...
Scanning processes...                                                                                       

with this PR

Setting up cloudstack-common (4.20.2.0-shapeblue16348~xenial) ...
Listing '/usr/lib/python3/dist-packages/cloudutils'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/__init__.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/cloudException.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/configFileOps.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/db.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/globalEnv.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/networkConfig.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/serviceConfig.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/serviceConfigServer.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/syscfg.py'...
Compiling '/usr/lib/python3/dist-packages/cloudutils/utilities.py'...
Scanning processes...                                                                                                                                                        
Scanning candidates...                                                                                                                                                       
Scanning linux images...       

Copy link
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@shwstppr shwstppr requested a review from Copilot October 15, 2025 16:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes parsing and regex issues in cloudutils that led to warnings/errors during KVM agent installation by tightening output parsing and improving regex usage.

  • Make getLines return actual lines rather than a single string.
  • Harden default route parsing and add validation for expected output shape.
  • Improve regex usage in network and config parsing (raw strings, tighter patterns).

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
python/lib/cloudutils/utilities.py Change getLines to return a list of lines rather than a single string.
python/lib/cloudutils/networkConfig.py Add stricter parsing/validation for default route output; refine regex for inet/Bcast/Mask extraction.
python/lib/cloudutils/configFileOps.py Switch to raw string regex patterns for matching config lines.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +48 to 55
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]

Copy link

Copilot AI Oct 15, 2025

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).

Copilot uses AI. Check for mistakes.
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")
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raised exception lacks context for troubleshooting. Consider including the actual output and the expected format in the exception message, e.g., raise CloudRuntimeException("Output for the default route incomplete: '%s' (expected ' ')" % output).

Suggested change
raise CloudRuntimeException("Output for the default route incomplete")
raise CloudRuntimeException("Output for the default route incomplete: '%s' (expected '<GATEWAY> <DEVICE>')" % output)

Copilot uses AI. Check for mistakes.

def getLines(self):
return self.stdout.decode('utf-8').strip('\n')
return self.stdout.decode('utf-8').strip('\n').split('\n')
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use splitlines() to robustly handle different newline conventions and avoid edge cases with trailing newlines: return self.stdout.decode('utf-8').splitlines().

Suggested change
return self.stdout.decode('utf-8').strip('\n').split('\n')
return self.stdout.decode('utf-8').splitlines()

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +78
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
Copy link

Copilot AI Oct 15, 2025

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.

Copilot uses AI. Check for mistakes.
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)
Copy link
Member

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

@weizhouapache weizhouapache merged commit eee43e5 into apache:4.20 Oct 15, 2025
26 checks passed
@DaanHoogland DaanHoogland deleted the fix-kvm-agent-install-warnings branch October 16, 2025 08:32
@weizhouapache weizhouapache modified the milestones: 4.20.3, 4.20.2 Oct 16, 2025
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Oct 17, 2025
…11318)

* cloudutils: fix warning, error during kvm agent installation

Fixes apache#10379

Signed-off-by: Abhishek Kumar <[email protected]>

* fix

Signed-off-by: Abhishek Kumar <[email protected]>

* Update utilities.py

---------

Signed-off-by: Abhishek Kumar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ubuntu KVM agent installation warnings

5 participants