Beispiel #1
0
    def test_eth0_override(self):
        self.maxDiff = None
        context = {
            'DNS': '1.2.3.8',
            'ETH0_DNS': '1.2.3.6 1.2.3.7',
            'ETH0_GATEWAY': '1.2.3.5',
            'ETH0_GATEWAY6': '',
            'ETH0_IP': IP_BY_MACADDR,
            'ETH0_IP6': '',
            'ETH0_IP6_PREFIX_LENGTH': '',
            'ETH0_IP6_ULA': '',
            'ETH0_MAC': '02:00:0a:12:01:01',
            'ETH0_MASK': '255.255.0.0',
            'ETH0_MTU': '',
            'ETH0_NETWORK': '10.18.0.0',
            'ETH0_SEARCH_DOMAIN': '',
        }
        for nic in self.system_nics:
            net = ds.OpenNebulaNetwork(context,
                                       mock.Mock(),
                                       system_nics_by_mac={MACADDR: nic})
            expected = {
                'version': 2,
                'ethernets': {
                    nic: {
                        'match': {
                            'macaddress': MACADDR
                        },
                        'addresses': [IP_BY_MACADDR + '/16'],
                        'gateway4': '1.2.3.5',
                        'nameservers': {
                            'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8']
                        }
                    }
                }
            }

            self.assertEqual(expected, net.gen_conf())
Beispiel #2
0
    def test_eth0_override(self):
        self.maxDiff = None
        context = {
            "DNS": "1.2.3.8",
            "ETH0_DNS": "1.2.3.6 1.2.3.7",
            "ETH0_GATEWAY": "1.2.3.5",
            "ETH0_GATEWAY6": "",
            "ETH0_IP": IP_BY_MACADDR,
            "ETH0_IP6": "",
            "ETH0_IP6_PREFIX_LENGTH": "",
            "ETH0_IP6_ULA": "",
            "ETH0_MAC": "02:00:0a:12:01:01",
            "ETH0_MASK": "255.255.0.0",
            "ETH0_MTU": "",
            "ETH0_NETWORK": "10.18.0.0",
            "ETH0_SEARCH_DOMAIN": "",
        }
        for nic in self.system_nics:
            net = ds.OpenNebulaNetwork(
                context, mock.Mock(), system_nics_by_mac={MACADDR: nic}
            )
            expected = {
                "version": 2,
                "ethernets": {
                    nic: {
                        "match": {"macaddress": MACADDR},
                        "addresses": [IP_BY_MACADDR + "/16"],
                        "gateway4": "1.2.3.5",
                        "nameservers": {
                            "addresses": ["1.2.3.6", "1.2.3.7", "1.2.3.8"]
                        },
                    }
                },
            }

            self.assertEqual(expected, net.gen_conf())
Beispiel #3
0
    def test_multiple_nics(self):
        """Test rendering multiple nics with names that differ from context."""
        self.maxDiff = None
        MAC_1 = "02:00:0a:12:01:01"
        MAC_2 = "02:00:0a:12:01:02"
        context = {
            'DNS': '1.2.3.8',
            'ETH0_DNS': '1.2.3.6 1.2.3.7',
            'ETH0_GATEWAY': '1.2.3.5',
            'ETH0_GATEWAY6': IP6_GW,
            'ETH0_IP': '10.18.1.1',
            'ETH0_IP6': IP6_GLOBAL,
            'ETH0_IP6_PREFIX_LENGTH': '',
            'ETH0_IP6_ULA': IP6_ULA,
            'ETH0_MAC': MAC_2,
            'ETH0_MASK': '255.255.0.0',
            'ETH0_MTU': '1280',
            'ETH0_NETWORK': '10.18.0.0',
            'ETH0_SEARCH_DOMAIN': 'example.com',
            'ETH3_DNS': '10.3.1.2',
            'ETH3_GATEWAY': '10.3.0.1',
            'ETH3_GATEWAY6': '',
            'ETH3_IP': '10.3.1.3',
            'ETH3_IP6': '',
            'ETH3_IP6_PREFIX_LENGTH': '',
            'ETH3_IP6_ULA': '',
            'ETH3_MAC': MAC_1,
            'ETH3_MASK': '255.255.0.0',
            'ETH3_MTU': '',
            'ETH3_NETWORK': '10.3.0.0',
            'ETH3_SEARCH_DOMAIN': 'third.example.com third.example.org',
        }
        net = ds.OpenNebulaNetwork(context,
                                   mock.Mock(),
                                   system_nics_by_mac={
                                       MAC_1: 'enp0s25',
                                       MAC_2: 'enp1s2'
                                   })

        expected = {
            'version': 2,
            'ethernets': {
                'enp1s2': {
                    'match': {
                        'macaddress': MAC_2
                    },
                    'addresses':
                    ['10.18.1.1/16', IP6_GLOBAL + '/64', IP6_ULA + '/64'],
                    'gateway4':
                    '1.2.3.5',
                    'gateway6':
                    IP6_GW,
                    'nameservers': {
                        'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8'],
                        'search': ['example.com']
                    },
                    'mtu':
                    '1280'
                },
                'enp0s25': {
                    'match': {
                        'macaddress': MAC_1
                    },
                    'addresses': ['10.3.1.3/16'],
                    'gateway4': '10.3.0.1',
                    'nameservers': {
                        'addresses': ['10.3.1.2', '1.2.3.8'],
                        'search': ['third.example.com', 'third.example.org']
                    }
                }
            }
        }

        self.assertEqual(expected, net.gen_conf())
