Example #1
0
 def _get_ips_from_subnet(self, **kwargs):
     subnet = self.create_subnet(self.network, **kwargs)
     port_mac = data_utils.rand_mac_address()
     port = self.create_port(self.network, mac_address=port_mac)
     real_ip = next(iter(port['fixed_ips']), None)['ip_address']
     eui_ip = data_utils.get_ipv6_addr_by_EUI64(subnet['cidr'],
                                                port_mac).format()
     return real_ip, eui_ip
Example #2
0
 def _get_ips_from_subnet(self, **kwargs):
     subnet = self.create_subnet(self.network, **kwargs)
     port_mac = data_utils.rand_mac_address()
     port = self.create_port(self.network, mac_address=port_mac)
     real_ip = next(iter(port['fixed_ips']), None)['ip_address']
     eui_ip = data_utils.get_ipv6_addr_by_EUI64(subnet['cidr'],
                                                port_mac).format()
     return real_ip, eui_ip
Example #3
0
 def test_dhcpv6_two_subnets(self):
     """When one IPv6 subnet configured with IPv6 SLAAC or DHCPv6 stateless
     and other IPv6 is with DHCPv6 stateful, port shall receive EUI-64 IP
     addresses from first subnet and DHCPv6 address from second one.
     Order of subnet creating should be unimportant.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
                 ('slaac', 'slaac'),
                 ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {'ipv6_ra_mode': ra_mode,
                       'ipv6_address_mode': add_mode}
             kwargs_dhcp = {'ipv6_address_mode': 'dhcpv6-stateful'}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(
                     self.network, **kwargs_dhcp)
             else:
                 subnet_dhcp = self.create_subnet(
                     self.network, **kwargs_dhcp)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             dhcp_ip = subnet_dhcp["allocation_pools"][0]["start"]
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'],
                 port_mac
             ).format()
             # TODO(sergsh): remove this when 1219795 is fixed
             dhcp_ip = [dhcp_ip, (netaddr.IPAddress(dhcp_ip) + 1).format()]
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [real_ips[sub['id']]
                                          for sub in subnet_dhcp,
                                          subnet_slaac]
             self.client.delete_port(port['id'])
             self.ports.pop()
             body = self.client.list_ports()
             ports_id_list = [i['id'] for i in body['ports']]
             self.assertNotIn(port['id'], ports_id_list)
             self._clean_network()
             self.assertEqual(real_eui_ip,
                              eui_ip,
                              'Real IP is {0}, but shall be {1}'.format(
                                  real_eui_ip,
                                  eui_ip))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip,
                     str(dhcp_ip)))
Example #4
0
 def test_dhcpv6_64_subnets(self):
     """When a Network contains two subnets, one being an IPv6 subnet
     configured with ipv6_ra_mode either as slaac or dhcpv6-stateless,
     and the other subnet being an IPv4 subnet, a port attached to the
     network shall receive IP addresses from the subnets as follows: An
     IPv6 address calculated using EUI-64 from the first subnet, and an
     IPv4 address from the second subnet. The ordering of the subnets
     that the port is associated with should not affect this behavior.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
                 ('slaac', 'slaac'),
                 ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {'ipv6_ra_mode': ra_mode,
                       'ipv6_address_mode': add_mode}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(
                     self.network, ip_version=4)
             else:
                 subnet_dhcp = self.create_subnet(
                     self.network, ip_version=4)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             dhcp_ip = subnet_dhcp["allocation_pools"][0]["start"]
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'],
                 port_mac
             ).format()
             # TODO(sergsh): remove this when 1219795 is fixed
             dhcp_ip = [dhcp_ip, (netaddr.IPAddress(dhcp_ip) + 1).format()]
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [real_ips[sub['id']]
                                          for sub in subnet_dhcp,
                                          subnet_slaac]
             self._clean_network()
             self.assertTrue({real_eui_ip,
                              real_dhcp_ip}.issubset([eui_ip] + dhcp_ip))
             self.assertEqual(real_eui_ip,
                              eui_ip,
                              'Real IP is {0}, but shall be {1}'.format(
                                  real_eui_ip,
                                  eui_ip))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip,
                     str(dhcp_ip)))
