Пример #1
0
def test_absent():
    """
    Test to ensure that no instances with the specified names exist.
    """
    name = "mycloud"

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

    mock = MagicMock(side_effect=[True, False])
    mock_bool = MagicMock(side_effect=[False, True, True])
    mock_dict = MagicMock(return_value={"cloud": "saltcloud"})
    with patch.dict(
            cloud.__salt__,
        {
            "cmd.retcode": mock,
            "cloud.has_instance": mock_bool,
            "cloud.destroy": mock_dict,
        },
    ):
        comt = "onlyif condition is false"
        ret.update({"comment": comt})
        assert cloud.absent(name, onlyif=False) == ret

        assert cloud.absent(name, onlyif="") == ret

        comt = "unless condition is true"
        ret.update({"comment": comt})
        assert cloud.absent(name, unless=True) == ret

        assert cloud.absent(name, unless="") == ret

        comt = "Already absent instance {}".format(name)
        ret.update({"comment": comt})
        assert cloud.absent(name) == ret

        with patch.dict(cloud.__opts__, {"test": True}):
            comt = "Instance {} needs to be destroyed".format(name)
            ret.update({"comment": comt, "result": None})
            assert cloud.absent(name) == ret

        with patch.dict(cloud.__opts__, {"test": False}):
            comt = ("Destroyed instance {}").format(name)
            ret.update({
                "comment": comt,
                "result": True,
                "changes": {
                    "cloud": "saltcloud"
                }
            })
            assert cloud.absent(name) == ret
Пример #2
0
    def test_absent(self):
        '''
        Test to ensure that no instances with the specified names exist.
        '''
        name = 'mycloud'

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

        mock = MagicMock(side_effect=[True, False])
        mock_bool = MagicMock(side_effect=[False, True, True])
        mock_dict = MagicMock(return_value={'cloud': 'saltcloud'})
        with patch.dict(
                cloud.__salt__, {
                    'cmd.retcode': mock,
                    'cloud.has_instance': mock_bool,
                    'cloud.destroy': mock_dict
                }):
            comt = ('onlyif execution failed')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name, onlyif=False), ret)

            self.assertDictEqual(cloud.absent(name, onlyif=''), ret)

            comt = ('unless execution succeeded')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name, unless=True), ret)

            self.assertDictEqual(cloud.absent(name, unless=''), ret)

            comt = ('Already absent instance {0}'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name), ret)

            with patch.dict(cloud.__opts__, {'test': True}):
                comt = ('Instance {0} needs to be destroyed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(cloud.absent(name), ret)

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = (('Destroyed instance {0}').format(name))
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        'cloud': 'saltcloud'
                    }
                })
                self.assertDictEqual(cloud.absent(name), ret)
Пример #3
0
    def test_absent(self):
        '''
        Test to ensure that no instances with the specified names exist.
        '''
        name = 'mycloud'

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

        mock = MagicMock(side_effect=[True, False])
        mock_bool = MagicMock(side_effect=[False, True, True])
        mock_dict = MagicMock(return_value={'cloud': 'saltcloud'})
        with patch.dict(cloud.__salt__, {'cmd.retcode': mock,
                                         'cloud.has_instance': mock_bool,
                                         'cloud.destroy': mock_dict}):
            comt = ('onlyif execution failed')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name, onlyif=False), ret)

            self.assertDictEqual(cloud.absent(name, onlyif=''), ret)

            comt = ('unless execution succeeded')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name, unless=True), ret)

            self.assertDictEqual(cloud.absent(name, unless=''), ret)

            comt = ('Already absent instance {0}'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.absent(name), ret)

            with patch.dict(cloud.__opts__, {'test': True}):
                comt = ('Instance {0} needs to be destroyed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(cloud.absent(name), ret)

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = (('Destroyed instance {0}').format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'cloud': 'saltcloud'}})
                self.assertDictEqual(cloud.absent(name), ret)