Beispiel #1
0
def test_license_absent():
    """
    Test to ensures that the specified PowerPath license key is absent
    on the host.
    """
    name = "mylic"

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

    mock_t = MagicMock(side_effect=[
        {
            "result": True,
            "output": name
        },
        {
            "result": False,
            "output": name
        },
    ])
    mock = MagicMock(side_effect=[False, True, True, True, True])
    mock_l = MagicMock(return_value=[{"key": "salt"}])
    with patch.dict(
            powerpath.__salt__,
        {
            "powerpath.has_powerpath": mock,
            "powerpath.list_licenses": mock_l,
            "powerpath.remove_license": mock_t,
        },
    ):
        comt = "PowerPath is not installed."
        ret.update({"comment": comt, "result": False})
        assert powerpath.license_absent(name) == ret

        comt = "License key {} not present".format(name)
        ret.update({"comment": comt, "result": True})
        assert powerpath.license_absent(name) == ret

        with patch.dict(powerpath.__opts__, {"test": True}):
            comt = "License key salt is set to be removed"
            ret.update({"comment": comt, "result": None, "name": "salt"})
            assert powerpath.license_absent("salt") == ret

        with patch.dict(powerpath.__opts__, {"test": False}):
            ret.update({
                "comment": name,
                "result": True,
                "changes": {
                    "salt": "removed"
                }
            })
            assert powerpath.license_absent("salt") == ret

            ret.update({"result": False, "changes": {}})
            assert powerpath.license_absent("salt") == ret
Beispiel #2
0
    def test_license_absent(self):
        '''
        Test to ensures that the specified PowerPath license key is absent
        on the host.
        '''
        name = 'mylic'

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

        mock_t = MagicMock(side_effect=[{
            'result': True,
            'output': name
        }, {
            'result': False,
            'output': name
        }])
        mock = MagicMock(side_effect=[False, True, True, True, True])
        mock_l = MagicMock(return_value=[{'key': 'salt'}])
        with patch.dict(
                powerpath.__salt__, {
                    'powerpath.has_powerpath': mock,
                    'powerpath.list_licenses': mock_l,
                    'powerpath.remove_license': mock_t
                }):
            comt = ('PowerPath is not installed.')
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(powerpath.license_absent(name), ret)

            comt = ('License key {0} not present'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(powerpath.license_absent(name), ret)

            with patch.dict(powerpath.__opts__, {'test': True}):
                comt = ('License key salt is set to be removed')
                ret.update({'comment': comt, 'result': None, 'name': 'salt'})
                self.assertDictEqual(powerpath.license_absent('salt'), ret)

            with patch.dict(powerpath.__opts__, {'test': False}):
                ret.update({
                    'comment': name,
                    'result': True,
                    'changes': {
                        'salt': 'removed'
                    }
                })
                self.assertDictEqual(powerpath.license_absent('salt'), ret)

                ret.update({'result': False, 'changes': {}})
                self.assertDictEqual(powerpath.license_absent('salt'), ret)
Beispiel #3
0
    def test_license_absent(self):
        '''
        Test to ensures that the specified PowerPath license key is absent
        on the host.
        '''
        name = 'mylic'

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

        mock_t = MagicMock(side_effect=[{'result': True, 'output': name},
                                        {'result': False, 'output': name}])
        mock = MagicMock(side_effect=[False, True, True, True, True])
        mock_l = MagicMock(return_value=[{'key': 'salt'}])
        with patch.dict(powerpath.__salt__,
                        {'powerpath.has_powerpath': mock,
                         'powerpath.list_licenses': mock_l,
                         'powerpath.remove_license': mock_t}):
            comt = ('PowerPath is not installed.')
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(powerpath.license_absent(name), ret)

            comt = ('License key {0} not present'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(powerpath.license_absent(name), ret)

            with patch.dict(powerpath.__opts__, {'test': True}):
                comt = ('License key salt is set to be removed')
                ret.update({'comment': comt, 'result': None, 'name': 'salt'})
                self.assertDictEqual(powerpath.license_absent('salt'), ret)

            with patch.dict(powerpath.__opts__, {'test': False}):
                ret.update({'comment': name, 'result': True,
                            'changes': {'salt': 'removed'}})
                self.assertDictEqual(powerpath.license_absent('salt'), ret)

                ret.update({'result': False, 'changes': {}})
                self.assertDictEqual(powerpath.license_absent('salt'), ret)