From ed59113e94a7ea071ab98de301a83aeb7cc784e0 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Thu, 7 Jul 2016 12:27:18 -0600 Subject: [PATCH 1/8] Change network state integration test to use test=True --- tests/integration/states/network.py | 65 ++++++++++++----------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tests/integration/states/network.py b/tests/integration/states/network.py index 2cded46879..9d546addef 100644 --- a/tests/integration/states/network.py +++ b/tests/integration/states/network.py @@ -27,55 +27,42 @@ class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): if os_family not in ('RedHat', 'Debian'): self.skipTest('Network state only supported on RedHat and Debian based systems') - self.run_function('cmd.run', ['ip link add name dummy0 type dummy']) - - def tearDown(self): - self.run_function('cmd.run', ['ip link delete dev dummy0']) - def test_managed(self): ''' network.managed ''' - if_name = 'dummy0' - ipaddr = '10.1.0.1' - netmask = '255.255.255.0' - broadcast = '10.1.0.255' - - expected_if_ret = [{ - "broadcast": broadcast, - "netmask": netmask, - "label": if_name, - "address": ipaddr - }] - - ret = self.run_function('state.sls', mods='network.managed') - self.assertSaltTrueReturn(ret) - - interface = self.run_function('network.interface', [if_name]) - self.assertEqual(interface, expected_if_ret) - + state_key = + ret = self.run_function('state.sls', mods='network.managed', test=True) + + out = ret['network_|-dummy0_|-dummy0_|-managed']['comment'].split('\n') + + self.assertIn('Interface dummy0 is set to be updated:', out) + self.assertIn(' DEVICE="dummy0"', out) + self.assertIn(' USERCTL="no"', out) + self.assertIn(' ONBOOT="yes"', out) + self.assertIn(' IPADDR="10.1.0.1"', out) + def test_routes(self): - ''' + ''' network.routes - ''' + ''' state_key = 'network_|-routes_|-dummy0_|-routes' - expected_changes = {'network_routes': 'Added interface dummy0 routes.'} - - ret = self.run_function('state.sls', mods='network.routes') - - self.assertSaltTrueReturn(ret) - self.assertEqual(ret[state_key]['changes'], expected_changes) - + expected_changes = 'Interface dummy0 routes are set to be added.' + + ret = self.run_function('state.sls', mods='network.routes', test=True) + print(ret) + + self.assertEqual(ret[state_key]['comment'], expected_changes) + def test_system(self): - ''' + ''' network.system - ''' + ''' state_key = 'network_|-system_|-system_|-system' - - ret = self.run_function('state.sls', mods='network.system') - - self.assertSaltTrueReturn(ret) - self.assertIn('network_settings', ret[state_key]['changes']) + comment_out = 'Global network settings are set to be updated:\n--- \n+++ \n@@ -1 +1,4 @@\n-# Created by anaconda\n+NETWORKING=yes\n+HOSTNAME=server1.example.com\n+GATEWAY=10.1.0.1\n+GATEWAYDEV=dummy0' + + ret = self.run_function('state.sls', mods='network.system', test=True) + self.assertEqual(ret[state_key]['comment'], comment_out) if __name__ == '__main__': From b2616833b0cb7eb50afff26b60bc6d5b6fc0bc11 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Mon, 11 Jul 2016 14:35:25 -0600 Subject: [PATCH 2/8] Some small changes --- tests/integration/states/network.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/integration/states/network.py b/tests/integration/states/network.py index 9d546addef..b59ee1907b 100644 --- a/tests/integration/states/network.py +++ b/tests/integration/states/network.py @@ -33,34 +33,34 @@ class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): ''' state_key = ret = self.run_function('state.sls', mods='network.managed', test=True) - + out = ret['network_|-dummy0_|-dummy0_|-managed']['comment'].split('\n') - + self.assertIn('Interface dummy0 is set to be updated:', out) self.assertIn(' DEVICE="dummy0"', out) self.assertIn(' USERCTL="no"', out) self.assertIn(' ONBOOT="yes"', out) self.assertIn(' IPADDR="10.1.0.1"', out) - + def test_routes(self): - ''' + ''' network.routes - ''' + ''' state_key = 'network_|-routes_|-dummy0_|-routes' expected_changes = 'Interface dummy0 routes are set to be added.' - + ret = self.run_function('state.sls', mods='network.routes', test=True) print(ret) - + self.assertEqual(ret[state_key]['comment'], expected_changes) - + def test_system(self): - ''' + ''' network.system - ''' + ''' state_key = 'network_|-system_|-system_|-system' comment_out = 'Global network settings are set to be updated:\n--- \n+++ \n@@ -1 +1,4 @@\n-# Created by anaconda\n+NETWORKING=yes\n+HOSTNAME=server1.example.com\n+GATEWAY=10.1.0.1\n+GATEWAYDEV=dummy0' - + ret = self.run_function('state.sls', mods='network.system', test=True) self.assertEqual(ret[state_key]['comment'], comment_out) From bfe0dd0b8a86f9cc3300e0a037575b76216c3752 Mon Sep 17 00:00:00 2001 From: Loren Gordon Date: Tue, 12 Jul 2016 07:58:27 -0400 Subject: [PATCH 3/8] Clarifies the proper way to reference states It seems in some situations, or in some earlier version, using a `/` to reference sls files in subdirectories did work. However, because of the inconsistency it caused occasional confusion. This updates the tutorial to focus on the canonical `.` notation, which always works. --- doc/topics/tutorials/states_pt1.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/topics/tutorials/states_pt1.rst b/doc/topics/tutorials/states_pt1.rst index a2e150cbde..b10d773c60 100644 --- a/doc/topics/tutorials/states_pt1.rst +++ b/doc/topics/tutorials/states_pt1.rst @@ -176,13 +176,13 @@ and all changes made. 1. The ``.sls`` is discarded (i.e. ``webserver.sls`` becomes ``webserver``). 2. Subdirectories can be used for better organization. - a. Each subdirectory can be represented with a dot (following the python - import model) or a slash. ``webserver/dev.sls`` can also be referred to - as ``webserver.dev`` - b. Because slashes can be represented as dots, SLS files can not contain - dots in the name besides the dot for the SLS suffix. The SLS file - webserver_1.0.sls can not be matched, and webserver_1.0 would match - the directory/file webserver_1/0.sls + a. Each subdirectory is represented with a dot (following the Python + import model) in Salt states and on the command line . ``webserver/dev.sls`` + on the filesystem is referred to as ``webserver.dev`` in Salt + b. Because slashes are represented as dots, SLS files can not contain + dots in the name (other than the dot for the SLS suffix). The SLS + file ``webserver_1.0.sls`` can not be matched, and ``webserver_1.0`` + would match the directory/file ``webserver_1/0.sls`` 3. A file called ``init.sls`` in a subdirectory is referred to by the path of the directory. So, ``webserver/init.sls`` is referred to as From 34bcf9ccfc012f6bb6dcd5d669c3db85dd3fd785 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Tue, 12 Jul 2016 12:40:40 -0600 Subject: [PATCH 4/8] Changed network state test to use test=True --- tests/integration/states/network.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/integration/states/network.py b/tests/integration/states/network.py index b59ee1907b..1d61a1bc3f 100644 --- a/tests/integration/states/network.py +++ b/tests/integration/states/network.py @@ -31,16 +31,10 @@ class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): ''' network.managed ''' - state_key = + state_key = 'network_|-dummy0_|-dummy0_|-managed' + ret = self.run_function('state.sls', mods='network.managed', test=True) - - out = ret['network_|-dummy0_|-dummy0_|-managed']['comment'].split('\n') - - self.assertIn('Interface dummy0 is set to be updated:', out) - self.assertIn(' DEVICE="dummy0"', out) - self.assertIn(' USERCTL="no"', out) - self.assertIn(' ONBOOT="yes"', out) - self.assertIn(' IPADDR="10.1.0.1"', out) + self.assertEqual('Interface dummy0 is set to be added.', ret[state_key]['comment']) def test_routes(self): ''' @@ -50,19 +44,17 @@ class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): expected_changes = 'Interface dummy0 routes are set to be added.' ret = self.run_function('state.sls', mods='network.routes', test=True) - print(ret) - self.assertEqual(ret[state_key]['comment'], expected_changes) + self.assertEqual(ret[state_key]['comment'], 'Interface dummy0 routes are set to be added.') def test_system(self): ''' network.system ''' state_key = 'network_|-system_|-system_|-system' - comment_out = 'Global network settings are set to be updated:\n--- \n+++ \n@@ -1 +1,4 @@\n-# Created by anaconda\n+NETWORKING=yes\n+HOSTNAME=server1.example.com\n+GATEWAY=10.1.0.1\n+GATEWAYDEV=dummy0' ret = self.run_function('state.sls', mods='network.system', test=True) - self.assertEqual(ret[state_key]['comment'], comment_out) + self.assertIn('Global network settings are set to be updated:', ret[state_key]['comment']) if __name__ == '__main__': From dd1559a599a7f78524a13df62badeebdf8288896 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Wed, 13 Jul 2016 11:08:26 -0600 Subject: [PATCH 5/8] Check that mysqladmin exists before running mysql integration tests. --- tests/integration/modules/mysql.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/modules/mysql.py b/tests/integration/modules/mysql.py index fe7999f8c2..af09393323 100644 --- a/tests/integration/modules/mysql.py +++ b/tests/integration/modules/mysql.py @@ -14,6 +14,7 @@ ensure_in_syspath('../../') # Import salt libs import integration +import salt.utils from salt.modules import mysql as mysqlmod # Import 3rd-party libs @@ -28,6 +29,9 @@ try: except Exception: NO_MYSQL = True +if not salt.utils.which('mysqladmin'): + NO_MYSQL = True + @skipIf( NO_MYSQL, From 50360263c528ec49b02b2fbb983ca6d8cb13cc03 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Wed, 13 Jul 2016 14:51:28 -0600 Subject: [PATCH 6/8] Adjust the mine test a little bit to give it a better chance of success (#34647) --- tests/integration/modules/mine.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/modules/mine.py b/tests/integration/modules/mine.py index f65008ec2e..665c3c8fb8 100644 --- a/tests/integration/modules/mine.py +++ b/tests/integration/modules/mine.py @@ -2,8 +2,9 @@ ''' Test the salt mine system ''' -# Import Pytohn libs +# Import Python libs from __future__ import absolute_import +import time # Import Salt Testing libs from salttesting.helpers import ensure_in_syspath @@ -83,6 +84,8 @@ class MineTest(integration.ModuleCase): minion_tgt=minion_id ) ) + time.sleep(1) + for minion_id in ('minion', 'sub_minion'): ret = self.run_function( 'mine.get', [minion_id, 'grains.items'], From bc63f25a6f27c3f0229ebc184abaa8248de6ea62 Mon Sep 17 00:00:00 2001 From: Nicole Thomas Date: Wed, 13 Jul 2016 18:58:54 -0400 Subject: [PATCH 7/8] Lint 34644 (#34651) * Better error handling for __virtual__ in dockerng module * Modify lodaer global test to use populated dunders This prevents a number of errors in the error log and makes for a more robust test IMHO * Lint #34644 --- salt/modules/dockerng.py | 10 +++++++--- tests/integration/loader/globals.py | 28 +++++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/salt/modules/dockerng.py b/salt/modules/dockerng.py index 851e1c5c33..cd4197b6a2 100644 --- a/salt/modules/dockerng.py +++ b/salt/modules/dockerng.py @@ -526,8 +526,12 @@ def __virtual__(): Only load if docker libs are present ''' if HAS_DOCKER_PY: - docker_py_versioninfo = _get_docker_py_versioninfo() - + try: + docker_py_versioninfo = _get_docker_py_versioninfo() + except Exception: + # May fail if we try to connect to a docker daemon but can't + return (False, 'Docker module found, but no version could be' + ' extracted') # Don't let a failure to interpret the version keep this module from # loading. Log a warning (log happens in _get_docker_py_versioninfo()). if docker_py_versioninfo is None: @@ -536,7 +540,7 @@ def __virtual__(): if docker_py_versioninfo >= MIN_DOCKER_PY: try: docker_versioninfo = version().get('VersionInfo') - except CommandExecutionError: + except Exception: docker_versioninfo = None if docker_versioninfo is None or docker_versioninfo >= MIN_DOCKER: diff --git a/tests/integration/loader/globals.py b/tests/integration/loader/globals.py index 2769955c2c..9e1807e43f 100644 --- a/tests/integration/loader/globals.py +++ b/tests/integration/loader/globals.py @@ -19,6 +19,7 @@ import integration import salt.loader import inspect import yaml +import copy # Import 3rd-party libs import salt.ext.six as six @@ -33,6 +34,15 @@ class LoaderGlobalsTest(integration.ModuleCase): This is intended as a shorter term way of testing these so we don't break the loader ''' + + def setUp(self): + # Poor man's classSetUp (not supported in 2.6) + if not hasattr(self, 'minion_mods'): + self.opts = dict(copy.deepcopy(self.master_opts)) + self.opts['grains'] = salt.loader.grains(self.opts) + self.utils = salt.loader.utils(self.opts) + self.minion_mods = salt.loader.minion_mods(self.opts, utils=self.utils) + def _verify_globals(self, mod_dict): ''' Verify that the globals listed in the doc string (from the test) are in these modules @@ -64,7 +74,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __salt__ - __context__ ''' - self._verify_globals(salt.loader.auth(self.master_opts)) + self._verify_globals(salt.loader.auth(self.opts)) def test_runners(self): ''' @@ -75,7 +85,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.runner(self.master_opts)) + self._verify_globals(salt.loader.runner(self.opts)) def test_returners(self): ''' @@ -86,7 +96,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.returners(self.master_opts, {})) + self._verify_globals(salt.loader.returners(self.opts, {})) def test_pillars(self): ''' @@ -97,13 +107,13 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.pillars(self.master_opts, {})) + self._verify_globals(salt.loader.pillars(self.opts, {})) def test_tops(self): ''' Test that tops have: [] ''' - self._verify_globals(salt.loader.tops(self.master_opts)) + self._verify_globals(salt.loader.tops(self.opts)) def test_outputters(self): ''' @@ -113,13 +123,13 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.outputters(self.master_opts)) + self._verify_globals(salt.loader.outputters(self.opts)) def test_serializers(self): ''' Test that serializers have: [] ''' - self._verify_globals(salt.loader.serializers(self.master_opts)) + self._verify_globals(salt.loader.serializers(self.opts)) def test_states(self): ''' @@ -130,7 +140,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.states(self.master_opts, {}, {})) + self._verify_globals(salt.loader.states(self.opts, self.minion_mods, {})) def test_renderers(self): ''' @@ -141,7 +151,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __opts__ # Minion configuration options - __context__ # Context dict shared amongst all modules of the same type ''' - self._verify_globals(salt.loader.render(self.master_opts, {})) + self._verify_globals(salt.loader.render(self.opts, {})) if __name__ == '__main__': From 64a154826a170c431fc4de4e25150788b5476514 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 14 Jul 2016 12:11:44 -0600 Subject: [PATCH 8/8] Revert "Modify lodaer global test to use populated dunders" This reverts commit f45dbe8508df70ce3f563915318791614449b341. --- tests/integration/loader/globals.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/tests/integration/loader/globals.py b/tests/integration/loader/globals.py index 9e1807e43f..2769955c2c 100644 --- a/tests/integration/loader/globals.py +++ b/tests/integration/loader/globals.py @@ -19,7 +19,6 @@ import integration import salt.loader import inspect import yaml -import copy # Import 3rd-party libs import salt.ext.six as six @@ -34,15 +33,6 @@ class LoaderGlobalsTest(integration.ModuleCase): This is intended as a shorter term way of testing these so we don't break the loader ''' - - def setUp(self): - # Poor man's classSetUp (not supported in 2.6) - if not hasattr(self, 'minion_mods'): - self.opts = dict(copy.deepcopy(self.master_opts)) - self.opts['grains'] = salt.loader.grains(self.opts) - self.utils = salt.loader.utils(self.opts) - self.minion_mods = salt.loader.minion_mods(self.opts, utils=self.utils) - def _verify_globals(self, mod_dict): ''' Verify that the globals listed in the doc string (from the test) are in these modules @@ -74,7 +64,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __salt__ - __context__ ''' - self._verify_globals(salt.loader.auth(self.opts)) + self._verify_globals(salt.loader.auth(self.master_opts)) def test_runners(self): ''' @@ -85,7 +75,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.runner(self.opts)) + self._verify_globals(salt.loader.runner(self.master_opts)) def test_returners(self): ''' @@ -96,7 +86,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.returners(self.opts, {})) + self._verify_globals(salt.loader.returners(self.master_opts, {})) def test_pillars(self): ''' @@ -107,13 +97,13 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.pillars(self.opts, {})) + self._verify_globals(salt.loader.pillars(self.master_opts, {})) def test_tops(self): ''' Test that tops have: [] ''' - self._verify_globals(salt.loader.tops(self.opts)) + self._verify_globals(salt.loader.tops(self.master_opts)) def test_outputters(self): ''' @@ -123,13 +113,13 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.outputters(self.opts)) + self._verify_globals(salt.loader.outputters(self.master_opts)) def test_serializers(self): ''' Test that serializers have: [] ''' - self._verify_globals(salt.loader.serializers(self.opts)) + self._verify_globals(salt.loader.serializers(self.master_opts)) def test_states(self): ''' @@ -140,7 +130,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __grains__ - __context__ ''' - self._verify_globals(salt.loader.states(self.opts, self.minion_mods, {})) + self._verify_globals(salt.loader.states(self.master_opts, {}, {})) def test_renderers(self): ''' @@ -151,7 +141,7 @@ class LoaderGlobalsTest(integration.ModuleCase): - __opts__ # Minion configuration options - __context__ # Context dict shared amongst all modules of the same type ''' - self._verify_globals(salt.loader.render(self.opts, {})) + self._verify_globals(salt.loader.render(self.master_opts, {})) if __name__ == '__main__':