Beispiel #1
0
    def test_routes(self):
        '''
            Test to manage network interface static routes.
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}

        mock = MagicMock(
            side_effect=[AttributeError, False, False, "True", False, False])
        with patch.dict(network.__salt__, {"ip.get_routes": mock}):
            self.assertDictEqual(network.routes('salt'), ret)

            mock = MagicMock(side_effect=[False, True, '', True, True])
            with patch.dict(network.__salt__, {"ip.build_routes": mock}):
                ret.update({
                    'result': True,
                    'comment': 'Interface salt routes are up to date.'
                })
                self.assertDictEqual(network.routes('salt', test='a'), ret)

                ret.update({
                    'comment': 'Interface salt routes are'
                    ' set to be added.',
                    'result': None
                })
                self.assertDictEqual(network.routes('salt', test='a'), ret)

                ret.update({
                    'comment':
                    'Interface salt routes are set to be'
                    ' updated:\n--- \n+++ \n@@ -1,4 +0,0 @@\n-T\n-r'
                    '\n-u\n-e'
                })
                self.assertDictEqual(network.routes('salt', test='a'), ret)

                mock = MagicMock(side_effect=[AttributeError, True])
                with patch.dict(network.__salt__,
                                {"ip.apply_network_settings": mock}):
                    ret.update({
                        'changes': {
                            'network_routes': 'Added interface salt routes.'
                        },
                        'comment': '',
                        'result': False
                    })
                    self.assertDictEqual(network.routes('salt'), ret)

                    ret.update({
                        'changes': {
                            'network_routes': 'Added interface salt routes.'
                        },
                        'comment': 'Interface salt routes added.',
                        'result': True
                    })
                    self.assertDictEqual(network.routes('salt'), ret)
Beispiel #2
0
    def test_routes(self):
        """
            Test to manage network interface static routes.
        """
        ret = {"name": "salt", "changes": {}, "result": False, "comment": ""}

        mock = MagicMock(
            side_effect=[AttributeError, False, False, "True", False, False])
        with patch.dict(network.__salt__, {"ip.get_routes": mock}):
            self.assertDictEqual(network.routes("salt"), ret)

            mock = MagicMock(side_effect=[False, True, "", True, True])
            with patch.dict(network.__salt__, {"ip.build_routes": mock}):
                ret.update({
                    "result": True,
                    "comment": "Interface salt routes are up to date."
                })
                self.assertDictEqual(network.routes("salt", test="a"), ret)

                ret.update({
                    "comment": "Interface salt routes are"
                    " set to be added.",
                    "result": None,
                })
                self.assertDictEqual(network.routes("salt", test="a"), ret)

                ret.update({
                    "comment":
                    "Interface salt routes are set to be"
                    " updated:\n--- \n+++ \n@@ -1,4 +0,0 @@\n-T\n-r"
                    "\n-u\n-e"
                })
                self.assertDictEqual(network.routes("salt", test="a"), ret)

                mock = MagicMock(side_effect=[AttributeError, True])
                with patch.dict(network.__salt__,
                                {"ip.apply_network_settings": mock}):
                    ret.update({
                        "changes": {
                            "network_routes": "Added interface salt routes."
                        },
                        "comment": "",
                        "result": False,
                    })
                    self.assertDictEqual(network.routes("salt"), ret)

                    ret.update({
                        "changes": {
                            "network_routes": "Added interface salt routes."
                        },
                        "comment": "Interface salt routes added.",
                        "result": True,
                    })
                    self.assertDictEqual(network.routes("salt"), ret)