コード例 #1
0
ファイル: test_cmd.py プロジェクト: mamh-mixed/saltstack-salt
def test_run_root():
    """
    Test to run a command with a different root
    """
    name = "cmd.script"

    ret = {"name": name, "result": False, "changes": {}, "comment": ""}

    with patch.dict(cmd.__grains__, {"shell": "shell"}):
        with patch.dict(cmd.__opts__, {"test": False}):
            mock = MagicMock(
                side_effect=[CommandExecutionError, {
                    "retcode": 1
                }])
            with patch.dict(cmd.__salt__, {"cmd.run_chroot": mock}):
                ret.update({"comment": "", "result": False})
                assert cmd.run(name, root="/mnt") == ret

                ret.update({
                    "comment": 'Command "cmd.script" run',
                    "result": False,
                    "changes": {
                        "retcode": 1
                    },
                })
                assert cmd.run(name, root="/mnt") == ret
コード例 #2
0
ファイル: test_cmd.py プロジェクト: paususe/salt-saltstack
    def test_run(self):
        """
        Test to run a command if certain circumstances are met.
        """
        name = "cmd.script"

        ret = {"name": name, "result": False, "changes": {}, "comment": ""}

        with patch.dict(cmd.__opts__, {"test": False}):
            comt = "Invalidly-formatted 'env' parameter. See documentation."
            ret.update({"comment": comt})
            self.assertDictEqual(cmd.run(name, env="salt"), ret)

        with patch.dict(cmd.__grains__, {"shell": "shell"}):
            with patch.dict(cmd.__opts__, {"test": False}):
                mock = MagicMock(side_effect=[CommandExecutionError, {"retcode": 1}])
                with patch.dict(cmd.__salt__, {"cmd.run_all": mock}):
                    ret.update({"comment": "", "result": False})
                    self.assertDictEqual(cmd.run(name), ret)

                    ret.update(
                        {
                            "comment": 'Command "cmd.script" run',
                            "result": False,
                            "changes": {"retcode": 1},
                        }
                    )
                    self.assertDictEqual(cmd.run(name), ret)

            with patch.dict(cmd.__opts__, {"test": True}):
                comt = 'Command "cmd.script" would have been executed'
                ret.update({"comment": comt, "result": None, "changes": {}})
                self.assertDictEqual(cmd.run(name), ret)
コード例 #3
0
    def test_run_root(self):
        '''
        Test to run a command with a different root
        '''
        name = 'cmd.script'

        ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            with patch.dict(cmd.__opts__, {'test': False}):
                mock = MagicMock(
                    side_effect=[CommandExecutionError, {
                        'retcode': 1
                    }])
                with patch.dict(cmd.__salt__, {'cmd.run_chroot': mock}):
                    ret.update({'comment': '', 'result': False})
                    self.assertDictEqual(cmd.run(name, root='/mnt'), ret)

                    ret.update({
                        'comment': 'Command "cmd.script" run',
                        'result': False,
                        'changes': {
                            'retcode': 1
                        }
                    })
                    self.assertDictEqual(cmd.run(name, root='/mnt'), ret)
コード例 #4
0
    def test_run(self):
        '''
        Test to run a command if certain circumstances are met.
        '''
        name = 'cmd.script'

        ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}

        with patch.dict(cmd.__opts__, {'test': False}):
            comt = ("Invalidly-formatted 'env' parameter. See documentation.")
            ret.update({'comment': comt})
            self.assertDictEqual(cmd.run(name, env='salt'), ret)

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            with patch.dict(cmd.__opts__, {'test': False}):
                mock = MagicMock(
                    side_effect=[CommandExecutionError, {
                        'retcode': 1
                    }])
                with patch.dict(cmd.__salt__, {'cmd.run_all': mock}):
                    ret.update({'comment': '', 'result': False})
                    self.assertDictEqual(cmd.run(name), ret)

                    ret.update({
                        'comment': 'Command "cmd.script" run',
                        'result': False,
                        'changes': {
                            'retcode': 1
                        }
                    })
                    self.assertDictEqual(cmd.run(name), ret)

            with patch.dict(cmd.__opts__, {'test': True}):
                comt = ('Command "cmd.script" would have been executed')
                ret.update({'comment': comt, 'result': None, 'changes': {}})
                self.assertDictEqual(cmd.run(name), ret)

            mock = MagicMock(return_value=1)
            with patch.dict(cmd.__salt__, {'cmd.retcode': mock}):
                with patch.dict(cmd.__opts__, {'test': False}):
                    comt = ('onlyif condition is false')
                    ret.update({
                        'comment': comt,
                        'result': True,
                        'skip_watch': True
                    })
                    self.assertDictEqual(cmd.run(name, onlyif=''), ret)
コード例 #5
0
ファイル: cmd_test.py プロジェクト: bryson/salt
    def test_run(self):
        '''
        Test to run a command if certain circumstances are met.
        '''
        name = 'cmd.script'

        ret = {'name': name,
               'result': False,
               'changes': {},
               'comment': ''}

        with patch.dict(cmd.__opts__, {'test': False}):
            comt = ("Invalidly-formatted 'env' parameter. See documentation.")
            ret.update({'comment': comt})
            self.assertDictEqual(cmd.run(name, env='salt'), ret)

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            with patch.dict(cmd.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[CommandExecutionError,
                                              {'retcode': 1}])
                with patch.dict(cmd.__salt__, {'cmd.run_all': mock}):
                    ret.update({'comment': '', 'result': False})
                    self.assertDictEqual(cmd.run(name), ret)

                    ret.update({'comment': 'Command "cmd.script" run',
                                'result': False, 'changes': {'retcode': 1}})
                    self.assertDictEqual(cmd.run(name), ret)

            with patch.dict(cmd.__opts__, {'test': True}):
                comt = ('Command "cmd.script" would have been executed')
                ret.update({'comment': comt, 'result': None, 'changes': {}})
                self.assertDictEqual(cmd.run(name), ret)

            mock = MagicMock(return_value=1)
            with patch.dict(cmd.__salt__, {'cmd.retcode': mock}):
                with patch.dict(cmd.__opts__, {'test': False}):
                    comt = ('onlyif execution failed')
                    ret.update({'comment': comt, 'result': True,
                                'skip_watch': True})
                    self.assertDictEqual(cmd.run(name, onlyif=''), ret)