Example #1
0
    def test_present(self):
        '''
        Test to ensure that the specified kernel module is 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}):
            comment = 'Kernel module {0} is already present'.format(name)
            ret.update({'comment': comment})
            self.assertDictEqual(kmod.present(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 set to be loaded'.format(name)
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.present(name), ret)

        mock_mod_list = MagicMock(return_value=[])
        mock_available = MagicMock(return_value=[name])
        mock_load = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.available': mock_available,
                                        'kmod.load': mock_load}):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Loaded kernel module {0}'.format(name)
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {name: 'loaded'}})
                self.assertDictEqual(kmod.present(name), ret)
Example #2
0
    def test_present(self):
        '''
        Test to ensure that the specified kernel module is 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}):
            comment = 'Kernel module {0} is already present'.format(name)
            ret.update({'comment': comment})
            self.assertDictEqual(kmod.present(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 set to be loaded'.format(name)
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.present(name), ret)

        mock_mod_list = MagicMock(return_value=[])
        mock_available = MagicMock(return_value=[name])
        mock_load = MagicMock(return_value=[name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.available': mock_available,
                                        'kmod.load': mock_load}):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Loaded kernel module {0}'.format(name)
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {name: 'loaded'}})
                self.assertDictEqual(kmod.present(name), ret)
Example #3
0
    def test_present_multi(self):
        '''
        Test to ensure that multiple kernel modules are 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}):
            call_ret = kmod.present(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 already present', 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}):
                call_ret = kmod.present(name, mods=mods)
                ret.update({'result': None})

                # 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 loaded', comment)

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

        mock_mod_list = MagicMock(return_value=[])
        mock_available = MagicMock(return_value=mods)
        mock_load = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.available': mock_available,
                                        'kmod.load': mock_load}):
            with patch.dict(kmod.__opts__, {'test': False}):
                call_ret = kmod.present(name, mods=mods)
                ret.update({'result': True,
                            'changes': {mods[0]: 'loaded',
                                        mods[1]: 'loaded'}})

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

                # Assert against all other dictionary key/values
                self.assertDictEqual(ret, call_ret)
Example #4
0
    def test_present_multi(self):
        '''
        Test to ensure that multiple kernel modules are 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}):
            comment = 'Kernel modules {0} are already present'.format(
                ', '.join(mods))
            ret.update({'comment': comment})
            self.assertDictEqual(kmod.present(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 set to be loaded'.format(
                    ', '.join(mods))
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.present(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=[])
        mock_available = MagicMock(return_value=mods)
        mock_load = MagicMock(return_value=mods)
        with patch.dict(
                kmod.__salt__, {
                    'kmod.mod_list': mock_mod_list,
                    'kmod.available': mock_available,
                    'kmod.load': mock_load
                }):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Loaded kernel modules {0}'.format(', '.join(mods))
                ret.update({
                    'comment': comment,
                    'result': True,
                    'changes': {
                        mods[0]: 'loaded',
                        mods[1]: 'loaded'
                    }
                })
                self.assertDictEqual(kmod.present(name, mods=mods), ret)
Example #5
0
    def test_present(self):
        '''
        Test to ensure that the specified kernel module is loaded.
        '''
        name = 'kvm_amd'

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

        mock = MagicMock(
            side_effect=[[name], [], [], [], [], [name], [], [name]])
        mock_t = MagicMock(side_effect=[[name], name])
        with patch.dict(kmod.__salt__, {
                'kmod.mod_list': mock,
                'kmod.available': mock,
                'kmod.load': mock_t
        }):
            comt = ('Kernel module {0} is already present'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(kmod.present(name), ret)

            with patch.dict(kmod.__opts__, {'test': True}):
                comt = ('Module {0} is set to be loaded'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(kmod.present(name), ret)

            with patch.dict(kmod.__opts__, {'test': False}):
                comt = ('Kernel module {0} is unavailable'.format(name))
                ret.update({'comment': comt, 'result': False})
                self.assertDictEqual(kmod.present(name), ret)

                comt = ('Loaded kernel module {0}'.format(name))
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        'kvm_amd': 'loaded'
                    }
                })
                self.assertDictEqual(kmod.present(name), ret)

                comt = ('Loaded kernel module {0}'.format(name))
                ret.update({'comment': name, 'changes': {}, 'result': False})
                self.assertDictEqual(kmod.present(name), ret)
