No more hard-coded salt paths.

All system paths that salt expects and needs are all configurable at install time. This allows for packagers to setup salt's **default** internal paths at build time. For example, under windows, the configuration directory is expected at `c:\salt\conf\`, on FreeBSD at `/usr/local/etc/salt`, etc.

The configurable paths are:

* Salt root directory, `salt_root` in the master and minion configuration files, `--salt-root-dir` option to `python setup.py install`.  Default: `/`
* Salt configuration directory, `--salt-config-dir` option to `python setup.py install`.  Default: `/etc/salt`
* Salt cache directory, `--salt-cache-dir` option to `python setup.py install`.  Default: `/var/cache/salt`
* Salt sock directory, `--salt-sock-dir` option to `python setup.py install`.  Default: `/var/run/salt`
* Salt services root directory, `--salt-srv-root-dir` option to `python setup.py install`.  Default: `/srv`
* Salt base file roots directory, `--salt-base-file-roots-dir` option to `python setup.py install`.  Default: `/srv/salt`
* Salt base pillar roots directory, `--salt-base-pillar-roots-dir` option to `python setup.py install`.  Default: `/srv/pillar`
* Salt base master roots directory, `--salt-base-master-roots-dir` option to `python setup.py install`.  Default: `/srv/salt-master`
* Salt logs directory, `--salt-logs-dir` option to `python setup.py install`.  Default: `/var/log/salt`
* Salt pidfile directory, `--salt-pidfile-dir` option to `python setup.py install`.  Default: `/var/run`
This commit is contained in:
Pedro Algarvio 2013-08-25 22:55:57 +00:00
parent 8e96adeb13
commit 9a4ce0ea9d
10 changed files with 84 additions and 58 deletions

View file

