diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 0ede993700..2d971816f5 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -848,6 +848,12 @@ class TestDaemon(object): ) opts_dict['extension_modules'] = os.path.join(opts_dict['root_dir'], 'extension_modules') + # Copy the autosign_file to the new master root_dir + shutil.copyfile( + os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'), + os.path.join(opts_dict['root_dir'], 'autosign_file') + ) + # Point the config values to the correct temporary paths for name in ('hosts', 'aliases'): optname = '{0}.file'.format(name) diff --git a/tests/integration/daemons/test_masterapi.py b/tests/integration/daemons/test_masterapi.py index d32b6d56f4..67ea52ae0d 100644 --- a/tests/integration/daemons/test_masterapi.py +++ b/tests/integration/daemons/test_masterapi.py @@ -7,6 +7,7 @@ import shutil # Import Salt Testing libs from tests.support.case import ShellCase +from tests.support.paths import TMP, INTEGRATION_TEST_DIR # Import 3rd-party libs @@ -19,53 +20,45 @@ class AutosignGrainsTest(ShellCase): Test autosigning minions based on grain values. ''' - def test_autosign_grains_accept(self): + def setUp(self): + shutil.copyfile( + os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_grains', 'autosign_file'), + os.path.join(TMP, 'root_dir', 'autosign_file') + ) self.run_key('-d minion -y') self.run_call('test.ping') # get minon to try to authenticate itself again - try: - self.assertEqual(self.run_key('-l acc'), ['Accepted Keys:', 'sub_minion']) - self.assertEqual(self.run_key('-l un'), ['Unaccepted Keys:', 'minion']) - except AssertionError: - self.run_key('-a minion -y') - raise + if 'minion' in self.run_key('-l acc'): + self.skipTest('Could not deauthorize minion') + if 'minion' not in self.run_key('-l un'): + self.skipTest('minion did not try to authenticate itself') - autosign_grains_dir = os.path.join(self.master_opts['autosign_grains_dir']) - if not os.path.isdir(autosign_grains_dir): - os.makedirs(autosign_grains_dir) - with salt.utils.files.fopen(os.path.join(autosign_grains_dir, 'test_grain'), 'w') as f: + self.autosign_grains_dir = os.path.join(self.master_opts['autosign_grains_dir']) + if not os.path.isdir(self.autosign_grains_dir): + os.makedirs(self.autosign_grains_dir) + + def tearDown(self): + shutil.copyfile( + os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'), + os.path.join(TMP, 'root_dir', 'autosign_file') + ) + self.run_call('test.ping') # get minon to try to authenticate itself again + self.run_key('-a minion -y') + + if os.path.isdir(self.autosign_grains_dir): + shutil.rmtree(self.autosign_grains_dir) + + def test_autosign_grains_accept(self): + with salt.utils.files.fopen(os.path.join(self.autosign_grains_dir, 'test_grain'), 'w') as f: f.write('#invalid_value\ncheese') self.run_call('test.ping') # get minon to try to authenticate itself again - try: - self.assertEqual(self.run_key('-l acc'), ['Accepted Keys:', 'minion', 'sub_minion']) - finally: - self.run_key('-a minion -y') - if os.path.isdir(autosign_grains_dir): - shutil.rmtree(autosign_grains_dir) + self.assertIn('minion', self.run_key('-l acc')) def test_autosign_grains_fail(self): - self.run_key('-d minion -y') - self.run_call('test.ping') # get minon to try to authenticate itself again - - try: - self.assertEqual(self.run_key('-l acc'), ['Accepted Keys:', 'sub_minion']) - self.assertEqual(self.run_key('-l un'), ['Unaccepted Keys:', 'minion']) - except AssertionError: - self.run_key('-a minion -y') - raise - - autosign_grains_dir = os.path.join(self.master_opts['autosign_grains_dir']) - if not os.path.isdir(autosign_grains_dir): - os.makedirs(autosign_grains_dir) - with salt.utils.files.fopen(os.path.join(autosign_grains_dir, 'test_grain'), 'w') as f: + with salt.utils.files.fopen(os.path.join(self.autosign_grains_dir, 'test_grain'), 'w') as f: f.write('#cheese\ninvalid_value') self.run_call('test.ping') # get minon to try to authenticate itself again - try: - self.assertEqual(self.run_key('-l acc'), ['Accepted Keys:', 'sub_minion']) - self.assertEqual(self.run_key('-l un'), ['Unaccepted Keys:', 'minion']) - finally: - self.run_key('-a minion -y') - if os.path.isdir(autosign_grains_dir): - shutil.rmtree(autosign_grains_dir) + self.assertNotIn('minion', self.run_key('-l acc')) + self.assertIn('minion', self.run_key('-l un')) diff --git a/tests/integration/files/autosign_file b/tests/integration/files/autosign_file new file mode 100644 index 0000000000..120b5bedb5 --- /dev/null +++ b/tests/integration/files/autosign_file @@ -0,0 +1,3 @@ +minion +sub_minion +syndic diff --git a/tests/integration/files/autosign_grains/autosign_file b/tests/integration/files/autosign_grains/autosign_file new file mode 100644 index 0000000000..819340bb0c --- /dev/null +++ b/tests/integration/files/autosign_grains/autosign_file @@ -0,0 +1,2 @@ +sub_minion +syndic diff --git a/tests/integration/files/conf/master b/tests/integration/files/conf/master index 55606ab416..17a18016d2 100644 --- a/tests/integration/files/conf/master +++ b/tests/integration/files/conf/master @@ -8,7 +8,6 @@ worker_threads: 3 pidfile: master.pid sock_dir: master_sock timeout: 12 -open_mode: True fileserver_list_cache_time: 0 file_buffer_size: 8192 file_recv: True @@ -99,3 +98,4 @@ libcloud_dns: shopper_id: 12345 autosign_grains_dir: autosign_grains +autosign_file: autosign_file