Example #5
0
 def test_dhcpv6_two_subnets(self):
     """When one IPv6 subnet configured with IPv6 SLAAC or DHCPv6 stateless
     and other IPv6 is with DHCPv6 stateful, port shall receive EUI-64 IP
     addresses from first subnet and DHCPv6 address from second one.
     Order of subnet creating should be unimportant.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
             ('slaac', 'slaac'),
             ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {
                 'ipv6_ra_mode': ra_mode,
                 'ipv6_address_mode': add_mode
             }
             kwargs_dhcp = {'ipv6_address_mode': 'dhcpv6-stateful'}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(self.network,
                                                  **kwargs_dhcp)
             else:
                 subnet_dhcp = self.create_subnet(self.network,
                                                  **kwargs_dhcp)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             dhcp_ip = subnet_dhcp["allocation_pools"][0]["start"]
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'], port_mac).format()
             # TODO(sergsh): remove this when 1219795 is fixed
             dhcp_ip = [dhcp_ip, (netaddr.IPAddress(dhcp_ip) + 1).format()]
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [
                 real_ips[sub['id']] for sub in subnet_dhcp, subnet_slaac
             ]
             self.client.delete_port(port['id'])
             self.ports.pop()
             body = self.client.list_ports()
             ports_id_list = [i['id'] for i in body['ports']]
             self.assertNotIn(port['id'], ports_id_list)
             self._clean_network()
             self.assertEqual(
                 real_eui_ip, eui_ip,
                 'Real IP is {0}, but shall be {1}'.format(
                     real_eui_ip, eui_ip))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip, str(dhcp_ip)))
Example #6
0
 def test_dhcpv6_64_subnets(self):
     """When a Network contains two subnets, one being an IPv6 subnet
     configured with ipv6_ra_mode either as slaac or dhcpv6-stateless,
     and the other subnet being an IPv4 subnet, a port attached to the
     network shall receive IP addresses from the subnets as follows: An
     IPv6 address calculated using EUI-64 from the first subnet, and an
     IPv4 address from the second subnet. The ordering of the subnets
     that the port is associated with should not affect this behavior.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
             ('slaac', 'slaac'),
             ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {
                 'ipv6_ra_mode': ra_mode,
                 'ipv6_address_mode': add_mode
             }
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(self.network,
                                                  ip_version=4)
             else:
                 subnet_dhcp = self.create_subnet(self.network,
                                                  ip_version=4)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             dhcp_ip = subnet_dhcp["allocation_pools"][0]["start"]
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'], port_mac).format()
             # TODO(sergsh): remove this when 1219795 is fixed
             dhcp_ip = [dhcp_ip, (netaddr.IPAddress(dhcp_ip) + 1).format()]
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [
                 real_ips[sub['id']] for sub in subnet_dhcp, subnet_slaac
             ]
             self._clean_network()
             self.assertTrue({real_eui_ip,
                              real_dhcp_ip}.issubset([eui_ip] + dhcp_ip))
             self.assertEqual(
                 real_eui_ip, eui_ip,
                 'Real IP is {0}, but shall be {1}'.format(
                     real_eui_ip, eui_ip))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip, str(dhcp_ip)))
Example #7
0
 def test_dhcpv6_two_subnets(self):
     # NOTE: When one IPv6 subnet configured with dnsmasq SLAAC or DHCP
     # stateless and other IPv6 is with DHCP stateful, port shall receive
     # EUI-64 IP addresses from first subnet and DHCP address from second
     # one. Order of subnet creating should be unimportant.
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
             ('slaac', 'slaac'),
             ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {
                 'ipv6_ra_mode': ra_mode,
                 'ipv6_address_mode': add_mode
             }
             kwargs_dhcp = {'ipv6_address_mode': 'dhcpv6-stateful'}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(self.network,
                                                  **kwargs_dhcp)
             else:
                 subnet_dhcp = self.create_subnet(self.network,
                                                  **kwargs_dhcp)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'], port_mac).format()
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [
                 real_ips[sub['id']] for sub in [subnet_dhcp, subnet_slaac]
             ]
             self.ports_client.delete_port(port['id'])
             self.ports.pop()
             body = self.ports_client.list_ports()
             ports_id_list = [i['id'] for i in body['ports']]
             self.assertNotIn(port['id'], ports_id_list)
             self._clean_network()
             self.assertEqual(
                 real_eui_ip, eui_ip,
                 'Real IP is {0}, but shall be {1}'.format(
                     real_eui_ip, eui_ip))
             msg = ('Real IP address is {0} and it is NOT on '
                    'subnet {1}'.format(real_dhcp_ip, subnet_dhcp['cidr']))
             self.assertIn(netaddr.IPAddress(real_dhcp_ip),
                           netaddr.IPNetwork(subnet_dhcp['cidr']), msg)
Example #8
0
 def test_get_ipv6_addr_by_EUI64(self):
     actual = data_utils.get_ipv6_addr_by_EUI64('2001:db8::',
                                                '00:16:3e:33:44:55')
     self.assertIsInstance(actual, netaddr.IPAddress)
     self.assertEqual(actual,
                      netaddr.IPAddress('2001:db8::216:3eff:fe33:4455'))
Example #9
0
 def test_get_ipv6_addr_by_EUI64(self):
     actual = data_utils.get_ipv6_addr_by_EUI64('2001:db8::',
                                                '00:16:3e:33:44:55')
     self.assertIsInstance(actual, netaddr.IPAddress)
     self.assertEqual(actual,
                      netaddr.IPAddress('2001:db8::216:3eff:fe33:4455'))