@ -41,6 +41,7 @@ import salt.utils
import salt.utils.verify
import salt.utils.event
import salt.utils.minions
import salt.syspaths as syspaths
from salt.exceptions import SaltInvocationError
from salt.exceptions import EauthAuthenticationError
@ -77,7 +78,9 @@ class LocalClient(object):
running as (unless :conf_master:`external_auth` is configured and
authentication credentials are included in the execution.
'''
def __init__(self, c_path='/etc/salt/master', mopts=None):
def __init__(self,
c_path=os.path.join(syspaths.CONFIG_DIR, 'master'),
mopts=None):
if mopts:
self.opts = mopts
else:
@ -1281,7 +1284,7 @@ class Caller(object):
# Or call objects directly
caller.sminion.functions['cmd.run']('ls -l')
'''
def __init__(self, c_path='/etc/salt/minion'):
def __init__(self, c_path=os.path.join(syspaths.CONFIG_DIR, 'minion')):
self.opts = salt.config.minion_config(c_path)
self.sminion = salt.minion.SMinion(self.opts)

View file

@ -14,6 +14,7 @@ import salt.client
import salt.runner
import salt.wheel
import salt.utils
import salt.syspaths as syspaths
from salt.exceptions import SaltException, EauthAuthenticationError
from salt.utils.event import tagify
@ -37,8 +38,12 @@ class APIClient(object):
'''
def __init__(self, opts=None):
if not opts:
opts = salt.config.client_config(os.environ.get('SALT_MASTER_CONFIG',
'/etc/salt/master'))
opts = salt.config.client_config(
os.environ.get(
'SALT_MASTER_CONFIG',
os.path.join(syspaths.CONFIG_DIR, 'master')
)
)
self.opts = opts
self.localClient = salt.client.LocalClient(self.opts['conf_file'])
self.runnerClient = salt.runner.RunnerClient(self.opts)

View file

@ -24,6 +24,7 @@ import salt.loader
import salt.utils
import salt.utils.network
import salt.pillar
import salt.syspaths as syspaths
log = logging.getLogger(__name__)
@ -162,13 +163,13 @@ DEFAULT_MINION_OPTS = {
'master_port': '4506',
'master_finger': '',
'user': 'root',
'root_dir': '/',
'pki_dir': '/etc/salt/pki/minion',
'root_dir': syspaths.ROOT_DIR,
'pki_dir': os.path.join(syspaths.CONFIG_DIR, 'pki', 'minion'),
'id': None,
'cachedir': '/var/cache/salt/minion',
'cachedir': os.path.join(syspaths.CACHE_DIR, 'minion'),
'cache_jobs': False,
'conf_file': '/etc/salt/minion',
'sock_dir': '/var/run/salt/minion',
'conf_file': os.path.join(syspaths.CONFIG_DIR, 'minion'),
'sock_dir': os.path.join(syspaths.SOCK_DIR, 'minion'),
'backup_mode': '',
'renderer': 'yaml_jinja',
'failhard': False,
@ -180,10 +181,10 @@ DEFAULT_MINION_OPTS = {
'top_file': '',
'file_client': 'remote',
'file_roots': {
'base': ['/srv/salt'],
'base': [syspaths.BASE_FILE_ROOTS_DIR],
},
'pillar_roots': {
'base': ['/srv/pillar'],
'base': [syspaths.BASE_PILLAR_ROOTS_DIR],
},
'hash_type': 'md5',
'external_nodes': '',
@ -205,7 +206,7 @@ DEFAULT_MINION_OPTS = {
'file_buffer_size': 262144,
'tcp_pub_port': 4510,
'tcp_pull_port': 4511,
'log_file': '/var/log/salt/minion',
'log_file': os.path.join(syspaths.LOGS_DIR, 'minion'),
'log_level': None,
'log_level_logfile': None,
'log_datefmt': _DFLT_LOG_DATEFMT,
@ -233,7 +234,7 @@ DEFAULT_MINION_OPTS = {
'recon_default': 100,
'recon_randomize': False,
'win_repo_cachefile': 'salt://win/repo/winrepo.p',
'pidfile': '/var/run/salt-minion.pid',
'pidfile': os.path.join(syspaths.PIDFILE_DIR, 'salt-minion.pid'),
'range_server': 'range:80',
'tcp_keepalive': True,
'tcp_keepalive_idle': 300,
@ -247,21 +248,21 @@ DEFAULT_MASTER_OPTS = {
'auth_mode': 1,
'user': 'root',
'worker_threads': 5,
'sock_dir': '/var/run/salt/master',
'sock_dir': os.path.join(syspaths.SOCK_DIR, 'master'),
'ret_port': '4506',
'timeout': 5,
'keep_jobs': 24,
'root_dir': '/',
'pki_dir': '/etc/salt/pki/master',
'cachedir': '/var/cache/salt/master',
'root_dir': syspaths.ROOT_DIR,
'pki_dir': os.path.join(syspaths.CONFIG_DIR, 'master'),
'cachedir': os.path.join(syspaths.CACHE_DIR, 'master'),
'file_roots': {
'base': ['/srv/salt'],
'base': [syspaths.BASE_FILE_ROOTS_DIR],
},
'master_roots': {
'base': ['/srv/salt-master'],
'base': [syspaths.BASE_MASTER_ROOTS_DIR],
},
'pillar_roots': {
'base': ['/srv/pillar'],
'base': [syspaths.BASE_PILLAR_ROOTS_DIR],
},
'gitfs_remotes': [],
'gitfs_root': '',
@ -285,7 +286,7 @@ DEFAULT_MASTER_OPTS = {
'fileserver_backend': ['roots'],
'max_open_files': 100000,
'hash_type': 'md5',
'conf_file': '/etc/salt/master',
'conf_file': os.path.join(syspaths.CONFIG_DIR, 'master'),
'open_mode': False,
'auto_accept': False,
'renderer': 'yaml_jinja',
@ -300,7 +301,7 @@ DEFAULT_MASTER_OPTS = {
'minion_data_cache': True,
'enforce_mine_cache': False,
'ipv6': False,
'log_file': '/var/log/salt/master',
'log_file': os.path.join(syspaths.LOGS_DIR, 'master'),
'log_level': None,
'log_level_logfile': None,
'log_datefmt': _DFLT_LOG_DATEFMT,
@ -308,7 +309,7 @@ DEFAULT_MASTER_OPTS = {
'log_fmt_console': _DFLT_LOG_FMT_CONSOLE,
'log_fmt_logfile': _DFLT_LOG_FMT_LOGFILE,
'log_granular_levels': {},
'pidfile': '/var/run/salt-master.pid',
'pidfile': os.path.join(syspaths.PIDFILE_DIR, 'salt-master.pid'),
'publish_session': 86400,
'cluster_masters': [],
'cluster_mode': 'paranoid',
@ -323,12 +324,14 @@ DEFAULT_MASTER_OPTS = {
'loop_interval': 60,
'nodegroups': {},
'cython_enable': False,
'key_logfile': '/var/log/salt/key',
# XXX: Remove 'key_logfile' support in 0.18.0
'key_logfile': os.path.join(syspaths.LOGS_DIR, 'key'),
'verify_env': True,
'permissive_pki_access': False,
'default_include': 'master.d/*.conf',
'win_repo': '/srv/salt/win/repo',
'win_repo_mastercachefile': '/srv/salt/win/repo/winrepo.p',
'win_repo': os.path.join(syspaths.BASE_FILE_ROOTS_DIR, 'win', 'repo'),
'win_repo_mastercachefile': os.path.join(syspaths.BASE_FILE_ROOTS_DIR,
'win', 'repo', 'winrepo.p'),
'win_gitrepos': ['https://github.com/saltstack/salt-winrepo.git'],
}
@ -341,7 +344,7 @@ def _validate_file_roots(opts):
if not isinstance(opts['file_roots'], dict):
log.warning('The file_roots parameter is not properly formatted,'
' using defaults')
return {'base': ['/srv/salt']}
return {'base': [syspaths.BASE_FILE_ROOTS_DIR]}
for env, dirs in list(opts['file_roots'].items()):
if not isinstance(dirs, list) and not isinstance(dirs, tuple):
opts['file_roots'][env] = []
@ -511,12 +514,12 @@ def include_config(include, orig_path, verbose):
if verbose:
log.warn(
'Warning parsing configuration file: "include" path/glob '
'"{0}" matches no files'.format(path)
'{0!r} matches no files'.format(path)
)
for fn_ in sorted(glob.glob(path)):
try:
log.debug('Including configuration from {0}'.format(fn_))
log.debug('Including configuration from {0!r}'.format(fn_))
configuration.update(_read_conf_file(fn_))
except Exception as err:
log.warn(
@ -604,7 +607,7 @@ def syndic_config(master_config_path,
opts.update(master_opts)
opts.update(minion_opts)
syndic_opts = {
'root_dir': opts.get('root_dir', '/'),
'root_dir': opts.get('root_dir', syspaths.ROOT_DIR),
'pidfile': opts.get('syndic_pidfile', 'salt-syndic.pid'),
'log_file': opts.get('syndic_log_file', 'salt-syndic.log'),
'id': minion_opts['id'],
@ -660,8 +663,11 @@ def get_id():
not an IP address is being used for the ID.
'''
log.debug('Guessing ID. The id can be explicitly in set {0}'
.format('/etc/salt/minion'))
log.debug(
'Guessing ID. The id can be explicitly in set {0}'.format(
os.path.join(syspaths.CONFIG_DIR, 'minion')
)
)
# Check /etc/hostname
try:

View file

@ -9,6 +9,7 @@ import urllib
# Import salt libs
import salt.utils
import salt.syspaths as syspaths
# Set up the default values for all systems
DEFAULTS = {'mongo.db': 'salt',
@ -43,7 +44,7 @@ DEFAULTS = {'mongo.db': 'salt',
'ldap.bindpw': '',
'hosts.file': '/etc/hosts',
'aliases.file': '/etc/aliases',
'virt.images': '/srv/salt-images',
'virt.images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images'),
'virt.tunnel': False,
}

View file

@ -28,6 +28,7 @@ import salt.minion
import salt.pillar
import salt.fileclient
import salt.utils.event
import salt.syspaths as syspaths
from salt._compat import string_types
from salt.template import compile_template, compile_template_str
from salt.exceptions import SaltReqTimeoutError, SaltException
@ -1684,7 +1685,7 @@ class BaseHighState(object):
opts['failhard'] = False
opts['state_top'] = 'salt://top.sls'
opts['nodegroups'] = {}
opts['file_roots'] = {'base': ['/srv/salt']}
opts['file_roots'] = {'base': [syspaths.BASE_FILE_ROOTS_DIR]}
else:
opts['renderer'] = mopts['renderer']
opts['failhard'] = mopts.get('failhard', False)

View file

@ -17,11 +17,12 @@ import os.path
try:
# Let's try loading the system paths from the generated module at
# installation time.
from salt._syspaths import (
ROOT_DIR,
CONFIG_DIR,
from salt._syspaths import ( # pylint: disable=E0611
ROOT_DIR, # because pylint thinks that _syspaths is an
CONFIG_DIR, # attribute of salt.__init__
CACHE_DIR,
SOCK_DIR,
SRV_ROOT_DIR,
BASE_FILE_ROOTS_DIR,
BASE_PILLAR_ROOTS_DIR,
BASE_MASTER_ROOTS_DIR,
@ -38,8 +39,9 @@ except ImportError:
CONFIG_DIR = os.path.join(ROOT_DIR, 'etc', 'salt')
CACHE_DIR = os.path.join(ROOT_DIR, 'var', 'cache', 'salt')
SOCK_DIR = os.path.join(ROOT_DIR, 'var', 'run', 'salt')
BASE_FILE_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'salt')
BASE_PILLAR_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'pillar')
BASE_MASTER_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'salt-master')
SRV_ROOT_DIR = os.path.join(ROOT_DIR, 'srv')
BASE_FILE_ROOTS_DIR = os.path.join(SRV_ROOT_DIR, 'salt')
BASE_PILLAR_ROOTS_DIR = os.path.join(SRV_ROOT_DIR, 'pillar')
BASE_MASTER_ROOTS_DIR = os.path.join(SRV_ROOT_DIR, 'salt-master')
LOGS_DIR = os.path.join(ROOT_DIR, 'var', 'logs', 'salt')
PIDFILE_DIR = os.path.join(ROOT_DIR, 'var', 'run')

