示例#1
0
文件: kmod_test.py 项目: DaveQB/salt
    def test_absent(self):
        '''
        Test to verify that the named kernel module is not loaded.
        '''
        name = 'kvm_amd'

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

        mock = MagicMock(side_effect=[[name], [name], [name], []])
        mock_t = MagicMock(side_effect=[[name], ['A']])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock,
                                        'kmod.remove': mock_t}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comt = ('Module {0} is set to be unloaded'.format(name))
                ret.update({'comment': comt})
                self.assertDictEqual(kmod.absent(name), ret)

            with patch.dict(kmod.__opts__, {'test': False}):
                comt = ('Removed kernel module {0}'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {name: 'removed'}})
                self.assertDictEqual(kmod.absent(name), ret)

                comt = ('Module {0} is present but failed to remove'
                        .format(name))
                ret.update({'comment': comt, 'result': False,
                            'changes': {'A': 'removed'}})
                self.assertDictEqual(kmod.absent(name), ret)

            comt = ('Kernel module {0} is already absent'.format(name))
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(kmod.absent(name), ret)
示例#2
0
    def test_absent_multi(self):
        '''
        Test to verify that multiple kernel modules are not loaded.
        '''
        name = 'salted kernel'
        mods = ['cheese', 'crackers']
        ret = {'name': name, 'result': True, 'changes': {}}

        mock_mod_list = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                ret.update({'result': None})
                call_ret = kmod.absent(name, mods=mods)

                # Check comment independently: makes test more stable on PY3
                comment = call_ret.pop('comment')
                self.assertIn('cheese', comment)
                self.assertIn('crackers', comment)
                self.assertIn('are set to be removed', comment)

                # Assert against all other dictionary key/values
                self.assertDictEqual(ret, call_ret)

        mock_mod_list = MagicMock(return_value=mods)
        mock_remove = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {
                'kmod.mod_list': mock_mod_list,
                'kmod.remove': mock_remove
        }):
            with patch.dict(kmod.__opts__, {'test': False}):
                call_ret = kmod.absent(name, mods=mods)
                ret.update({
                    'result': True,
                    'changes': {
                        mods[0]: 'removed',
                        mods[1]: 'removed'
                    }
                })

                # Check comment independently: makes test more stable on PY3
                comment = call_ret.pop('comment')
                self.assertIn('cheese', comment)
                self.assertIn('crackers', comment)
                self.assertIn('Removed kernel modules', comment)

                # Assert against all other dictionary key/values
                self.assertDictEqual(ret, call_ret)

        mock_mod_list = MagicMock(return_value=[])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel modules {0} are already removed'.format(
                    ', '.join(mods))
                ret.update({'comment': comment, 'result': True, 'changes': {}})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)
示例#3
0
def test_absent_multi():
    """
    Test to verify that multiple kernel modules are not loaded.
    """
    name = "salted kernel"
    mods = ["cheese", "crackers"]
    ret = {"name": name, "result": True, "changes": {}}

    mock_mod_list = MagicMock(return_value=mods)
    with patch.dict(kmod.__salt__, {"kmod.mod_list": mock_mod_list}):
        with patch.dict(kmod.__opts__, {"test": True}):
            ret.update({"result": None})
            call_ret = kmod.absent(name, mods=mods)

            # Check comment independently: makes test more stable on PY3
            comment = call_ret.pop("comment")
            assert "cheese" in comment
            assert "crackers" in comment
            assert "are set to be removed" in comment

            # Assert against all other dictionary key/values
            assert ret == call_ret

    mock_mod_list = MagicMock(return_value=mods)
    mock_remove = MagicMock(return_value=mods)
    with patch.dict(kmod.__salt__, {
            "kmod.mod_list": mock_mod_list,
            "kmod.remove": mock_remove
    }):
        with patch.dict(kmod.__opts__, {"test": False}):
            call_ret = kmod.absent(name, mods=mods)
            ret.update({
                "result": True,
                "changes": {
                    mods[0]: "removed",
                    mods[1]: "removed"
                }
            })

            # Check comment independently: makes test more stable on PY3
            comment = call_ret.pop("comment")
            assert "cheese" in comment
            assert "crackers" in comment
            assert "Removed kernel modules" in comment

            # Assert against all other dictionary key/values
            assert ret == call_ret

    mock_mod_list = MagicMock(return_value=[])
    with patch.dict(kmod.__salt__, {"kmod.mod_list": mock_mod_list}):
        with patch.dict(kmod.__opts__, {"test": True}):
            comment = "Kernel modules {} are already removed".format(
                ", ".join(mods))
            ret.update({"comment": comment, "result": True, "changes": {}})
            assert kmod.absent(name, mods=mods) == ret
