def test_get_pod_and_endpoint_by_name(self): pod_dict = { 'pod_id': 'fake_pod_id', 'pod_name': 'fake_pod_name', 'az_name': 'fake_az' } api.create_pod(self.context, pod_dict) pod = api.get_pod_by_name(self.context, pod_dict['pod_name'] + '1') self.assertIsNone(pod) pod = api.get_pod_by_name(self.context, pod_dict['pod_name']) self.assertEqual(pod['pod_id'], pod_dict['pod_id']) self.assertEqual(pod['pod_name'], pod_dict['pod_name']) self.assertEqual(pod['az_name'], pod_dict['az_name']) config_dict = { 'service_id': 'fake_service_id', 'pod_id': 'fake_pod_id', 'service_type': cons.ST_CINDER, 'service_url': 'http://127.0.0.1:8774/v2.1/$(tenant_id)s' } api.create_pod_service_configuration(self.context, config_dict) endpoint = hclient.get_pod_service_endpoint( self.context, pod_dict['pod_name'], config_dict['service_type']) self.assertEqual(endpoint, config_dict['service_url'])
def test_get_pod_and_endpoint_by_name(self): pod_dict = { 'pod_id': 'fake_pod_id', 'region_name': 'fake_region_name', 'az_name': 'fake_az' } api.create_pod(self.context, pod_dict) pod = api.get_pod_by_name(self.context, pod_dict['region_name'] + '1') self.assertIsNone(pod) pod = api.get_pod_by_name(self.context, pod_dict['region_name']) self.assertEqual(pod['pod_id'], pod_dict['pod_id']) self.assertEqual(pod['region_name'], pod_dict['region_name']) self.assertEqual(pod['az_name'], pod_dict['az_name']) config_dict = { 'service_id': 'fake_service_id', 'pod_id': 'fake_pod_id', 'service_type': cons.ST_NEUTRON, 'service_url': 'http://127.0.0.1:9696/v2.0/networks' } api.create_cached_endpoints(self.context, config_dict) endpoint = hclient.get_pod_service_endpoint( self.context, pod_dict['region_name'], config_dict['service_type']) self.assertEqual(endpoint, config_dict['service_url']) endpoint = hclient.get_pod_service_endpoint( self.context, 'x_region_name', config_dict['service_type']) self.assertEqual(endpoint, '')
def test_get_pod_and_endpoint_by_name(self): pod_dict = { 'pod_id': 'fake_pod_id', 'pod_name': 'fake_pod_name', 'az_name': 'fake_az' } api.create_pod(self.context, pod_dict) pod = api.get_pod_by_name(self.context, pod_dict['pod_name'] + '1') self.assertEqual(pod, None) pod = api.get_pod_by_name(self.context, pod_dict['pod_name']) self.assertEqual(pod['pod_id'], pod_dict['pod_id']) self.assertEqual(pod['pod_name'], pod_dict['pod_name']) self.assertEqual(pod['az_name'], pod_dict['az_name']) config_dict = { 'service_id': 'fake_service_id', 'pod_id': 'fake_pod_id', 'service_type': cons.ST_CINDER, 'service_url': 'http://127.0.0.1:8774/v2.1/$(tenant_id)s' } api.create_pod_service_configuration(self.context, config_dict) endpoint = hclient.get_pod_service_endpoint( self.context, pod_dict['pod_name'], config_dict['service_type']) self.assertEqual(endpoint, config_dict['service_url'])
def test_get_pod_by_region(self): self._create_pod(0, 'test_az_uuid1') self._create_pod(1, 'test_az_uuid1') self._create_pod(2, 'test_az_uuid2') region_name = 'test_pod_3' pod = api.get_pod_by_name(self.context, region_name) self.assertIsNone(pod) region_name = 'test_pod_0' pod = api.get_pod_by_name(self.context, region_name) self.assertEqual(pod['region_name'], region_name)
def prepare_bottom_external_subnet_by_bottom_name( self, context, subnet, region_name, b_net_name, top_subnet_id): t_ctx = t_context.get_context_from_neutron_context(context) pod = db_api.get_pod_by_name(t_ctx, region_name) b_client = self._get_client(region_name) bottom_network = b_client.list_networks( t_ctx, [{'key': 'name', 'comparator': 'eq', 'value': b_net_name}] ) if not bottom_network: raise t_exceptions.InvalidInput( reason='bottom network not found for %(b_net_name)s' % {'b_net_name': b_net_name}) body = { 'subnet': { 'name': top_subnet_id, 'network_id': bottom_network[0]['id'], 'tenant_id': subnet['tenant_id'] } } attrs = ('ip_version', 'cidr', 'gateway_ip', 'allocation_pools', 'enable_dhcp') for attr in attrs: if validators.is_attr_set(subnet.get(attr)): body['subnet'][attr] = subnet[attr] self.prepare_bottom_element( t_ctx, subnet['tenant_id'], pod, {'id': top_subnet_id}, t_constants.RT_SUBNET, body)
def prepare_bottom_router_gateway(self, n_context, region_name, segment_name): t_ctx = t_context.get_context_from_neutron_context(n_context) pod = db_api.get_pod_by_name(t_ctx, region_name) b_client = self._get_client(pod['region_name']) # when using new l3 network model, a local router will # be created automatically for an external net, and the # router's name is same to the net's id b_router = b_client.list_routers(t_ctx, filters=[{ 'key': 'name', 'comparator': 'eq', 'value': segment_name }]) if not b_router: raise t_exceptions.NotFound() b_nets = b_client.list_networks(t_ctx, filters=[{ 'key': 'name', 'comparator': 'eq', 'value': segment_name }]) if not b_nets: raise t_exceptions.NotFound() b_info = {'network_id': b_nets[0]['id']} return b_client.action_routers(t_ctx, 'add_gateway', b_router[0]['id'], b_info)
def prepare_bottom_external_subnet_by_bottom_name(self, context, subnet, region_name, b_net_name, top_subnet_id): t_ctx = t_context.get_context_from_neutron_context(context) pod = db_api.get_pod_by_name(t_ctx, region_name) b_client = self._get_client(region_name) bottom_network = b_client.list_networks(t_ctx, [{ 'key': 'name', 'comparator': 'eq', 'value': b_net_name }]) if not bottom_network: raise t_exceptions.InvalidInput( reason='bottom network not found for %(b_net_name)s' % {'b_net_name': b_net_name}) body = { 'subnet': { 'name': top_subnet_id, 'network_id': bottom_network[0]['id'], 'tenant_id': subnet['tenant_id'] } } attrs = ('ip_version', 'cidr', 'gateway_ip', 'allocation_pools', 'enable_dhcp') for attr in attrs: if validators.is_attr_set(subnet.get(attr)): body['subnet'][attr] = subnet[attr] self.prepare_bottom_element(t_ctx, subnet['tenant_id'], pod, {'id': top_subnet_id}, t_constants.RT_SUBNET, body)
def is_local_router(t_ctx, router): router_az_hints = NetworkHelper.get_router_az_hints(router) if not router_az_hints: return False if len(router_az_hints) > 1: return False router_az_hint = router_az_hints[0] return bool(db_api.get_pod_by_name(t_ctx, router_az_hint))
def get_pod_service_endpoint(context, pod_name, st): pod = db_api.get_pod_by_name(context, pod_name) if pod: c = client.Client() return c.get_endpoint(context, pod['pod_id'], st) return ''
def get_pod_service_endpoint(context, region_name, st): pod = db_api.get_pod_by_name(context, region_name) if pod: c = client.Client() return c.get_endpoint(context, pod['pod_id'], st) return ''
def is_local_network(t_ctx, net): if net[provider_net.NETWORK_TYPE] == t_constants.NT_LOCAL: return True net_az_hints = net.get(AZ_HINTS) if not net_az_hints: return False if len(net_az_hints) > 1: return False net_az_hint = net_az_hints[0] return bool(db_api.get_pod_by_name(t_ctx, net_az_hint))
def remove_bottom_router_gateway( self, n_context, region_name, b_net_name): t_ctx = t_context.get_context_from_neutron_context(n_context) pod = db_api.get_pod_by_name(t_ctx, region_name) b_client = self._get_client(pod['region_name']) # when using new l3 network model, a local router will # be created automatically for an external net, and the # router's name is same to the net's id b_router = b_client.list_routers( t_ctx, filters=[{'key': 'name', 'comparator': 'eq', 'value': b_net_name}]) if not b_router: raise t_exceptions.NotFound() return b_client.action_routers( t_ctx, 'remove_gateway', b_router[0]['id'], b_router[0]['id'])
def fake_get_pod_service_endpoint(ctx, pod_name, st): pod = api.get_pod_by_name(ctx, pod_name) if pod: f = [{'key': 'pod_id', 'comparator': 'eq', 'value': pod['pod_id']}, {'key': 'service_type', 'comparator': 'eq', 'value': st}] pod_services = api.list_pod_service_configurations( ctx, filters=f, sorts=[]) if len(pod_services) != 1: return '' return pod_services[0]['service_url'] return ''
def fake_get_pod_service_endpoint(ctx, region_name, st): pod = api.get_pod_by_name(ctx, region_name) if pod: f = [{ 'key': 'pod_id', 'comparator': 'eq', 'value': pod['pod_id'] }, { 'key': 'service_type', 'comparator': 'eq', 'value': st }] pod_services = api.list_cached_endpoints(ctx, filters=f, sorts=[]) if len(pod_services) != 1: return '' return pod_services[0]['service_url'] return ''