From 70e36764ee2575a86bfc8c0098b37443f4ec7f53 Mon Sep 17 00:00:00 2001 From: Ch3LL Date: Thu, 12 Jul 2018 12:16:33 -0400 Subject: [PATCH] Add more tests for salt-ssh state.sls_id --- salt/client/ssh/wrapper/state.py | 3 +++ .../files/file/base/ssh_state_tests.sls | 4 +++ tests/integration/ssh/test_state.py | 27 +++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/salt/client/ssh/wrapper/state.py b/salt/client/ssh/wrapper/state.py index 2a7e4aa130..6b8f39325e 100644 --- a/salt/client/ssh/wrapper/state.py +++ b/salt/client/ssh/wrapper/state.py @@ -33,6 +33,9 @@ log = logging.getLogger(__name__) def _ssh_state(chunks, __opts__, __context__, __pillar__, __salt__, st_kwargs, kwargs, test=False): + ''' + funciton to run a state with the given chunk via salt-ssh + ''' file_refs = salt.client.ssh.state.lowstate_file_refs( chunks, _merge_extra_filerefs( diff --git a/tests/integration/files/file/base/ssh_state_tests.sls b/tests/integration/files/file/base/ssh_state_tests.sls index a121bdfb77..642d33fa3c 100644 --- a/tests/integration/files/file/base/ssh_state_tests.sls +++ b/tests/integration/files/file/base/ssh_state_tests.sls @@ -3,3 +3,7 @@ ssh-file-test: file.managed: - name: /tmp/{{ jinja }} - contents: 'test' + +second_id: + cmd.run: + - name: echo test diff --git a/tests/integration/ssh/test_state.py b/tests/integration/ssh/test_state.py index 45bdee27aa..031d91896a 100644 --- a/tests/integration/ssh/test_state.py +++ b/tests/integration/ssh/test_state.py @@ -24,9 +24,12 @@ class SSHStateTest(SSHCase): ''' testing the state system with salt-ssh ''' - def _check_dict_ret(self, ret, val, exp_ret): + def _check_dict_ret(self, ret, val, exp_ret, equal=True): for key, value in ret.items(): - self.assertEqual(value[val], exp_ret) + if equal: + self.assertEqual(value[val], exp_ret) + else: + self.assertNotEqual(value[val], exp_ret) def _check_request(self, empty=False): check = self.run_function('state.check_request', wipe=False) @@ -50,12 +53,32 @@ class SSHStateTest(SSHCase): ''' test state.sls_id with salt-ssh ''' + # check state.sls_id with test=True + ret = self.run_function('state.sls_id', ['ssh-file-test', SSH_SLS, + 'test=True']) + self._check_dict_ret(ret=ret, val='comment', + exp_ret='The file /tmp/test is set to be changed') + + # check state.sls_id without test=True ret = self.run_function('state.sls_id', ['ssh-file-test', SSH_SLS]) self._check_dict_ret(ret=ret, val='__sls__', exp_ret=SSH_SLS) + # make sure the other id in the state was not run + self._check_dict_ret(ret=ret, val='__id__', + exp_ret='second_id', equal=False) + + check_file = self.run_function('file.file_exists', ['/tmp/test']) self.assertTrue(check_file) + def test_state_sls_wrong_id(self): + ''' + test state.sls_id when id does not exist + ''' + # check state.sls_id with test=True + ret = self.run_function('state.sls_id', ['doesnotexist', SSH_SLS]) + assert 'No matches for ID' in ret + def test_state_show_sls(self): ''' test state.show_sls with salt-ssh