Skip to content

Updates for deprecated modules in Python 3.12 and Invalid escape sequence issues - #2124

Merged
deveshjagwani merged 3 commits into
masterfrom
dev/dejagwan/moduleUpdates
Nov 27, 2025
Merged

Updates for deprecated modules in Python 3.12 and Invalid escape sequence issues#2124
deveshjagwani merged 3 commits into
masterfrom
dev/dejagwan/moduleUpdates

Conversation

@deveshjagwani

@deveshjagwani deveshjagwani commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

ADO Task: 34492797

Fix Python 3.12 compatibility issues

  • Replace distutils.version with packaging/distutils/custom fallback in WaagentLib.py
  • Replace imp module with importlib.util fallback in WAAgentUtil.py
  • Fix invalid escape sequences in HandlerUtil.py JSON processing
  • Add setuptools fallback for distutils removal in setup.py

Resolves VMBackup extension failure on Debian 12 with Python 3.12. All changes maintain backward compatibility with older Python versions.

Fix platform.dist() deprecation error for Python 3.8+

  • Added conditional import for distro package
  • Implemented multi-tier fallback strategy in get_dist_info()
  • Enhanced error handling with proper logging
  • Maintains backward compatibility across all Python versions
  • Resolves AttributeError: module 'platform' has no attribute 'dist'

Fix Python 3.13+ compatibility: Handle deprecated crypt module import

  • Add try/except block for crypt import to handle Python 3.13+ where crypt module was removed
  • Update gen_password_hash() to gracefully handle missing crypt module
  • Add TODO comment for future cleanup of unused code in VMBackup extension
  • Maintains backward compatibility with older Python versions
  • Resolves import error while preserving all existing functionality

- Replace distutils.version with packaging/distutils/custom fallback in WaagentLib.py
- Replace imp module with importlib.util fallback in WAAgentUtil.py
- Fix invalid escape sequences in HandlerUtil.py JSON processing
- Add setuptools fallback for distutils removal in setup.py

Resolves VMBackup extension failure on Debian 12 with Python 3.12.
All changes maintain backward compatibility with older Python versions.
Devesh Jagwani added 2 commits November 6, 2025 12:18
- Added conditional import for distro package
- Implemented multi-tier fallback strategy in get_dist_info()
- Enhanced error handling with proper logging
- Maintains backward compatibility across all Python versions
- Resolves AttributeError: module 'platform' has no attribute 'dist'
- Add try/except block for crypt import to handle Python 3.13+ where crypt module was removed
- Update gen_password_hash() to gracefully handle missing crypt module
- Add TODO comment for future cleanup of unused code in VMBackup extension
- Maintains backward compatibility with older Python versions
- Resolves import error while preserving all existing functionality
Comment thread VMBackup/main/Utils/HandlerUtil.py
Comment thread VMBackup/main/Utils/HandlerUtil.py

@arisettisanjana arisettisanjana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please share the extension logs with the updated changes using older and latest python versions

@deveshjagwani

deveshjagwani commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

Extension success status result logs are present in the work item in PR description (ADO: 34492797). Also the rpc names are there @arisettisanjana

@arisettisanjana

Copy link
Copy Markdown
Contributor

Extension success status result logs are present in the work item in PR description (ADO: 34492797). Also the rpc names are there @arisettisanjana

The tests were run to verify on py3.13 versions so, just wanted to be sure that we have tested these changes for backward compatibility i.e with lesser python versions

@deveshjagwani

Copy link
Copy Markdown
Contributor Author

Extension success status result logs are present in the work item in PR description (ADO: 34492797). Also the rpc names are there @arisettisanjana

The tests were run to verify on py3.13 versions so, just wanted to be sure that we have tested these changes for backward compatibility i.e with lesser python versions

I haven't tested specifically for lesser python versions. But code will pickup the imports and logic for lesser python versions wherever needed.

@deveshjagwani deveshjagwani reopened this Nov 27, 2025
@deveshjagwani
deveshjagwani merged commit 5d8f38c into master Nov 27, 2025
1 check passed
ppusuluri-ms pushed a commit that referenced this pull request Apr 21, 2026
…ape sequence issues (#2124)" (#2163)

This reverts commit 5d8f38c.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
vupadhyay-ms pushed a commit to vupadhyay-ms/azure-linux-extensions that referenced this pull request Jul 10, 2026
… 51000001082652)

Ubuntu 26.04 / Py 3.14 removed the stdlib modules 'crypt' (Py 3.13),
'distutils' (Py 3.12), and 'imp' (Py 3.12). VMBackup imports all three
unconditionally, so handle.py -enable crashes at file-load time before
any snapshot logic runs -> CRP reports VMExtensionProvisioningTimeout ->
customer backup fails.

Changes (2 files):

* VMBackup/main/WaagentLib.py
  - Add PEP 263 encoding declaration (defense-in-depth vs future Unicode)
  - Wrap 'import crypt' in try/except; crypt = None fallback
  - Replace 'from distutils.version import LooseVersion' with 3-tier ladder:
    packaging.version -> distutils.version -> ASCII-only hand-written class
  - Guard gen_password_hash() with 'if crypt is None: raise NotImplementedError'

* VMBackup/main/Utils/WAAgentUtil.py
  - Replace 'except ImportError' fallback with hasattr(importlib.util,
    'module_from_spec') capability check (Py 2.7 raised AttributeError,
    not ImportError - this was one of the PR Azure#2124 regressions)
  - Drop outer 'except Exception: raise Exception(Cant load waagent)'
    wrapper that was hiding the real traceback in ICM logs

This is a corrected re-landing of PR Azure#2124 (reverted by PR Azure#2163 due to
ICM 783505554). Defenses vs those regressions:
  - Pure ASCII in modified files (byte-scan verified: 0 non-ASCII bytes)
  - PEP 263 encoding declaration future-proofs against Unicode leaks
  - hasattr() capability check is exception-type-independent
  - Tier 3 LooseVersion class inherits from 'object' (new-style, correct
    Py 2.7 rich-comparison dispatch)

Tested on Py 2.7 (Docker), 3.10, 3.12, 3.13, 3.14: 18/18 PASS.
End-to-end portal-triggered backup on Py 3.14 with branch code in
/var/lib/waagent/... completed with extension status: success and
snapshot URIs written to blob storage.

Fixes: ICM 51000001082652
Re-lands: PR Azure#2124 (reverted in PR Azure#2163)
Regression-tests: ICM 783505554
Related: Azure#2172

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants