Exemplo n.º 1
0
    def test_latest_active_with_changes(self):
        '''
        Test - latest_active when a new kernel is available
        '''
        reboot = MagicMock(return_value=True)
        latest = MagicMock(return_value=1)
        with patch.dict(
                kernelpkg.__salt__, {'kernelpkg.needs_reboot': reboot,
                                     'kernelpkg.latest_installed': latest}), \
                patch.dict(kernelpkg.__opts__, {'test': False}):
            kernelpkg.__salt__['system.reboot'].reset_mock()
            ret = kernelpkg.latest_active(name=STATE_NAME)
            self.assertEqual(ret['name'], STATE_NAME)
            self.assertTrue(ret['result'])
            self.assertIsInstance(ret['changes'], dict)
            self.assertIsInstance(ret['comment'], six.text_type)
            self.assert_called_once(kernelpkg.__salt__['system.reboot'])

            with patch.dict(kernelpkg.__opts__, {'test': True}):
                kernelpkg.__salt__['system.reboot'].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret['name'], STATE_NAME)
                self.assertIsNone(ret['result'])
                self.assertDictEqual(ret['changes'],
                                     {'kernel': {
                                         'new': 1,
                                         'old': 0
                                     }})
                self.assertIsInstance(ret['comment'], six.text_type)
                kernelpkg.__salt__['system.reboot'].assert_not_called()
Exemplo n.º 2
0
    def test_latest_active_with_changes(self):
        """
        Test - latest_active when a new kernel is available
        """
        reboot = MagicMock(return_value=True)
        latest = MagicMock(return_value=1)
        with patch.dict(
                kernelpkg.__salt__,
            {
                "kernelpkg.needs_reboot": reboot,
                "kernelpkg.latest_installed": latest
            },
        ), patch.dict(kernelpkg.__opts__, {"test": False}):
            kernelpkg.__salt__["system.reboot"].reset_mock()
            ret = kernelpkg.latest_active(name=STATE_NAME)
            self.assertEqual(ret["name"], STATE_NAME)
            self.assertTrue(ret["result"])
            self.assertIsInstance(ret["changes"], dict)
            self.assertIsInstance(ret["comment"], six.text_type)
            self.assert_called_once(kernelpkg.__salt__["system.reboot"])

            with patch.dict(kernelpkg.__opts__, {"test": True}):
                kernelpkg.__salt__["system.reboot"].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret["name"], STATE_NAME)
                self.assertIsNone(ret["result"])
                self.assertDictEqual(ret["changes"],
                                     {"kernel": {
                                         "new": 1,
                                         "old": 0
                                     }})
                self.assertIsInstance(ret["comment"], six.text_type)
                kernelpkg.__salt__["system.reboot"].assert_not_called()
Exemplo n.º 3
0
    def test_latest_active_at_latest(self):
        '''
        Test - latest_active when the newest kernel is already active
        '''
        reboot = MagicMock(return_value=False)
        with patch.dict(kernelpkg.__salt__, {'kernelpkg.needs_reboot': reboot}):
            with patch.dict(kernelpkg.__opts__, {'test': False}):
                kernelpkg.__salt__['system.reboot'].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret['name'], STATE_NAME)
                self.assertTrue(ret['result'])
                self.assertDictEqual(ret['changes'], {})
                self.assertIsInstance(ret['comment'], str)
                kernelpkg.__salt__['system.reboot'].assert_not_called()

            with patch.dict(kernelpkg.__opts__, {'test': True}):
                kernelpkg.__salt__['system.reboot'].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret['name'], STATE_NAME)
                self.assertTrue(ret['result'])
                self.assertDictEqual(ret['changes'], {})
                self.assertIsInstance(ret['comment'], str)
                kernelpkg.__salt__['system.reboot'].assert_not_called()
Exemplo n.º 4
0
    def test_latest_active_at_latest(self):
        """
        Test - latest_active when the newest kernel is already active
        """
        reboot = MagicMock(return_value=False)
        with patch.dict(kernelpkg.__salt__,
                        {"kernelpkg.needs_reboot": reboot}):
            with patch.dict(kernelpkg.__opts__, {"test": False}):
                kernelpkg.__salt__["system.reboot"].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret["name"], STATE_NAME)
                self.assertTrue(ret["result"])
                self.assertDictEqual(ret["changes"], {})
                self.assertIsInstance(ret["comment"], six.text_type)
                kernelpkg.__salt__["system.reboot"].assert_not_called()

            with patch.dict(kernelpkg.__opts__, {"test": True}):
                kernelpkg.__salt__["system.reboot"].reset_mock()
                ret = kernelpkg.latest_active(name=STATE_NAME)
                self.assertEqual(ret["name"], STATE_NAME)
                self.assertTrue(ret["result"])
                self.assertDictEqual(ret["changes"], {})
                self.assertIsInstance(ret["comment"], six.text_type)
                kernelpkg.__salt__["system.reboot"].assert_not_called()