Example #6
0
def test_present():
    """
    Test to ensure that the specified kernel module is 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}):
        comment = "Kernel module {} is already present".format(name)
        ret.update({"comment": comment})
        assert kmod.present(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 set to be loaded".format(name)
            ret.update({"comment": comment, "result": None})
            assert kmod.present(name) == ret

    mock_mod_list = MagicMock(return_value=[])
    mock_available = MagicMock(return_value=[name])
    mock_load = MagicMock(return_value=[name])
    with patch.dict(
            kmod.__salt__,
        {
            "kmod.mod_list": mock_mod_list,
            "kmod.available": mock_available,
            "kmod.load": mock_load,
        },
    ):
        with patch.dict(kmod.__opts__, {"test": False}):
            comment = "Loaded kernel module {}".format(name)
            ret.update({
                "comment": comment,
                "result": True,
                "changes": {
                    name: "loaded"
                }
            })
            assert kmod.present(name) == ret
Example #7
0
    def test_present(self):
        '''
        Test to ensure that the specified kernel module is loaded.
        '''
        name = 'kvm_amd'

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

        mock = MagicMock(side_effect=[[name], [], [], [], [], [name], [],
                                      [name]])
        mock_t = MagicMock(side_effect=[[name], name])
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock,
                                        'kmod.available': mock,
                                        'kmod.load': mock_t}):
            comt = ('Kernel module {0} is already present'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(kmod.present(name), ret)

            with patch.dict(kmod.__opts__, {'test': True}):
                comt = ('Module {0} is set to be loaded'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(kmod.present(name), ret)

            with patch.dict(kmod.__opts__, {'test': False}):
                comt = ('Kernel module {0} is unavailable'.format(name))
                ret.update({'comment': comt, 'result': False})
                self.assertDictEqual(kmod.present(name), ret)

                comt = ('Loaded kernel module {0}'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'kvm_amd': 'loaded'}})
                self.assertDictEqual(kmod.present(name), ret)

                comt = ('Loaded kernel module {0}'.format(name))
                ret.update({'comment': name, 'changes': {}, 'result': False})
                self.assertDictEqual(kmod.present(name), ret)
Example #8
0
    def test_present_multi(self):
        '''
        Test to ensure that multiple kernel modules are 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}):
            comment = 'Kernel modules {0} are already present'.format(', '.join(mods))
            ret.update({'comment': comment})
            self.assertDictEqual(kmod.present(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 set to be loaded'.format(', '.join(mods))
                ret.update({'comment': comment, 'result': None})
                self.assertDictEqual(kmod.present(name, mods=mods), ret)

        mock_mod_list = MagicMock(return_value=[])
        mock_available = MagicMock(return_value=mods)
        mock_load = MagicMock(return_value=mods)
        with patch.dict(kmod.__salt__, {'kmod.mod_list': mock_mod_list,
                                        'kmod.available': mock_available,
                                        'kmod.load': mock_load}):
            with patch.dict(kmod.__opts__, {'test': False}):
                comment = 'Loaded kernel modules {0}'.format(', '.join(mods))
                ret.update({'comment': comment,
                            'result': True,
                            'changes': {mods[0]: 'loaded',
                                        mods[1]: 'loaded'}})
                self.assertDictEqual(kmod.present(name, mods=mods), ret)
Example #9
0
def test_present_multi():
    """
    Test to ensure that multiple kernel modules are 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}):
        call_ret = kmod.present(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 already present" 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}):
            call_ret = kmod.present(name, mods=mods)
            ret.update({"result": None})

            # 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 loaded" in comment

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

    mock_mod_list = MagicMock(return_value=[])
    mock_available = MagicMock(return_value=mods)
    mock_load = MagicMock(return_value=mods)
    with patch.dict(
            kmod.__salt__,
        {
            "kmod.mod_list": mock_mod_list,
            "kmod.available": mock_available,
            "kmod.load": mock_load,
        },
    ):
        with patch.dict(kmod.__opts__, {"test": False}):
            call_ret = kmod.present(name, mods=mods)
            ret.update({
                "result": True,
                "changes": {
                    mods[0]: "loaded",
                    mods[1]: "loaded"
                }
            })

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

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