Exemple #1
0
    def test_mod_watch(self):
        """
        Test to execute a cmd function based on a watch call
        """
        name = "cmd.script"

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

        def func():
            """
            Mock func method
            """
            return {}

        with patch.dict(cmd.__grains__, {"shell": "shell"}):
            with patch.dict(cmd.__opts__, {"test": False}):
                mock = MagicMock(return_value={"retcode": 1})
                with patch.dict(cmd.__salt__, {"cmd.run_all": mock}):
                    self.assertDictEqual(
                        cmd.mod_watch(name, sfun="wait", stateful=True), ret
                    )

                    comt = 'Command "cmd.script" run'
                    ret.update({"comment": comt, "changes": {"retcode": 1}})
                    self.assertDictEqual(
                        cmd.mod_watch(name, sfun="wait", stateful=False), ret
                    )

                with patch.dict(cmd.__salt__, {"cmd.script": mock}):
                    ret.update({"comment": "", "changes": {}})
                    self.assertDictEqual(
                        cmd.mod_watch(name, sfun="script", stateful=True), ret
                    )

                    comt = "Command 'cmd.script' run"
                    ret.update({"comment": comt, "changes": {"retcode": 1}})
                    self.assertDictEqual(
                        cmd.mod_watch(name, sfun="script", stateful=False), ret
                    )

                with patch.dict(cmd.__salt__, {"cmd.script": mock}):
                    ret.update({"comment": "", "changes": {}})
                    self.assertDictEqual(
                        cmd.mod_watch(name, sfun="call", func=func), ret
                    )

                    comt = "cmd.call needs a named parameter func"
                    ret.update({"comment": comt})
                    self.assertDictEqual(cmd.mod_watch(name, sfun="call"), ret)

                comt = (
                    "cmd.salt does not work with the watch requisite,"
                    " please use cmd.wait or cmd.wait_script"
                )
                ret.update({"comment": comt})
                self.assertDictEqual(cmd.mod_watch(name, sfun="salt"), ret)
Exemple #2
0
    def test_mod_watch(self):
        '''
        Test to execute a cmd function based on a watch call
        '''
        name = 'cmd.script'

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

        def func():
            '''
            Mock func method
            '''
            return {}

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            with patch.dict(cmd.__opts__, {'test': False}):
                mock = MagicMock(return_value={'retcode': 1})
                with patch.dict(cmd.__salt__, {'cmd.run_all': mock}):
                    self.assertDictEqual(cmd.mod_watch(name, sfun='wait',
                                                       stateful=True), ret)

                    comt = ('Command "cmd.script" run')
                    ret.update({'comment': comt, 'changes': {'retcode': 1}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='wait',
                                                       stateful=False), ret)

                with patch.dict(cmd.__salt__, {'cmd.script': mock}):
                    ret.update({'comment': '', 'changes': {}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='script',
                                                       stateful=True), ret)

                    comt = ("Command 'cmd.script' run")
                    ret.update({'comment': comt, 'changes': {'retcode': 1}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='script',
                                                       stateful=False), ret)

                with patch.dict(cmd.__salt__, {'cmd.script': mock}):
                    ret.update({'comment': '', 'changes': {}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='call',
                                                       func=func), ret)

                    comt = ('cmd.call needs a named parameter func')
                    ret.update({'comment': comt})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='call'), ret)

                comt = ('cmd.salt does not work with the watch requisite,'
                        ' please use cmd.wait or cmd.wait_script')
                ret.update({'comment': comt})
                self.assertDictEqual(cmd.mod_watch(name, sfun='salt'), ret)
Exemple #3
0
    def test_mod_watch(self):
        '''
        Test to execute a cmd function based on a watch call
        '''
        name = 'cmd.script'

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

        def func():
            '''
            Mock func method
            '''
            return {}

        with patch.dict(cmd.__grains__, {'shell': 'shell'}):
            with patch.dict(cmd.__opts__, {'test': False}):
                mock = MagicMock(return_value={'retcode': 1})
                with patch.dict(cmd.__salt__, {'cmd.run_all': mock}):
                    self.assertDictEqual(cmd.mod_watch(name, sfun='wait',
                                                       stateful=True), ret)

                    comt = ('Command "cmd.script" run')
                    ret.update({'comment': comt, 'changes': {'retcode': 1}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='wait',
                                                       stateful=False), ret)

                with patch.dict(cmd.__salt__, {'cmd.script': mock}):
                    ret.update({'comment': '', 'changes': {}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='script',
                                                       stateful=True), ret)

                    comt = ("Command 'cmd.script' run")
                    ret.update({'comment': comt, 'changes': {'retcode': 1}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='script',
                                                       stateful=False), ret)

                with patch.dict(cmd.__salt__, {'cmd.script': mock}):
                    ret.update({'comment': '', 'changes': {}})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='call',
                                                       func=func), ret)

                    comt = ('cmd.call needs a named parameter func')
                    ret.update({'comment': comt})
                    self.assertDictEqual(cmd.mod_watch(name, sfun='call'), ret)

                comt = ('cmd.salt does not work with the watch requisite,'
                        ' please use cmd.wait or cmd.wait_script')
                ret.update({'comment': comt})
                self.assertDictEqual(cmd.mod_watch(name, sfun='salt'), ret)