예제 #1
0
    def test_prepare_bottom_router_gateway(self, mock_context):
        self._prepare_pods()
        mock_context.return_value = self.context
        self.assertRaises(t_exceptions.NotFound,
                          self.helper.prepare_bottom_router_gateway,
                          self.context, 'pod_1', 'fake_router')

        router_id = self._prepare_router(test_utils.TEST_TENANT_ID,
                                         router_az_hints='az_name_1')
        self.assertRaises(t_exceptions.NotFound,
                          self.helper.prepare_bottom_router_gateway,
                          self.context, 'pod_1', router_id)
        b_net_id = uuidutils.generate_uuid()
        b_net = {
            'id': b_net_id,
            'name': router_id,
            'tenant_id': test_utils.TEST_TENANT_ID,
            'project_id': test_utils.TEST_TENANT_ID,
            'description': 'description',
            'admin_state_up': False,
            'shared': False,
            'provider:network_type': 'vlan',
            'availability_zone_hints': None
        }
        BOTTOM1_NETS.append(test_utils.DotDict(b_net))

        self.helper.prepare_bottom_router_gateway(self.context, 'pod_1',
                                                  router_id)
        b_gw_ports = list_resource('port', False)
        self.assertEqual(b_gw_ports[0]['device_id'], router_id)
예제 #2
0
def _transform_az(network):
    az_hints_key = 'availability_zone_hints'
    if az_hints_key in network:
        ret = test_utils.DotDict(network)
        az_str = network[az_hints_key]
        ret[az_hints_key] = jsonutils.loads(az_str) if az_str else []
        return ret
    return network
예제 #3
0
 def _prepare_top_network(self,
                          project_id,
                          network_type='vlan',
                          az_hints=None):
     t_net_id = uuidutils.generate_uuid()
     t_subnet_id = uuidutils.generate_uuid()
     t_net = {
         'id': t_net_id,
         'name': t_net_id,
         'tenant_id': project_id,
         'project_id': project_id,
         'description': 'description',
         'admin_state_up': False,
         'shared': False,
         'provider:network_type': network_type,
         'availability_zone_hints': az_hints
     }
     t_subnet = {
         'id': t_subnet_id,
         'network_id': t_net_id,
         'name': t_subnet_id,
         'ip_version': 4,
         'cidr': '10.0.1.0/24',
         'allocation_pools': [],
         'enable_dhcp': True,
         'gateway_ip': '10.0.1.1',
         'ipv6_address_mode': q_constants.IPV6_SLAAC,
         'ipv6_ra_mode': q_constants.IPV6_SLAAC,
         'tenant_id': project_id,
         'project_id': project_id,
         'description': 'description',
         'host_routes': [],
         'dns_nameservers': [],
         'segment_id': 'b85fd910-e483-4ef1-bdf5-b0f747d0b0d5'
     }
     TOP_NETS.append(test_utils.DotDict(t_net))
     TOP_SUBNETS.append(test_utils.DotDict(t_subnet))
     return t_net, t_subnet
예제 #4
0
 def _prepare_router(self, project_id, router_az_hints=None):
     b_router_id = uuidutils.generate_uuid()
     b_router = {
         'id': b_router_id,
         'name': b_router_id,
         'distributed': False,
         'tenant_id': project_id,
         'attached_ports': test_utils.DotList(),
         'extra_attributes': {
             'availability_zone_hints': router_az_hints
         }
     }
     BOTTOM1_ROUTERS.append(test_utils.DotDict(b_router))
     return b_router_id
예제 #5
0
 def action_routers(self, ctx, action, *args, **kwargs):
     router_id, body = args
     if action == 'add_gateway':
         port = {
             'admin_state_up': True,
             'id': uuidutils.generate_uuid(),
             'name': '',
             'network_id': body['network_id'],
             'fixed_ips': '10.0.1.1',
             'mac_address': '',
             'device_id': router_id,
             'device_owner': 'network:router_gateway',
             'binding:vif_type': 'ovs',
             'binding:host_id': 'host_1'
         }
         BOTTOM1_PORTS.append(test_utils.DotDict(port))
     elif action == 'remove_gateway':
         self.delete_routers(ctx, router_id)