Beispiel #4
0
 def test_distro_passed_through(self, m_get_physical_nics_by_mac):
     ds.OpenNebulaNetwork({}, mock.sentinel.distro)
     self.assertEqual(
         [mock.call(mock.sentinel.distro)],
         m_get_physical_nics_by_mac.call_args_list,
     )
Beispiel #5
0
 def test_get_ip(self):
     """Verify get_ip('device') correctly returns IPv4 address."""
     context = {'ETH0_IP': PUBLIC_IP}
     net = ds.OpenNebulaNetwork(context, mock.Mock())
     val = net.get_ip('eth0', MACADDR)
     self.assertEqual(PUBLIC_IP, val)
Beispiel #6
0
 def test_get_mtu(self):
     """Verify get_mtu('device') correctly returns MTU size."""
     context = {'ETH0_MTU': '1280'}
     net = ds.OpenNebulaNetwork(context, mock.Mock())
     val = net.get_mtu('eth0')
     self.assertEqual('1280', val)
Beispiel #7
0
    def test_multiple_nics(self):
        """Test rendering multiple nics with names that differ from context."""
        self.maxDiff = None
        MAC_1 = "02:00:0a:12:01:01"
        MAC_2 = "02:00:0a:12:01:02"
        context = {
            "DNS": "1.2.3.8",
            "ETH0_DNS": "1.2.3.6 1.2.3.7",
            "ETH0_GATEWAY": "1.2.3.5",
            "ETH0_GATEWAY6": IP6_GW,
            "ETH0_IP": "10.18.1.1",
            "ETH0_IP6": IP6_GLOBAL,
            "ETH0_IP6_PREFIX_LENGTH": "",
            "ETH0_IP6_ULA": IP6_ULA,
            "ETH0_MAC": MAC_2,
            "ETH0_MASK": "255.255.0.0",
            "ETH0_MTU": "1280",
            "ETH0_NETWORK": "10.18.0.0",
            "ETH0_SEARCH_DOMAIN": "example.com",
            "ETH3_DNS": "10.3.1.2",
            "ETH3_GATEWAY": "10.3.0.1",
            "ETH3_GATEWAY6": "",
            "ETH3_IP": "10.3.1.3",
            "ETH3_IP6": "",
            "ETH3_IP6_PREFIX_LENGTH": "",
            "ETH3_IP6_ULA": "",
            "ETH3_MAC": MAC_1,
            "ETH3_MASK": "255.255.0.0",
            "ETH3_MTU": "",
            "ETH3_NETWORK": "10.3.0.0",
            "ETH3_SEARCH_DOMAIN": "third.example.com third.example.org",
        }
        net = ds.OpenNebulaNetwork(
            context,
            mock.Mock(),
            system_nics_by_mac={MAC_1: "enp0s25", MAC_2: "enp1s2"},
        )

        expected = {
            "version": 2,
            "ethernets": {
                "enp1s2": {
                    "match": {"macaddress": MAC_2},
                    "addresses": [
                        "10.18.1.1/16",
                        IP6_GLOBAL + "/64",
                        IP6_ULA + "/64",
                    ],
                    "gateway4": "1.2.3.5",
                    "gateway6": IP6_GW,
                    "nameservers": {
                        "addresses": ["1.2.3.6", "1.2.3.7", "1.2.3.8"],
                        "search": ["example.com"],
                    },
                    "mtu": "1280",
                },
                "enp0s25": {
                    "match": {"macaddress": MAC_1},
                    "addresses": ["10.3.1.3/16"],
                    "gateway4": "10.3.0.1",
                    "nameservers": {
                        "addresses": ["10.3.1.2", "1.2.3.8"],
                        "search": ["third.example.com", "third.example.org"],
                    },
                },
            },
        }

        self.assertEqual(expected, net.gen_conf())
Beispiel #8
0
 def test_get_mtu(self):
     """Verify get_mtu('device') correctly returns MTU size."""
     context = {"ETH0_MTU": "1280"}
     net = ds.OpenNebulaNetwork(context, mock.Mock())
     val = net.get_mtu("eth0")
     self.assertEqual("1280", val)
Beispiel #9
0
    def test_lo(self):
        net = ds.OpenNebulaNetwork(context={}, system_nics_by_mac={})
        self.assertEqual(net.gen_conf(), u'''\
auto lo
iface lo inet loopback
''')
    def test_lo(self):
        net = ds.OpenNebulaNetwork('', {})
        self.assertEqual(net.gen_conf(), u'''\
auto lo
iface lo inet loopback
''')