From fb673a4f561a30d52c9bc01033521bd4da427410 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 26 Jul 2016 15:43:06 -0600 Subject: [PATCH 1/5] Add windows path for hosts file --- salt/modules/config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/salt/modules/config.py b/salt/modules/config.py index 48337f3b6c..13a345ccd9 100644 --- a/salt/modules/config.py +++ b/salt/modules/config.py @@ -27,6 +27,12 @@ import salt.utils.sdb as sdb # Import 3rd-party libs import salt.ext.six as six +if salt.utils.is_windows(): + _HOSTS_FILE = os.path.join( + os.environ['SystemRoot'], 'System32', 'drivers', 'etc', 'hosts') +else: + _HOSTS_FILE = os.path.join('etc', 'hosts') + log = logging.getLogger(__name__) __proxyenabled__ = ['*'] @@ -65,7 +71,7 @@ DEFAULTS = {'mongo.db': 'salt', 'ldap.attrs': None, 'ldap.binddn': '', 'ldap.bindpw': '', - 'hosts.file': '/etc/hosts', + 'hosts.file': _HOSTS_FILE, 'aliases.file': '/etc/aliases', 'virt.images': os.path.join(syspaths.SRV_ROOT_DIR, 'salt-images'), 'virt.tunnel': False, From 15a7e985636f2ee521cf542a9d58d508d126bd12 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 26 Jul 2016 15:50:05 -0600 Subject: [PATCH 2/5] Fix linux path to hosts --- salt/modules/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/config.py b/salt/modules/config.py index 13a345ccd9..c24ac39796 100644 --- a/salt/modules/config.py +++ b/salt/modules/config.py @@ -31,7 +31,7 @@ if salt.utils.is_windows(): _HOSTS_FILE = os.path.join( os.environ['SystemRoot'], 'System32', 'drivers', 'etc', 'hosts') else: - _HOSTS_FILE = os.path.join('etc', 'hosts') + _HOSTS_FILE = os.path.join('/', 'etc', 'hosts') log = logging.getLogger(__name__) From d7800567f5b20f283c240c007732830f284953c6 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 26 Jul 2016 16:00:07 -0600 Subject: [PATCH 3/5] Fix hosts integration test --- salt/modules/hosts.py | 4 ---- tests/integration/__init__.py | 4 ++++ tests/integration/files/conf/minion | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/salt/modules/hosts.py b/salt/modules/hosts.py index 28a80c3303..177f7482d5 100644 --- a/salt/modules/hosts.py +++ b/salt/modules/hosts.py @@ -21,10 +21,6 @@ def __get_hosts_filename(): ''' Return the path to the appropriate hosts file ''' - # TODO: Investigate using "%SystemRoot%\system32" for this - if salt.utils.is_windows(): - return 'C:\\Windows\\System32\\drivers\\etc\\hosts' - return __salt__['config.option']('hosts.file') diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index d223841145..1874c549c2 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -1018,6 +1018,8 @@ class TestDaemon(object): minion_opts['config_dir'] = TMP_CONF_DIR minion_opts['root_dir'] = os.path.join(TMP, 'rootdir') minion_opts['pki_dir'] = os.path.join(TMP, 'rootdir', 'pki') + minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts') + minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases') # This sub_minion also connects to master sub_minion_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'sub_minion')) @@ -1026,6 +1028,8 @@ class TestDaemon(object): sub_minion_opts['config_dir'] = TMP_SUB_MINION_CONF_DIR sub_minion_opts['root_dir'] = os.path.join(TMP, 'rootdir-sub-minion') sub_minion_opts['pki_dir'] = os.path.join(TMP, 'rootdir-sub-minion', 'pki', 'minion') + sub_minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts') + sub_minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases') # This is the master of masters syndic_master_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'syndic_master')) diff --git a/tests/integration/files/conf/minion b/tests/integration/files/conf/minion index 53bdb4ac07..fcffea09e7 100644 --- a/tests/integration/files/conf/minion +++ b/tests/integration/files/conf/minion @@ -14,8 +14,6 @@ pidfile: minion.pid # module extension test.foo: baz -hosts.file: /tmp/salt-tests-tmpdir/hosts -aliases.file: /tmp/salt-tests-tmpdir/aliases integration.test: True # Grains addons From 47fb8379d77b5daaa2a636b4b524d9245098502d Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 26 Jul 2016 16:07:55 -0600 Subject: [PATCH 4/5] Remove hosts and aliases from sub_minion conf --- tests/integration/files/conf/sub_minion | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/files/conf/sub_minion b/tests/integration/files/conf/sub_minion index 008ade341d..9d20d21439 100644 --- a/tests/integration/files/conf/sub_minion +++ b/tests/integration/files/conf/sub_minion @@ -14,8 +14,6 @@ pidfile: sub_minion.pid # module extension test.foo: baz -hosts.file: /tmp/salt-tests-tmpdir/hosts -aliases.file: /tmp/salt-tests-tmpdir/aliases integration.test: True # Grains addons From a5d539a218a50f02dc99ffa62a9434d0c7ef58de Mon Sep 17 00:00:00 2001 From: twangboy Date: Wed, 27 Jul 2016 15:43:27 -0700 Subject: [PATCH 5/5] Fix hardcoded seperator --- salt/modules/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/config.py b/salt/modules/config.py index c24ac39796..87f9572f79 100644 --- a/salt/modules/config.py +++ b/salt/modules/config.py @@ -31,7 +31,7 @@ if salt.utils.is_windows(): _HOSTS_FILE = os.path.join( os.environ['SystemRoot'], 'System32', 'drivers', 'etc', 'hosts') else: - _HOSTS_FILE = os.path.join('/', 'etc', 'hosts') + _HOSTS_FILE = os.path.join(os.sep, 'etc', 'hosts') log = logging.getLogger(__name__)