Page MenuHomeDevCentral

Avoid importlib.machinery.SourceFileLoader load_module use
Needs ReviewPublic

Authored by dereckson on Wed, Sep 17, 16:42.
Tags
None
Referenced Files
F11744457: D3685.diff
Fri, Sep 19, 08:06
F11744155: D3685.diff
Fri, Sep 19, 05:33
F11743961: D3685.id9535.diff
Fri, Sep 19, 04:49
F11743610: D3685.id.diff
Fri, Sep 19, 02:07
F11743516: D3685.id9537.diff
Fri, Sep 19, 01:25
F11743262: D3685.id9536.diff
Thu, Sep 18, 23:17
F11743201: D3685.id9536.diff
Thu, Sep 18, 22:28
F11742681: D3685.id.diff
Thu, Sep 18, 18:45
Subscribers
None

Details

Summary

Currently, unit tests for Salt module and for scripts used the SourceFileLoader
class to manually load a specific script. The class load_module() method has
been deprecated for a while and won't be available in Python 3.12+.

Instead, we now use two strategies to import Python code:

  • treat _modules/ as a package folder by passing the path as PYTHONPATH
  • still use importlib for scripts, with compatible code

To import scripts directly with import can be a challenge, as roles like
"paas-docker" use dashes. The scripts filenames themselves contain dashes.

This fixes the following issue:
<frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method
is deprecated and slated for removal in Python 3.12; use exec_module() instead

Test Plan

On the T2123-improve-tests-suite branch to avoid distractions, make test
show every test pass without the deprecation warning.

Diff Detail

Repository
rOPS Nasqueron Operations
Lint
Lint Passed
Unit
No Test Coverage
Branch
T2123-improve-tests-suite
Build Status
Buildable 5903
Build 6185: arc lint + arc unit