예제 #6
0
 def _prepare_bottom_network(self,
                             project_id,
                             b_uuid=None,
                             network_type='vlan',
                             az_hints=None):
     b_net_id = b_uuid or uuidutils.generate_uuid()
     b_net = {
         'id': b_net_id,
         'name': b_net_id,
         'tenant_id': project_id,
         'project_id': project_id,
         'description': 'description',
         'admin_state_up': False,
         'shared': False,
         'provider:network_type': network_type,
         'availability_zone_hints': az_hints
     }
     BOTTOM1_NETS.append(test_utils.DotDict(b_net))
     return b_net
    def _prepare_trunk_test(self,
                            project_id,
                            ctx,
                            pod_name,
                            index,
                            is_create_bottom,
                            t_uuid=None,
                            b_uuid=None):
        t_trunk_id = t_uuid or uuidutils.generate_uuid()
        b_trunk_id = b_uuid or uuidutils.generate_uuid()
        t_parent_port_id = uuidutils.generate_uuid()
        t_sub_port_id = self._prepare_port_test(project_id,
                                                ctx,
                                                pod_name,
                                                index,
                                                create_bottom=is_create_bottom)

        t_subport = {
            'segmentation_type': 'vlan',
            'port_id': t_sub_port_id,
            'segmentation_id': 164,
            'trunk_id': t_trunk_id
        }

        t_trunk = {
            'id': t_trunk_id,
            'name': 'top_trunk_%d' % index,
            'status': 'DOWN',
            'description': 'created',
            'admin_state_up': True,
            'port_id': t_parent_port_id,
            'tenant_id': project_id,
            'project_id': project_id,
            'sub_ports': [t_subport]
        }
        TOP_TRUNKS.append(test_utils.DotDict(t_trunk))
        TOP_SUBPORTS.append(test_utils.DotDict(t_subport))

        b_trunk = None
        if is_create_bottom:
            b_subport = {
                'segmentation_type': 'vlan',
                'port_id': t_sub_port_id,
                'segmentation_id': 164,
                'trunk_id': b_trunk_id
            }

            b_trunk = {
                'id': b_trunk_id,
                'name': 'top_trunk_%d' % index,
                'status': 'UP',
                'description': 'created',
                'admin_state_up': True,
                'port_id': t_parent_port_id,
                'tenant_id': project_id,
                'project_id': project_id,
                'sub_ports': [b_subport]
            }

            if pod_name == 'pod_1':
                BOTTOM1_SUBPORTS.append(test_utils.DotDict(t_subport))
                BOTTOM1_TRUNKS.append(test_utils.DotDict(b_trunk))
            else:
                BOTTOM2_SUBPORTS.append(test_utils.DotDict(t_subport))
                BOTTOM2_TRUNKS.append(test_utils.DotDict(b_trunk))

            pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
            core.create_resource(
                ctx, models.ResourceRouting, {
                    'top_id': t_trunk_id,
                    'bottom_id': b_trunk_id,
                    'pod_id': pod_id,
                    'project_id': project_id,
                    'resource_type': constants.RT_TRUNK
                })

        return t_trunk, b_trunk
    def _prepare_port_test(self,
                           tenant_id,
                           ctx,
                           pod_name,
                           index,
                           device_onwer='compute:None',
                           create_bottom=True):
        t_port_id = uuidutils.generate_uuid()
        t_subnet_id = uuidutils.generate_uuid()
        t_net_id = uuidutils.generate_uuid()

        t_port = {
            'id': t_port_id,
            'name': 'top_port_%d' % index,
            'description': 'old_top_description',
            'extra_dhcp_opts': [],
            'device_owner': device_onwer,
            'security_groups': [],
            'device_id': '68f46ee4-d66a-4c39-bb34-ac2e5eb85470',
            'admin_state_up': True,
            'network_id': t_net_id,
            'tenant_id': tenant_id,
            'mac_address': 'fa:16:3e:cd:76:4%s' % index,
            'project_id': 'tenant_id',
            'binding:host_id': 'zhiyuan-5',
            'status': 'ACTIVE',
            'network_id': t_net_id,
            'fixed_ips': [{
                'subnet_id': t_subnet_id
            }]
        }
        TOP_PORTS.append(test_utils.DotDict(t_port))

        if create_bottom:
            b_port = {
                'id': t_port_id,
                'name': t_port_id,
                'description': 'old_bottom_description',
                'extra_dhcp_opts': [],
                'device_owner': device_onwer,
                'security_groups': [],
                'device_id': '68f46ee4-d66a-4c39-bb34-ac2e5eb85470',
                'admin_state_up': True,
                'network_id': t_net_id,
                'tenant_id': tenant_id,
                'device_owner': 'compute:None',
                'extra_dhcp_opts': [],
                'mac_address': 'fa:16:3e:cd:76:40',
                'project_id': 'tenant_id',
                'binding:host_id': 'zhiyuan-5',
                'status': 'ACTIVE',
                'network_id': t_net_id,
                'fixed_ips': [{
                    'subnet_id': t_subnet_id
                }]
            }
            if pod_name == 'pod_1':
                BOTTOM1_PORTS.append(test_utils.DotDict(b_port))
            else:
                BOTTOM2_PORTS.append(test_utils.DotDict(b_port))

            pod_id = 'pod_id_1' if pod_name == 'pod_1' else 'pod_id_2'
            core.create_resource(
                ctx, models.ResourceRouting, {
                    'top_id': t_port_id,
                    'bottom_id': t_port_id,
                    'pod_id': pod_id,
                    'project_id': tenant_id,
                    'resource_type': constants.RT_PORT
                })

        return t_port_id