View file

@ -582,7 +582,7 @@ def path_join(*parts):
if not parts:
return root
if platform.system().lower() == 'windows':
if is_windows():
if len(root) == 1:
root += ':'
root = root.rstrip(os.sep) + os.sep

View file

@ -6,12 +6,15 @@ Migration tools
import os.path
import shutil
# Import salt libs
import salt.syspaths as syspaths
def migrate_paths(opts):
'''
Migrate old minion and master pki file paths to new ones.
'''
oldpki_dir = '/etc/salt/pki'
oldpki_dir = os.path.join(syspaths.CONFIG_DIR, 'pki')
if not os.path.exists(oldpki_dir):
# There's not even a pki directory, don't bother migrating

View file

@ -24,6 +24,7 @@ import salt.config as config
import salt.loader as loader
import salt.utils as utils
import salt.version as version
import salt.syspaths as syspaths
def _sorted(mixins_or_funcs):
@ -259,11 +260,8 @@ class ConfigDirMixIn(object):
_config_filename_ = None
def _mixin_setup(self):
default = '/etc/salt'
if utils.is_windows():
default = 'c:\\salt\\conf'
self.add_option(
'-c', '--config-dir', default=default,
'-c', '--config-dir', default=syspaths.CONFIG_DIR,
help=('Pass in an alternative configuration directory. Default: '
'%default')
)
@ -272,7 +270,7 @@ class ConfigDirMixIn(object):
if not os.path.isdir(self.options.config_dir):
# No logging is configured yet
sys.stderr.write(
'WARNING: "{0}" directory does not exist.\n'.format(
'WARNING: {0!r} directory does not exist.\n'.format(
self.options.config_dir
)
)
@ -604,7 +602,9 @@ class PidfileMixin(object):
def _mixin_setup(self):
self.add_option(
'--pid-file', dest='pidfile',
default='/var/run/{0}.pid'.format(self.get_prog_name()),
default=os.path.join(
syspaths.PIDFILE_DIR, '{0}.pid'.format(self.get_prog_name())
),
help=('Specify the location of the pidfile. Default: %default')
)
@ -784,7 +784,7 @@ class OutputOptionsMixIn(object):
'--out', '--output',
dest='output',
help=(
'Print the output from the \'{0}\' command using the '
'Print the output from the {0!r} command using the '
'specified outputter. The builtins are {1}.'.format(
self.get_prog_name(),
', '.join([repr(k) for k in outputters])
@ -880,7 +880,7 @@ class MasterOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# ConfigDirMixIn config filename attribute
_config_filename_ = 'master'
# LogLevelMixIn attributes
_default_logging_logfile_ = '/var/log/salt/master'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'master')
def setup_config(self):
return config.master_config(self.get_config_file_path())
@ -897,7 +897,7 @@ class MinionOptionParser(MasterOptionParser):
# ConfigDirMixIn config filename attribute
_config_filename_ = 'minion'
# LogLevelMixIn attributes
_default_logging_logfile_ = '/var/log/salt/minion'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'minion')
def setup_config(self):
return config.minion_config(self.get_config_file_path())
@ -917,7 +917,7 @@ class SyndicOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# ConfigDirMixIn config filename attribute
_config_filename_ = 'master'
# LogLevelMixIn attributes
_default_logging_logfile_ = '/var/log/salt/master'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'master')
def setup_config(self):
return config.syndic_config(
@ -940,7 +940,7 @@ class SaltCMDOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_default_logging_level_ = 'warning'
_default_logging_logfile_ = '/var/log/salt/master'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'master')
_loglevel_config_setting_name_ = 'cli_salt_log_file'
def _mixin_setup(self):
@ -1112,7 +1112,7 @@ class SaltCPOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_default_logging_level_ = 'warning'
_default_logging_logfile_ = '/var/log/salt/master'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'master')
_loglevel_config_setting_name_ = 'cli_salt_cp_log_file'
def _mixin_after_parsed(self):
@ -1150,7 +1150,7 @@ class SaltKeyOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_skip_console_logging_config_ = True
_logfile_config_setting_name_ = 'key_logfile'
_default_logging_logfile_ = '/var/log/salt/key'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'key')
def _mixin_setup(self):
# XXX: Remove '--key-logfile' support in 0.18.0
@ -1360,7 +1360,7 @@ class SaltCallOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_default_logging_level_ = 'info'
_default_logging_logfile_ = '/var/log/salt/minion'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'minion')
def _mixin_setup(self):
self.add_option(
@ -1458,7 +1458,7 @@ class SaltRunOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_default_logging_level_ = 'warning'
_default_logging_logfile_ = '/var/log/salt/master'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'master')
_loglevel_config_setting_name_ = 'cli_salt_run_log_file'
def _mixin_setup(self):
@ -1497,7 +1497,7 @@ class SaltSSHOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
# LogLevelMixIn attributes
_default_logging_level_ = 'warning'
_default_logging_logfile_ = '/var/log/salt/ssh'
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'ssh')
_loglevel_config_setting_name_ = 'cli_salt_run_log_file'
def _mixin_setup(self):

