Пример #1
0
 def test_dad_for_external(self):
     mgr = ip.IPManager()
     with mock.patch.object(mgr, 'generic_to_host', lambda x: x):
         mgr.disable_duplicate_address_detection(
             models.Network('ABC123',
                            models.Interface('eth1'),
                            network_type=models.Network.TYPE_EXTERNAL))
         assert self.mock_execute.call_count == 0
Пример #2
0
 def fake_get_interface(cls, ifname):
     return models.Interface(
         media="Ethernet autoselect (1000baseT full-duplex,master)",
         state="up",
         ifname="ge1",
         groups=["egress"],
         lladdr="00:0c:29:e8:f9:2e",
         addresses=["fe80::20c:29ff:fee8:f92e/64", "192.168.229.129/24"])
Пример #3
0
    def test_aliases(self):
        addr1 = netaddr.IPNetwork('192.168.1.1/24')
        addr2 = netaddr.IPNetwork('192.168.1.2/24')

        iface = models.Interface(ifname='ge0', addresses=[str(addr1)])
        iface.aliases = [addr2]
        self.assertEqual(iface.addresses, [addr1])
        self.assertEqual(iface.aliases, [addr2])
        self.assertEqual(iface.all_addresses, [addr1, addr2])
Пример #4
0
 def test_to_dict_extended(self):
     iface = models.Interface()
     result = iface.to_dict(True)
     expected = [
         'addresses', 'description', 'groups', 'ifname', 'lladdr', 'media',
         'mtu', 'state', 'flags', 'extra_params'
     ]
     self.assertTrue(isinstance(result, dict))
     self.assertItemsEqual(result.keys(), expected)
Пример #5
0
 def test_dad_for_internal(self):
     mgr = ip.IPManager()
     with mock.patch.object(mgr, 'generic_to_host', lambda x: x):
         mgr.disable_duplicate_address_detection(
             models.Network('ABC123',
                            models.Interface('eth2'),
                            network_type=models.Network.TYPE_INTERNAL))
     assert self.mock_execute.call_count == 1
     assert self.mock_execute.call_args_list == [
         mock.call(['sysctl', '-w', 'net.ipv6.conf.eth2.accept_dad=0'],
                   'sudo'),
     ]
Пример #6
0
 def fake_get_interfaces(cls):
     iface1 = models.Interface(media="null",
                               state="down",
                               ifname="ge0",
                               groups=["enc"],
                               lladdr="null",
                               addresses=[])
     iface2 = models.Interface(
         media="Ethernet autoselect (1000baseT full-duplex,master)",
         state="up",
         ifname="ge1",
         groups=["egress"],
         lladdr="00:0c:29:e8:f9:2e",
         addresses=["fe80::20c:29ff:fee8:f92e/64", "192.168.229.129/24"])
     iface3 = models.Interface(
         media="Ethernet autoselect (1000baseT full-duplex,master)",
         state="up",
         ifname="ge2",
         groups=[],
         lladdr="00:0c:29:e8:f9:38",
         addresses=["192.168.57.101/24", "fe80::20c:29ff:fee8:f938/64"])
     return [iface1, iface2, iface3]
Пример #7
0
    def test_sysctl_failure(self):
        logger = ip.LOG
        logger.level = logging.DEBUG
        buff = StringIO()
        handler = logging.StreamHandler(buff)

        self.mock_execute.side_effect = RuntimeError
        mgr = ip.IPManager()
        with mock.patch.object(mgr, 'generic_to_host', lambda x: x):
            try:
                logger.addHandler(handler)
                mgr.disable_duplicate_address_detection(
                    models.Network(
                        'ABC123',
                        models.Interface('eth0'),
                        network_type=models.Network.TYPE_MANAGEMENT))
                assert 'Failed to disable v6 dad on eth0' in buff.getvalue()
            finally:
                logger.removeHandler(handler)
Пример #8
0
 def test_is_up_flags(self):
     self.assertFalse(models.Interface().is_up)
     iface = models.Interface(flags=['UP'])
     self.assertTrue(iface.is_up)
Пример #9
0
 def test_is_up_extra_params(self):
     self.assertFalse(models.Interface().is_up)
     iface = models.Interface(state='up')
     self.assertTrue(iface.is_up)
Пример #10
0
 def test_description_failure(self):
     iface = models.Interface()
     with self.assertRaises(ValueError):
         iface.description = 'the description'
Пример #11
0
 def test_description(self):
     iface = models.Interface()
     iface.description = 'the_description'
     self.assertEqual('the_description', iface.description)
Пример #12
0
 def test_eq_other_changed_values(self):
     iface = models.Interface(ifname='ge0', addresses=['192.168.1.1/24'])
     iface2 = models.Interface(ifname='ge1', addresses=['192.168.1.2/24'])
     self.assertNotEqual(iface, iface2)
Пример #13
0
 def test_eq_other_same_instance(self):
     iface = models.Interface(ifname='ge0', addresses=['192.168.1.1/24'])
     self.assertEqual(iface, iface)
Пример #14
0
 def test_eq_other_none(self):
     iface = models.Interface(ifname='ge0', addresses=['192.168.1.1/24'])
     self.assertNotEqual(iface, None)
Пример #15
0
 def test_repr(self):
     iface = models.Interface(ifname='ge0', addresses=['192.168.1.1/24'])
     expected = "<Interface: ge0 ['192.168.1.1/24']>"
     self.assertEqual(expected, repr(iface))
Пример #16
0
 def test_ifname(self):
     iface = models.Interface(ifname="em0")
     self.assertEquals(iface.ifname, "em0")