def test_get_router_ips_from_ib_network(self): connector = mock.Mock() test_ib_network = ib_objects.NetworkV4(connector, network_view='test-view', cidr='12.12.1.0/24') test_ib_network.options = [ ib_objects.DhcpOption(name='routers', value='192.168.1.1,192.168.1.2')] member_ips = utils.get_router_ips(test_ib_network) self.assertEqual("192.168.1.1", member_ips[0]) self.assertEqual("192.168.1.2", member_ips[1])
def test_get_dhcp_member_ips_from_ib_network(self): connector = mock.Mock() test_ib_network = ib_objects.NetworkV4(connector, network_view='test-view', cidr='12.12.1.0/24') test_ib_network.members = [ ib_objects.AnyMember(_struct='dhcpmember', name='nios-7.2.0-member3.com', ipv4addr='192.168.1.10')] member_ips = utils.get_dhcp_member_ips(test_ib_network) self.assertEqual("192.168.1.10", member_ips[0])
def _test_reserve_service_members_with_ib_network_without_dhcp_member( self, dns_support): user_id = 'test user' tenant_id = '90fbad5a098a4b7cb98826128d5b40b3' # prepare network network_name = 'Test Network' network = self.plugin_stub.create_network(tenant_id, network_name) # prepare subnet subnet_name = 'Test Subnet' subnet_cidr = '11.11.1.0/24' subnet = self.plugin_stub.create_subnet(tenant_id, subnet_name, network['id'], subnet_cidr) self.grid_config.dhcp_support = True self.grid_config.dns_support = dns_support ib_cxt = ib_context.InfobloxContext(self.ctx, user_id, network, subnet, self.grid_config, self.plugin) ib_cxt._register_services = mock.Mock() # ib network with dhcp member and gateway ips assigned connector = mock.Mock() test_ib_network = ib_objects.NetworkV4(connector, network_view='test-view', cidr='12.12.1.0/24') test_ib_network.members = [ ib_objects.AnyMember( _struct='dhcpmember', name=ib_cxt.mapping.authority_member.member_name) ] test_gateway_ip = '12.12.1.1' test_ib_network.options = [ ib_objects.DhcpOption(name='routers', value=test_gateway_ip) ] ib_cxt.reserve_service_members(test_ib_network) expected_dns_members = ([ib_cxt.mapping.authority_member] if dns_support else []) # authority member is CPM, so dhcp/dns member should be the same as # authority member self.assertEqual([ib_cxt.mapping.authority_member], ib_cxt.mapping.dhcp_members) self.assertEqual(expected_dns_members, ib_cxt.mapping.dns_members) actual_opt_router = [ opt for opt in test_ib_network.options if opt.name == 'routers' ] self.assertEqual(subnet['gateway_ip'] + ',' + test_gateway_ip, actual_opt_router[0].value)
def _test_reserve_service_members_with_ib_network_with_dhcp_member( self, test_dhcp_member, dns_support, expected_dns_members): user_id = 'test user' tenant_id = '90fbad5a098a4b7cb98826128d5b40b3' # prepare network network_name = 'Test Network' network = self.plugin_stub.create_network(tenant_id, network_name) # prepare subnet subnet_name = 'Test Subnet' subnet_cidr = '11.11.1.0/24' subnet = self.plugin_stub.create_subnet(tenant_id, subnet_name, network['id'], subnet_cidr) self.grid_config.dhcp_support = True self.grid_config.dns_support = dns_support ib_cxt = ib_context.InfobloxContext(self.ctx, user_id, network, subnet, self.grid_config, self.plugin) ib_cxt._register_services = mock.Mock() ib_cxt._get_dhcp_members = mock.Mock(return_value=[test_dhcp_member]) ib_cxt._get_dns_members = mock.Mock(return_value=[test_dhcp_member]) # ib network with dhcp member assigned connector = mock.Mock() test_ib_network = ib_objects.NetworkV4(connector, network_view='test-view', cidr='12.12.1.0/24') test_ib_network.members = [ ib_objects.AnyMember(_struct='dhcpmember', name=test_dhcp_member.member_name, ipv4addr=test_dhcp_member.member_ip) ] test_ib_network.options = [ ib_objects.DhcpOption(name='domain-name-servers', value=test_dhcp_member.member_ip) ] ib_cxt.reserve_service_members(test_ib_network) self.assertEqual([test_dhcp_member], ib_cxt.mapping.dhcp_members) self.assertEqual(expected_dns_members, ib_cxt.mapping.dns_members) actual_opt_router = [ opt for opt in test_ib_network.options if opt.name == 'routers' ] self.assertEqual(subnet['gateway_ip'], actual_opt_router[0].value)
def _test_reserve_service_members_with_ib_network_gm_owned( self, dns_support): user_id = 'test user' tenant_id = 'tenant-id' # prepare network network_name = 'Test Network' network = self.plugin_stub.create_network(tenant_id, network_name) # prepare subnet subnet_name = 'Test Subnet' subnet_cidr = '11.11.1.0/24' subnet = self.plugin_stub.create_subnet(tenant_id, subnet_name, network['id'], subnet_cidr) self.grid_config.dhcp_support = True self.grid_config.dns_support = dns_support ib_cxt = ib_context.InfobloxContext(self.ctx, user_id, network, subnet, self.grid_config, self.plugin) ib_cxt._register_services = mock.Mock() dhcp_members = dbi.get_service_members( self.ctx.session, network_view_id=ib_cxt.mapping.network_view_id, service=const.SERVICE_TYPE_DHCP) expected_dhcp_member = dhcp_members[0] # ib network with no members and options connector = mock.Mock() test_ib_network = ib_objects.NetworkV4(connector, network_view='default', cidr='12.12.1.0/24') test_ib_network.members = [] test_ib_network.options = [] ib_cxt.reserve_service_members(test_ib_network) expected_dns_members = (ib_cxt.mapping.dhcp_members if dns_support else []) self.assertEqual(expected_dhcp_member.member_id, ib_cxt.mapping.dhcp_members[0].member_id) self.assertEqual(expected_dns_members, ib_cxt.mapping.dns_members) actual_opt_router = [ opt for opt in test_ib_network.options if opt.name == 'routers' ] self.assertEqual(subnet['gateway_ip'], actual_opt_router[0].value)