Example #1
0
    def test_stopped(self):
        '''
        Test to ensure that a container is stopped.
        '''
        name = 'web01'

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

        mock = MagicMock(return_value={'state': {'new': 'stop'}})
        mock_t = MagicMock(side_effect=[None, 'stopped', 'frozen', 'frozen'])
        with patch.dict(lxc.__salt__, {'lxc.stop': mock,
                                       'lxc.state': mock_t}):
            comt = ('Container \'{0}\' does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(lxc.stopped(name), ret)

            comt = ('Container \'{0}\' is already stopped'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {'test': True}):
                comt = ("Container 'web01' would be stopped")
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {'test': False}):
                comt = ("Unable to stop container 'web01'")
                ret.update({'comment': comt, 'result': False, 'changes':
                            {'state': {'new': 'stop', 'old': 'frozen'}}})
                self.assertDictEqual(lxc.stopped(name), ret)
Example #2
0
    def test_stopped(self):
        '''
        Test to ensure that a container is stopped.
        '''
        name = 'web01'

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

        mock = MagicMock(return_value={'state': {'new': 'stop'}})
        mock_t = MagicMock(side_effect=[None, 'stopped', 'frozen', 'frozen'])
        with patch.dict(lxc.__salt__, {'lxc.stop': mock,
                                       'lxc.state': mock_t}):
            comt = ('Container \'{0}\' does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(lxc.stopped(name), ret)

            comt = ('Container \'{0}\' is already stopped'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {'test': True}):
                comt = ("Container 'web01' would be stopped")
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {'test': False}):
                comt = ("Unable to stop container 'web01'")
                ret.update({'comment': comt, 'result': False, 'changes':
                            {'state': {'new': 'stop', 'old': 'frozen'}}})
                self.assertDictEqual(lxc.stopped(name), ret)
Example #3
0
    def test_stopped(self):
        """
        Test to ensure that a container is stopped.
        """
        name = "web01"

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

        mock = MagicMock(return_value={"state": {"new": "stop"}})
        mock_t = MagicMock(side_effect=[None, "stopped", "frozen", "frozen"])
        with patch.dict(lxc.__salt__, {"lxc.stop": mock, "lxc.state": mock_t}):
            comt = "Container '{}' does not exist".format(name)
            ret.update({"comment": comt})
            self.assertDictEqual(lxc.stopped(name), ret)

            comt = "Container '{}' is already stopped".format(name)
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {"test": True}):
                comt = "Container 'web01' would be stopped"
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(lxc.stopped(name), ret)

            with patch.dict(lxc.__opts__, {"test": False}):
                comt = "Unable to stop container 'web01'"
                ret.update({
                    "comment": comt,
                    "result": False,
                    "changes": {
                        "state": {
                            "new": "stop",
                            "old": "frozen"
                        }
                    },
                })
                self.assertDictEqual(lxc.stopped(name), ret)