mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #56215 from dwoz/issue-56131
Fix for unless requisite when pip is not installed
This commit is contained in:
commit
c9bc9431c1
4 changed files with 35 additions and 15 deletions
|
@ -51,7 +51,7 @@ def purge_pip():
|
|||
return
|
||||
pip_related_entries = [
|
||||
(k, v) for (k, v) in sys.modules.items()
|
||||
or getattr(v, '__module__', '').startswith('pip.')
|
||||
if getattr(v, '__module__', '').startswith('pip.')
|
||||
or (isinstance(v, types.ModuleType) and v.__name__.startswith('pip.'))
|
||||
]
|
||||
for name, entry in pip_related_entries:
|
||||
|
@ -96,21 +96,8 @@ try:
|
|||
HAS_PIP = True
|
||||
except ImportError:
|
||||
HAS_PIP = False
|
||||
# Remove references to the loaded pip module above so reloading works
|
||||
import sys
|
||||
pip_related_entries = [
|
||||
(k, v) for (k, v) in sys.modules.items()
|
||||
or getattr(v, '__module__', '').startswith('pip.')
|
||||
or (isinstance(v, types.ModuleType) and v.__name__.startswith('pip.'))
|
||||
]
|
||||
for name, entry in pip_related_entries:
|
||||
sys.modules.pop(name)
|
||||
del entry
|
||||
purge_pip()
|
||||
|
||||
del pip
|
||||
sys_modules_pip = sys.modules.pop('pip', None)
|
||||
if sys_modules_pip is not None:
|
||||
del sys_modules_pip
|
||||
|
||||
if HAS_PIP is True:
|
||||
if not hasattr(purge_pip, '__pip_ver__'):
|
||||
|
|
10
tests/integration/files/file/base/issue-56131.sls
Normal file
10
tests/integration/files/file/base/issue-56131.sls
Normal file
|
@ -0,0 +1,10 @@
|
|||
# archive-test
|
||||
vault:
|
||||
archive.extracted:
|
||||
- name: {{ pillar['unzip_to'] }}
|
||||
- source: salt://issue-56131.zip
|
||||
- source_hash: sha256=4fc6f049d658a414aca066fb11c2109d05b59f082d707d5d6355b6c574d25720
|
||||
- archive_format: zip
|
||||
- enforce_toplevel: False
|
||||
- unless:
|
||||
- echo hello && 1
|
BIN
tests/integration/files/file/base/issue-56131.zip
Normal file
BIN
tests/integration/files/file/base/issue-56131.zip
Normal file
Binary file not shown.
|
@ -2268,3 +2268,26 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertEqual(state_run[state_id]['comment'],
|
||||
'Success!')
|
||||
self.assertTrue(state_run[state_id]['result'])
|
||||
|
||||
def test_issue_56131(self):
|
||||
module_path = os.path.join(RUNTIME_VARS.CODE_DIR, 'pip.py')
|
||||
if six.PY3:
|
||||
modulec_path = os.path.join(RUNTIME_VARS.CODE_DIR, '__pycache__', 'pip.pyc')
|
||||
else:
|
||||
modulec_path = os.path.join(RUNTIME_VARS.CODE_DIR, 'pip.pyc')
|
||||
unzip_path = os.path.join(RUNTIME_VARS.TMP, 'issue-56131.txt')
|
||||
|
||||
def clean_paths(paths):
|
||||
for path in paths:
|
||||
try:
|
||||
os.remove(path)
|
||||
except OSError:
|
||||
log.warn("Path not found: %s", path)
|
||||
|
||||
with salt.utils.files.fopen(module_path, 'w') as fp:
|
||||
fp.write('raise ImportError("No module named pip")')
|
||||
self.addCleanup(clean_paths, [unzip_path, module_path, modulec_path])
|
||||
assert not os.path.exists(unzip_path)
|
||||
state_run = self.run_function('state.sls', mods='issue-56131', pillar={'unzip_to': RUNTIME_VARS.TMP}, timeout=30)
|
||||
assert state_run is not False
|
||||
assert os.path.exists(unzip_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue