Fixed the prepend logic of the root_dir to relative config paths

This commit is contained in:
Alexandru Bleotu 2017-05-16 13:18:58 +01:00
parent 4f3b06dfb8
commit 93eb3fc9d4

View File

@ -2067,26 +2067,43 @@ def prepend_root_dir(opts, path_options):
'root_dir' option.
'''
root_dir = os.path.abspath(opts['root_dir'])
root_opt = opts['root_dir'].rstrip(os.sep)
def_root_dir = salt.syspaths.ROOT_DIR.rstrip(os.sep)
for path_option in path_options:
if path_option in opts:
path = opts[path_option]
tmp_path_def_root_dir = None
tmp_path_root_dir = None
# When running testsuite, salt.syspaths.ROOT_DIR is often empty
if def_root_dir != '' and (path == def_root_dir or path.startswith(def_root_dir + os.sep)):
# Remove the default root dir so we can add the override
path = path[len(def_root_dir):]
elif path == root_opt or path.startswith(root_opt + os.sep):
# Remove relative root dir so we can add the absolute root dir
path = path[len(root_opt):]
elif os.path.isabs(path_option):
if def_root_dir != '' and (path == def_root_dir or
path.startswith(def_root_dir + os.sep)):
# Remove the default root dir prefix
tmp_path_def_root_dir = path[len(def_root_dir):]
if root_dir and (path == root_dir or
path.startswith(root_dir + os.sep)) :
# Remove the root dir prefix
tmp_path_root_dir = path[len(root_dir):]
if tmp_path_def_root_dir and not tmp_path_root_dir:
# Just the default root dir matched
path = tmp_path_def_root_dir
elif tmp_path_root_dir and not tmp_path_def_root_dir:
# Just the root dir matched
path = tmp_path_root_dir
elif tmp_path_def_root_dir and tmp_path_root_dir:
# In this case both the default root dir and the override root
# dir matched; this means that either
# def_root_dir is a substring of root_dir or vice versa
# We must choose the most specific path
if def_root_dir in root_dir:
path = tmp_path_root_dir
else:
path = tmp_path_def_root_dir
if os.path.isabs(path):
# Absolute path (not default or overriden root_dir)
# No prepending required
continue
# Prepending the root dir
opts[path_option] = salt.utils.path_join(root_dir, path)
logging.getLogger(__name__).trace('log_file = {}'.format(opts.get(
'log_file')))
def insert_system_path(opts, paths):