Esempio n. 1
0
    def test_absent(self):
        '''
        Test to ensure a container is not present, destroying it if present.
        '''
        name = 'web01'

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

        mock = MagicMock(side_effect=[False, True, True])
        mock_des = MagicMock(return_value={'state': True})
        with patch.dict(lxc.__salt__, {'lxc.exists': mock,
                                       'lxc.destroy': mock_des}):
            comt = ('Container \'{0}\' does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(lxc.absent(name), ret)

            with patch.dict(lxc.__opts__, {'test': True}):
                comt = ('Container \'{0}\' would be destroyed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(lxc.absent(name), ret)

            with patch.dict(lxc.__opts__, {'test': False}):
                comt = ('Container \'{0}\' was destroyed'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'state': True}})
                self.assertDictEqual(lxc.absent(name), ret)
Esempio n. 2
0
    def test_absent(self):
        '''
        Test to ensure a container is not present, destroying it if present.
        '''
        name = 'web01'

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

        mock = MagicMock(side_effect=[False, True, True])
        mock_des = MagicMock(return_value={'state': True})
        with patch.dict(lxc.__salt__, {'lxc.exists': mock,
                                       'lxc.destroy': mock_des}):
            comt = ('Container \'{0}\' does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(lxc.absent(name), ret)

            with patch.dict(lxc.__opts__, {'test': True}):
                comt = ('Container \'{0}\' would be destroyed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(lxc.absent(name), ret)

            with patch.dict(lxc.__opts__, {'test': False}):
                comt = ('Container \'{0}\' was destroyed'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'state': True}})
                self.assertDictEqual(lxc.absent(name), ret)
Esempio n. 3
0
    def test_absent(self):
        """
        Test to ensure a container is not present, destroying it if present.
        """
        name = "web01"

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

        mock = MagicMock(side_effect=[False, True, True])
        mock_des = MagicMock(return_value={"state": True})
        with patch.dict(lxc.__salt__, {
                "lxc.exists": mock,
                "lxc.destroy": mock_des
        }):
            comt = "Container '{}' does not exist".format(name)
            ret.update({"comment": comt})
            self.assertDictEqual(lxc.absent(name), ret)

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

            with patch.dict(lxc.__opts__, {"test": False}):
                comt = "Container '{}' was destroyed".format(name)
                ret.update({
                    "comment": comt,
                    "result": True,
                    "changes": {
                        "state": True
                    }
                })
                self.assertDictEqual(lxc.absent(name), ret)