View file

@ -141,6 +141,7 @@ ROOT_DIR = {root_dir!r}
CONFIG_DIR = {config_dir!r}
CACHE_DIR = {cache_dir!r}
SOCK_DIR = {sock_dir!r}
SRV_ROOT_DIR= {srv_root_dir!r}
BASE_FILE_ROOTS_DIR = {base_file_roots_dir!r}
BASE_PILLAR_ROOTS_DIR = {base_pillar_roots_dir!r}
BASE_MASTER_ROOTS_DIR = {base_master_roots_dir!r}
@ -180,6 +181,7 @@ class Build(build):
config_dir=self.salt_config_dir,
cache_dir=self.salt_cache_dir,
sock_dir=self.salt_sock_dir,
srv_root_dir=self.salt_srv_root_dir,
base_file_roots_dir=self.salt_base_file_roots_dir,
base_pillar_roots_dir=self.salt_base_pillar_roots_dir,
base_master_roots_dir=self.salt_base_master_roots_dir,
@ -199,6 +201,8 @@ class Install(install):
'Salt\'s pre-configured cache directory'),
('salt-sock-dir=', None,
'Salt\'s pre-configured socket directory'),
('salt-srv-root-dir=', None,
'Salt\'s pre-configured service directory'),
('salt-base-file-roots-dir=', None,
'Salt\'s pre-configured file roots directory'),
('salt-base-pillar-roots-dir=', None,
@ -217,6 +221,7 @@ class Install(install):
self.salt_config_dir = CONFIG_DIR
self.salt_cache_dir = CACHE_DIR
self.salt_sock_dir = SOCK_DIR
self.salt_srv_root_dir = SRV_ROOT_DIR
self.salt_base_file_roots_dir = BASE_FILE_ROOTS_DIR
self.salt_base_pillar_roots_dir = BASE_PILLAR_ROOTS_DIR
self.salt_base_master_roots_dir = BASE_MASTER_ROOTS_DIR