示例#4
0
    def test_absent(self):
        '''
        Test to verify that the named kernel module is not loaded.
        '''
        name = 'kvm_amd'

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

        mock = MagicMock(side_effect=[[name], [name], [name], []])
        mock_t = MagicMock(side_effect=[[name], ['A']])
        with patch.dict(kmod.__salt__, {
                'kmod.mod_list': mock,
                'kmod.remove': mock_t
        }):
            with patch.dict(kmod.__opts__, {'test': True}):
                comt = ('Module {0} is set to be unloaded'.format(name))
                ret.update({'comment': comt})
                self.assertDictEqual(kmod.absent(name), ret)

            with patch.dict(kmod.__opts__, {'test': False}):
                comt = ('Removed kernel module {0}'.format(name))
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        name: 'removed'
                    }
                })
                self.assertDictEqual(kmod.absent(name), ret)

                comt = (
                    'Module {0} is present but failed to remove'.format(name))
                ret.update({
                    'comment': comt,
                    'result': False,
                    'changes': {
                        'A': 'removed'
                    }
                })
                self.assertDictEqual(kmod.absent(name), ret)

            comt = ('Kernel module {0} is already absent'.format(name))
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(kmod.absent(name), ret)
示例#5
0
    def test_absent_multi(self):
        '''
        Test to verify that multiple kernel modules are not loaded.
        '''
        name = 'salted kernel'
        mods = ['cheese', 'crackers']
        ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}

        mock_mod_list = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel modules {0} are set to be removed'.format(
                    ', '.join(mods))
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=mods)
        mock_remove = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {
                'kmod.mod_list': mock_mod_list,
                'kmod.remove': mock_remove
        }):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Removed kernel modules {0}'.format(', '.join(mods))
                ret.update({
                    'comment': comment,
                    'result': True,
                    'changes': {
                        mods[0]: 'removed',
                        mods[1]: 'removed'
                    }
                })
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=[])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel modules {0} are already removed'.format(
                    ', '.join(mods))
                ret.update({'comment': comment, 'result': True, 'changes': {}})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)
示例#6
0
    def test_absent_multi(self):
        '''
        Test to verify that multiple kernel modules are not loaded.
        '''
        name = 'salted kernel'
        mods = ['cheese', 'crackers']
        ret = {'name': name,
               'result': True,
               'comment': '',
               'changes': {}}

        mock_mod_list = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel modules {0} are set to be removed'.format(', '.join(mods))
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=mods)
        mock_remove = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.remove': mock_remove}):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Removed kernel modules {0}'.format(', '.join(mods))
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {mods[0]: 'removed',
                                        mods[1]: 'removed'}})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=[])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel modules {0} are already removed'.format(', '.join(mods))
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {}})
                self.assertDictEqual(kmod.absent(name, mods=mods), ret)
示例#7
0
    def test_absent(self):
        '''
        Test to verify that the named kernel module is not loaded.
        '''
        name = 'cheese'
        ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}

        mock_mod_list = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel module {0} is set to be removed'.format(name)
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.absent(name), ret)

        mock_mod_list = MagicMock(return_value=[name])
        mock_remove = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {
                'kmod.mod_list': mock_mod_list,
                'kmod.remove': mock_remove
        }):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Removed kernel module {0}'.format(name)
                ret.update({
                    'comment': comment,
                    'result': True,
                    'changes': {
                        name: 'removed'
                    }
                })
                self.assertDictEqual(kmod.absent(name), ret)

        mock_mod_list = MagicMock(return_value=[])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel module {0} is already removed'.format(name)
                ret.update({'comment': comment, 'result': True, 'changes': {}})
                self.assertDictEqual(kmod.absent(name), ret)
示例#8
0
def test_absent():
    """
    Test to verify that the named kernel module is not loaded.
    """
    name = "cheese"
    ret = {"name": name, "result": True, "comment": "", "changes": {}}

    mock_mod_list = MagicMock(return_value=[name])
    with patch.dict(kmod.__salt__, {"kmod.mod_list": mock_mod_list}):
        with patch.dict(kmod.__opts__, {"test": True}):
            comment = "Kernel module {} is set to be removed".format(name)
            ret.update({"comment": comment, "result": None})
            assert kmod.absent(name) == ret

    mock_mod_list = MagicMock(return_value=[name])
    mock_remove = MagicMock(return_value=[name])
    with patch.dict(kmod.__salt__, {
            "kmod.mod_list": mock_mod_list,
            "kmod.remove": mock_remove
    }):
        with patch.dict(kmod.__opts__, {"test": False}):
            comment = "Removed kernel module {}".format(name)
            ret.update({
                "comment": comment,
                "result": True,
                "changes": {
                    name: "removed"
                }
            })
            assert kmod.absent(name) == ret

    mock_mod_list = MagicMock(return_value=[])
    with patch.dict(kmod.__salt__, {"kmod.mod_list": mock_mod_list}):
        with patch.dict(kmod.__opts__, {"test": True}):
            comment = "Kernel module {} is already removed".format(name)
            ret.update({"comment": comment, "result": True, "changes": {}})
            assert kmod.absent(name) == ret
示例#9
0
    def test_absent(self):
        '''
        Test to verify that the named kernel module is not loaded.
        '''
        name = 'cheese'
        ret = {'name': name,
               'result': True,
               'comment': '',
               'changes': {}}

        mock_mod_list = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel module {0} is set to be removed'.format(name)
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.absent(name), ret)

        mock_mod_list = MagicMock(return_value=[name])
        mock_remove = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.remove': mock_remove}):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Removed kernel module {0}'.format(name)
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {name: 'removed'}})
                self.assertDictEqual(kmod.absent(name), ret)

        mock_mod_list = MagicMock(return_value=[])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list}):
            with patch.dict(kmod.__opts__, {'test': True}):
                comment = 'Kernel module {0} is already removed'.format(name)
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {}})
                self.assertDictEqual(kmod.absent(name), ret)