示例#1
0
    def test_empty_configuration(self):
        '''Confirms that we properly handle no configuration data on an interface'''
        # The interface has just been created as part of setup, there shouldn't be any IPs
        interface_cfg = NetworkInterfaceConfig('dummy0')

        if interface_cfg.get_ips():
            self.fail("dummy configuration returned an IP!")
示例#2
0
 def test_add_ipv6(self):
     '''Adds an IPv6 address and then confirms it'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     interface_cfg.add_v6_ip('fd00:a3b1:78a2::1', 64)
     ips = interface_cfg.get_ips()
     self.assertEqual(len(ips), 1, "dummy interface either didn't get the IP or has multiple!")
     self.assertEqual(ips[0]['ip_address'], 'fd00:a3b1:78a2::1', "IP assignment failure!")
     self.assertEqual(ips[0]['family'], AF_INET6, "IP assignment failure!")
     self.assertEqual(ips[0]['prefix_length'], 64, "IP assignment failure!")
示例#3
0
    def test_duplicate_ip_failure(self):
        '''Tests duplicate address protection'''
        interface_cfg = NetworkInterfaceConfig('dummy0')
        interface_cfg.add_v4_ip(ip_address='10.0.241.123',
                                prefix_length=24)

        with self.assertRaises(DuplicateIPError):
            interface_cfg.add_v4_ip(ip_address='10.0.241.123',
                                    prefix_length=24)
示例#4
0
    def test_add_ipv4(self):
        '''Adds an IPv4 address, and then confirms it via get_ips()'''
        interface_cfg = NetworkInterfaceConfig('dummy0')

        interface_cfg.add_v4_ip(ip_address='10.0.241.123',
                                prefix_length=24)

        # Retrieve the IPs on the interface and make sure its the only one
        # plus that it is the correct IP
        ips = interface_cfg.get_ips()
        self.assertEqual(len(ips), 1, "dummy interface either didn't get the IP or has multiple!")
        self.assertEqual(ips[0]['ip_address'], '10.0.241.123', "IP assignment failure!")
        self.assertEqual(ips[0]['family'], AF_INET)
        self.assertEqual(ips[0]['broadcast'], '10.0.241.255', "IP assignment failure!")
        self.assertEqual(ips[0]['prefix_length'], 24, "IP assignment failure!")
示例#5
0
    def test_remove_ipv6(self):
        '''Removes an IPv6 address and confirms it'''
        interface_cfg = NetworkInterfaceConfig('dummy0')
        interface_cfg.add_v6_ip('fd00:a3b1:78a2::1', 64)
        interface_cfg.remove_ip('fd00:a3b1:78a2::1')

        if interface_cfg.get_ips():
            self.fail("dummy configuration returned an IP!")
示例#6
0
    def test_remove_ipv4(self):
        '''Tests interface deconfiguration of v4 addresses'''
        interface_cfg = NetworkInterfaceConfig('dummy0')
        interface_cfg.add_v4_ip(ip_address='10.0.241.123',
                                prefix_length=24)

        # Now remove the IP
        interface_cfg.remove_ip('10.0.241.123')

        # And make sure its gone
        if interface_cfg.get_ips():
            self.fail("dummy configuration returned an IP!")
示例#7
0
 def test_check_for_nonexistent_ip(self):
     '''Tests IPNotFound response when getting information for a specific IP'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(IPNotFound):
         interface_cfg.get_full_ip_info("10.0.21.123")
示例#8
0
 def test_ipv6_reserved_reject(self):
     '''Rejects if the IP is in reserved address space'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v6_ip(ip_address='dead:beef::',
                                 prefix_length=64)
示例#9
0
 def test_network_address_rejection(self):
     '''Prefixes >/24 require a dedicated network address that can't be used as an IP'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='192.168.1.192',
                                 prefix_length=26)
示例#10
0
 def test_ipv6_loopback_address_reject(self):
     '''Rejects if we try to assign loopback'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v6_ip(ip_address='::1',
                                 prefix_length=128)
示例#11
0
 def test_ipv4_link_local_rejection(self):
     '''Reject if we try to use a link-local address'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='169.254.1.1',
                                 prefix_length=24)
示例#12
0
 def test_ipv4_class_e_rejection(self):
     '''Reject if we try to use a class E address'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='240.0.0.1',
                                 prefix_length=24)
示例#13
0
 def test_ipv4_multicast_rejection(self):
     '''Reject if we try to assign a multicast address'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='224.0.0.1',
                                 prefix_length=24)
示例#14
0
 def test_ipv4_loopback_address_rejection(self):
     '''Rejects if we try using a loopback address'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='127.0.1.2',
                                 prefix_length=24)
示例#15
0
 def test_broadcast_address_rejection(self):
     '''Rejects if we try using a broadcast address of a prefix'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='192.168.1.191',
                                 prefix_length=26)
示例#16
0
 def test_ipv6_multicast_reject(self):
     '''Rejects if address is IPv6 multicast'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v6_ip(ip_address="ff05::1:3",
                                 prefix_length=128)
示例#17
0
 def test_invalid_ip_check(self):
     '''Makes sure we raise ValueError on if we pass in an invalid IP'''
     interface_cfg = NetworkInterfaceConfig('dummy0')
     with self.assertRaises(ValueError):
         interface_cfg.add_v4_ip(ip_address='ImNotAnIP!',
                                 prefix_length=1337)