From 7e82f3ee7bb0d77dd1327cff300d34c0ad9f5e36 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Wed, 6 Mar 2019 14:12:10 +0100 Subject: [PATCH] extmods: add utils directories in sys.path When the minion start clean and there are not utils directory in the extmods cache, any import from a module to any code inside the utils directory will fail. A second run of the highstate will fix this issue, as the utils directories are added into sys.path inside config/__init__.py, as part of the master and minion startup. This commit add the utils directories during the synchronization of the custom modules. Fixes #51958 --- salt/utils/extmods.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/salt/utils/extmods.py b/salt/utils/extmods.py index 7466e7206066..760f6beaa072 100644 --- a/salt/utils/extmods.py +++ b/salt/utils/extmods.py @@ -8,6 +8,7 @@ import logging import os import shutil +import sys # Import salt libs import salt.fileclient @@ -131,6 +132,12 @@ def sync(opts, shutil.copyfile(fn_, dest) ret.append('{0}.{1}'.format(form, relname)) + # If the synchronized module is an utils + # directory, we add it to sys.path + for util_dir in opts['utils_dirs']: + if mod_dir.endswith(util_dir) and mod_dir not in sys.path: + sys.path.append(mod_dir) + touched = bool(ret) if opts['clean_dynamic_modules'] is True: current = set(_listdir_recursively(mod_dir))