コード例 #1
0
ファイル: cinder_data.py プロジェクト: lcnsir/horizon
def data(TEST):
    TEST.cinder_quotas = TestDataContainer()
    TEST.cinder_quota_usages = TestDataContainer()

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    #TEST.quotas.cinder = QuotaSetWrapper(quota)
    TEST.cinder_quotas.add(base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)
コード例 #2
0
def data(TEST):
    TEST.cinder_quotas = utils.TestDataContainer()
    TEST.cinder_quota_usages = utils.TestDataContainer()
    TEST.cinder_availability_zones = utils.TestDataContainer()

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    #TEST.quotas.cinder = QuotaSetWrapper(quota)
    TEST.cinder_quotas.add(base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)

    # Availability Zones
    # Cinder returns the following structure from os-availability-zone
    # {"availabilityZoneInfo":
    # [{"zoneState": {"available": true}, "zoneName": "nova"}]}
    # Note that the default zone is still "nova" even though this is cinder
    TEST.cinder_availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None), {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                }
            }))
    # Cinder Limits
    limits = {
        "absolute": {
            "totalVolumesUsed": 1,
            "totalGigabytesUsed": 5,
            "maxTotalVolumeGigabytes": 1000,
            "maxTotalVolumes": 10
        }
    }
    TEST.cinder_limits = limits
コード例 #3
0
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.agents = utils.TestDataContainer()
    TEST.networks = utils.TestDataContainer()
    TEST.subnets = utils.TestDataContainer()
    TEST.subnetpools = utils.TestDataContainer()
    TEST.ports = utils.TestDataContainer()
    TEST.routers = utils.TestDataContainer()
    TEST.routers_with_rules = utils.TestDataContainer()
    TEST.routers_with_routes = utils.TestDataContainer()
    TEST.q_floating_ips = utils.TestDataContainer()
    TEST.q_secgroups = utils.TestDataContainer()
    TEST.q_secgroup_rules = utils.TestDataContainer()
    TEST.providers = utils.TestDataContainer()
    TEST.pools = utils.TestDataContainer()
    TEST.vips = utils.TestDataContainer()
    TEST.members = utils.TestDataContainer()
    TEST.monitors = utils.TestDataContainer()
    TEST.neutron_quotas = utils.TestDataContainer()
    TEST.neutron_quota_usages = utils.TestDataContainer()
    TEST.vpnservices = utils.TestDataContainer()
    TEST.ikepolicies = utils.TestDataContainer()
    TEST.ipsecpolicies = utils.TestDataContainer()
    TEST.ipsecsiteconnections = utils.TestDataContainer()
    TEST.firewalls = utils.TestDataContainer()
    TEST.fw_policies = utils.TestDataContainer()
    TEST.fw_rules = utils.TestDataContainer()
    TEST.ip_availability = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_agents = utils.TestDataContainer()
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = utils.TestDataContainer()
    TEST.api_subnetpools = utils.TestDataContainer()
    TEST.api_ports = utils.TestDataContainer()
    TEST.api_routers = utils.TestDataContainer()
    TEST.api_routers_with_routes = utils.TestDataContainer()
    TEST.api_q_floating_ips = utils.TestDataContainer()
    TEST.api_q_secgroups = utils.TestDataContainer()
    TEST.api_q_secgroup_rules = utils.TestDataContainer()
    TEST.api_pools = utils.TestDataContainer()
    TEST.api_vips = utils.TestDataContainer()
    TEST.api_members = utils.TestDataContainer()
    TEST.api_monitors = utils.TestDataContainer()
    TEST.api_extensions = utils.TestDataContainer()
    TEST.api_vpnservices = utils.TestDataContainer()
    TEST.api_ikepolicies = utils.TestDataContainer()
    TEST.api_ipsecpolicies = utils.TestDataContainer()
    TEST.api_ipsecsiteconnections = utils.TestDataContainer()
    TEST.api_firewalls = utils.TestDataContainer()
    TEST.api_fw_policies = utils.TestDataContainer()
    TEST.api_fw_rules = utils.TestDataContainer()
    TEST.api_ip_availability = utils.TestDataContainer()

    # 1st network.
    network_dict = {'admin_state_up': True,
                    'id': '82288d84-e0a5-42ac-95be-e6af08727e42',
                    'name': 'net1',
                    'status': 'ACTIVE',
                    'subnets': ['e8abc972-eb0c-41f1-9edd-4bc6e3bcd8c9'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False}
    subnet_dict = {'allocation_pools': [{'end': '10.0.0.254',
                                         'start': '10.0.0.2'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': '10.0.0.0/24',
                   'enable_dhcp': True,
                   'gateway_ip': '10.0.0.1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 4,
                   'name': 'mysubnet1',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Ports on 1st network.
    port_dict = {'admin_state_up': True,
                 'device_id': 'af75c8e5-a1cc-4567-8d04-44fcd6922890',
                 'device_owner': 'network:dhcp',
                 'fixed_ips': [{'ip_address': '10.0.0.3',
                                'subnet_id': subnet_dict['id']}],
                 'id': '063cf7f3-ded1-4297-bc4c-31eae876cc91',
                 'mac_address': 'fa:16:3e:9c:d5:7e',
                 'name': '',
                 'network_id': network_dict['id'],
                 'status': 'ACTIVE',
                 'tenant_id': network_dict['tenant_id'],
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host',
                 'allowed_address_pairs': [{'ip_address': '174.0.0.201',
                                           'mac_address': 'fa:16:3e:7a:7b:18'}]
                 }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    port_dict = {'admin_state_up': True,
                 'device_id': '1',
                 'device_owner': 'compute:nova',
                 'fixed_ips': [{'ip_address': '10.0.0.4',
                                'subnet_id': subnet_dict['id']}],
                 'id': '7e6ce62c-7ea2-44f8-b6b4-769af90a8406',
                 'mac_address': 'fa:16:3e:9d:e6:2f',
                 'name': '',
                 'network_id': network_dict['id'],
                 'status': 'ACTIVE',
                 'tenant_id': network_dict['tenant_id'],
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host'}
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))
    assoc_port = port_dict

    port_dict = {'admin_state_up': True,
                 'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
                 'device_owner': 'network:router_interface',
                 'fixed_ips': [{'ip_address': '10.0.0.1',
                                'subnet_id': subnet_dict['id']}],
                 'id': '9036eedb-e7fa-458e-bc6e-d9d06d9d1bc4',
                 'mac_address': 'fa:16:3e:9c:d5:7f',
                 'name': '',
                 'network_id': network_dict['id'],
                 'status': 'ACTIVE',
                 'tenant_id': network_dict['tenant_id'],
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host'}
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # 2nd network.
    network_dict = {'admin_state_up': True,
                    'id': '72c3ab6c-c80f-4341-9dc5-210fa31ac6c2',
                    'name': 'net2',
                    'status': 'ACTIVE',
                    'subnets': ['3f7c5d79-ee55-47b0-9213-8e669fb03009'],
                    'tenant_id': '2',
                    'router:external': False,
                    'shared': True}
    subnet_dict = {'allocation_pools': [{'end': '172.16.88.254',
                                         'start': '172.16.88.2'}],
                   'dns_nameservers': ['10.56.1.20', '10.56.1.21'],
                   'host_routes': [{'destination': '192.168.20.0/24',
                                    'nexthop': '172.16.88.253'},
                                   {'destination': '192.168.21.0/24',
                                    'nexthop': '172.16.88.252'}],
                   'cidr': '172.16.88.0/24',
                   'enable_dhcp': True,
                   'gateway_ip': '172.16.88.1',
                   'id': '3f7c5d79-ee55-47b0-9213-8e669fb03009',
                   'ip_version': 4,
                   'name': 'aaaa',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    port_dict = {'admin_state_up': True,
                 'device_id': '2',
                 'device_owner': 'compute:nova',
                 'fixed_ips': [{'ip_address': '172.16.88.3',
                                'subnet_id': subnet_dict['id']}],
                 'id': '1db2cc37-3553-43fa-b7e2-3fc4eb4f9905',
                 'mac_address': 'fa:16:3e:56:e6:2f',
                 'name': '',
                 'network_id': network_dict['id'],
                 'status': 'ACTIVE',
                 'tenant_id': network_dict['tenant_id'],
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host'}

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # External network.
    network_dict = {'admin_state_up': True,
                    'id': '9b466b94-213a-4cda-badf-72c102a874da',
                    'name': 'ext_net',
                    'status': 'ACTIVE',
                    'subnets': ['d6bdc71c-7566-4d32-b3ff-36441ce746e8'],
                    'tenant_id': '3',
                    'router:external': True,
                    'shared': False}
    subnet_dict = {'allocation_pools': [{'start': '172.24.4.226.',
                                         'end': '172.24.4.238'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': '172.24.4.0/28',
                   'enable_dhcp': False,
                   'gateway_ip': '172.24.4.225',
                   'id': 'd6bdc71c-7566-4d32-b3ff-36441ce746e8',
                   'ip_version': 4,
                   'name': 'ext_subnet',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}
    ext_net = network_dict

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 1st v6 network.
    network_dict = {'admin_state_up': True,
                    'id': '96688ea1-ffa5-78ec-22ca-33aaabfaf775',
                    'name': 'v6_net1',
                    'status': 'ACTIVE',
                    'subnets': ['88ddd443-4377-ab1f-87dd-4bc4a662dbb6'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False}
    subnet_dict = {'allocation_pools': [{'end': 'ff09::ff',
                                         'start': 'ff09::02'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': 'ff09::/64',
                   'enable_dhcp': True,
                   'gateway_ip': 'ff09::1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 6,
                   'name': 'v6_subnet1',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id'],
                   'ipv6_modes': 'none/none'}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 2nd v6 network - slaac.
    network_dict = {'admin_state_up': True,
                    'id': 'c62e4bb3-296a-4cd1-8f6b-aaa7a0092326',
                    'name': 'v6_net2',
                    'status': 'ACTIVE',
                    'subnets': ['5d736a21-0036-4779-8f8b-eed5f98077ec'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False}
    subnet_dict = {'allocation_pools': [{'end': 'ff09::ff',
                                         'start': 'ff09::02'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': 'ff09::/64',
                   'enable_dhcp': True,
                   'gateway_ip': 'ff09::1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 6,
                   'name': 'v6_subnet2',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id'],
                   'ipv6_modes': 'slaac/slaac'}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Set up router data.
    port_dict = {'admin_state_up': True,
                 'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
                 'device_owner': 'network:router_gateway',
                 'fixed_ips': [{'ip_address': '10.0.0.3',
                                'subnet_id': subnet_dict['id']}],
                 'id': '44ec6726-4bdc-48c5-94d4-df8d1fbf613b',
                 'mac_address': 'fa:16:3e:9c:d5:7e',
                 'name': '',
                 'network_id': TEST.networks.get(name="ext_net")['id'],
                 'status': 'ACTIVE',
                 'tenant_id': '1',
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host'}
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    router_dict = {'id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
                   'name': 'router1',
                   'status': 'ACTIVE',
                   'admin_state_up': True,
                   'distributed': True,
                   'external_gateway_info':
                       {'network_id': ext_net['id']},
                   'tenant_id': '1'}
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {'id': '10e3dc42-1ce1-4d48-87cf-7fc333055d6c',
                   'name': 'router2',
                   'status': 'ACTIVE',
                   'admin_state_up': False,
                   'distributed': False,
                   'external_gateway_info': None,
                   'tenant_id': '1'}
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {'id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
                   'name': 'rulerouter',
                   'status': 'ACTIVE',
                   'admin_state_up': True,
                   'distributed': False,
                   'external_gateway_info':
                       {'network_id': ext_net['id']},
                   'tenant_id': '1',
                   'router_rules': [{'id': '101',
                                     'action': 'deny',
                                     'source': 'any',
                                     'destination': 'any',
                                     'nexthops': []},
                                    {'id': '102',
                                     'action': 'permit',
                                     'source': 'any',
                                     'destination': '8.8.8.8/32',
                                     'nexthops': ['1.0.0.2', '1.0.0.1']}]}
    TEST.api_routers.add(router_dict)
    TEST.routers_with_rules.add(neutron.Router(router_dict))
    router_dict_with_route = {'id': '725c24c9-061b-416b-b9d4-012392b32fd9',
                              'name': 'routerouter',
                              'status': 'ACTIVE',
                              'admin_state_up': True,
                              'distributed': False,
                              'external_gateway_info':
                                  {'network_id': ext_net['id']},
                              'tenant_id': '1',
                              'routes': [{'nexthop': '10.0.0.1',
                                          'destination': '172.0.0.0/24'},
                                         {'nexthop': '10.0.0.2',
                                          'destination': '172.1.0.0/24'}]}
    TEST.api_routers_with_routes.add(router_dict_with_route)
    TEST.routers_with_routes.add(neutron.Router(router_dict_with_route))

    # Floating IP.
    # Unassociated.
    fip_dict = {'tenant_id': '1',
                'floating_ip_address': '172.16.88.227',
                'floating_network_id': ext_net['id'],
                'id': '9012cd70-cfae-4e46-b71e-6a409e9e0063',
                'fixed_ip_address': None,
                'port_id': None,
                'router_id': None}
    TEST.api_q_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': None,
                              'instance_type': None})
    TEST.q_floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Associated (with compute port on 1st network).
    fip_dict = {'tenant_id': '1',
                'floating_ip_address': '172.16.88.228',
                'floating_network_id': ext_net['id'],
                'id': 'a97af8f2-3149-4b97-abbd-e49ad19510f7',
                'fixed_ip_address': assoc_port['fixed_ips'][0]['ip_address'],
                'port_id': assoc_port['id'],
                'router_id': router_dict['id']}
    TEST.api_q_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': '1',
                              'instance_type': 'compute'})
    TEST.q_floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Security group.

    sec_group_1 = {'tenant_id': '1',
                   'description': 'default',
                   'id': 'faad7c80-3b62-4440-967c-13808c37131d',
                   'name': 'default'}
    sec_group_2 = {'tenant_id': '1',
                   'description': 'NotDefault',
                   'id': '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d',
                   'name': 'other_group'}
    sec_group_3 = {'tenant_id': '1',
                   'description': 'NotDefault',
                   'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95',
                   'name': 'another_group'}

    def add_rule_to_group(secgroup, default_only=True):
        rule_egress_ipv4 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv4',
            'port_range_min': None, 'port_range_max': None,
            'protocol': None, 'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_egress_ipv6 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv6',
            'port_range_min': None, 'port_range_max': None,
            'protocol': None, 'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}

        rule_tcp_80 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 80, 'port_range_max': 80,
            'protocol': u'tcp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_icmp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 5, 'port_range_max': 8,
            'protocol': u'icmp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_group = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 80, 'port_range_max': 80,
            'protocol': u'tcp', 'remote_group_id': sec_group_1['id'],
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_all_tcp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv4',
            'port_range_min': 1, 'port_range_max': 65535,
            'protocol': u'tcp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/24',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}

        rules = []
        if not default_only:
            rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp]
        rules += [rule_egress_ipv4, rule_egress_ipv6]
        secgroup['security_group_rules'] = rules

    add_rule_to_group(sec_group_1, default_only=False)
    add_rule_to_group(sec_group_2)
    add_rule_to_group(sec_group_3)

    groups = [sec_group_1, sec_group_2, sec_group_3]
    sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups])
    for sg in groups:
        # Neutron API.
        TEST.api_q_secgroups.add(sg)
        for rule in sg['security_group_rules']:
            TEST.api_q_secgroup_rules.add(copy.copy(rule))
        # OpenStack Dashboard internaly API.
        TEST.q_secgroups.add(
            neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))
        for rule in sg['security_group_rules']:
            TEST.q_secgroup_rules.add(
                neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict))

    # Subnetpools

    # 1st subnetpool
    subnetpool_dict = {'default_prefixlen': 24,
                       'default_quota': None,
                       'id': '419eb314-e244-4088-aed7-851af9d9500d',
                       'ip_version': 4,
                       'max_prefixlen': 32,
                       'min_prefixlen': 12,
                       'name': 'mysubnetpool1',
                       'prefixes': ['172.16.0.0/12'],
                       'shared': False,
                       'tenant_id': '1'}

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # 2nd subnetpool (v6)
    subnetpool_dict = {'default_prefixlen': 64,
                       'default_quota': None,
                       'id': 'dcdad289-46f3-4298-bec6-41d91c942efa',
                       'ip_version': 6,
                       'max_prefixlen': 64,
                       'min_prefixlen': 60,
                       'name': 'mysubnetpool2',
                       'prefixes': ['2001:db8:42::/48'],
                       'shared': False,
                       'tenant_id': '1'}

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # Quotas.
    quota_data = {'network': '10',
                  'subnet': '10',
                  'port': '50',
                  'router': '10',
                  'floatingip': '50',
                  'security_group': '20',
                  'security_group_rule': '100',
                  }
    TEST.neutron_quotas.add(base.QuotaSet(quota_data))

    # Quota Usages
    quota_usage_data = {'networks': {'used': 0, 'quota': 5},
                        'subnets': {'used': 0, 'quota': 5},
                        'routers': {'used': 0, 'quota': 5},
                        }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.neutron_quota_usages.add(quota_usage)

    # Extensions.
    extension_1 = {"name": "security-group",
                   "alias": "security-group",
                   "description": "The security groups extension."}
    extension_2 = {"name": "Quota management support",
                   "alias": "quotas",
                   "description": "Expose functions for quotas management"}
    extension_3 = {"name": "Provider network",
                   "alias": "provider",
                   "description": "Provider network extension"}
    extension_4 = {"name": "Distributed Virtual Router",
                   "alias": "dvr",
                   "description":
                   "Enables configuration of Distributed Virtual Routers."}
    extension_5 = {"name": "HA Router extension",
                   "alias": "l3-ha",
                   "description": "Add HA capability to routers."}
    TEST.api_extensions.add(extension_1)
    TEST.api_extensions.add(extension_2)
    TEST.api_extensions.add(extension_3)
    TEST.api_extensions.add(extension_4)
    TEST.api_extensions.add(extension_5)

    # 1st agent.
    agent_dict = {"binary": "neutron-openvswitch-agent",
                  "description": None,
                  "admin_state_up": True,
                  "heartbeat_timestamp": "2013-07-26 06:51:47",
                  "alive": True,
                  "id": "c876ff05-f440-443e-808c-1d34cda3e88a",
                  "topic": "N/A",
                  "host": "devstack001",
                  "agent_type": "Open vSwitch agent",
                  "started_at": "2013-07-26 05:23:28",
                  "created_at": "2013-07-26 05:23:28",
                  "configurations": {"devices": 2}}
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # 2nd agent.
    agent_dict = {"binary": "neutron-dhcp-agent",
                  "description": None,
                  "admin_state_up": True,
                  "heartbeat_timestamp": "2013-07-26 06:51:48",
                  "alive": True,
                  "id": "f0d12e3d-1973-41a2-b977-b95693f9a8aa",
                  "topic": "dhcp_agent",
                  "host": "devstack001",
                  "agent_type": "DHCP agent",
                  "started_at": "2013-07-26 05:23:30",
                  "created_at": "2013-07-26 05:23:30",
                  "configurations": {
                      "subnets": 1,
                      "use_namespaces": True,
                      "dhcp_lease_duration": 120,
                      "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq",
                      "networks": 1,
                      "ports": 1}}
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # Service providers.
    provider_1 = {"service_type": "LOADBALANCER",
                  "name": "haproxy",
                  "default": True}
    TEST.providers.add(provider_1)

    # VPNaaS.

    # 1st VPNService.
    vpnservice_dict = {'id': '09a26949-6231-4f72-942a-0c8c0ddd4d61',
                       'tenant_id': '1',
                       'name': 'cloud_vpn1',
                       'description': 'vpn description',
                       'subnet_id': TEST.subnets.first().id,
                       'router_id': TEST.routers.first().id,
                       'vpn_type': 'ipsec',
                       'ipsecsiteconnections': [],
                       'admin_state_up': True,
                       'status': 'Active',
                       'ipsecsiteconns': TEST.ipsecsiteconnections.list()
                       }
    TEST.api_vpnservices.add(vpnservice_dict)
    TEST.vpnservices.add(vpn.VPNService(vpnservice_dict))

    # 2nd VPNService.
    vpnservice_dict = {'id': '09a26949-6231-4f72-942a-0c8c0ddd4d62',
                       'tenant_id': '1',
                       'name': 'cloud_vpn2',
                       'description': 'vpn description',
                       'subnet_id': TEST.subnets.first().id,
                       'router_id': TEST.routers.first().id,
                       'vpn_type': 'ipsec',
                       'ipsecsiteconnections': [],
                       'admin_state_up': True,
                       'status': 'Active',
                       'ipsecsiteconns': [],
                       'external_v4_ip': '10.0.0.0/24',
                       'external_v6_ip': 'fd4c:a535:831c::/64'
                       }
    TEST.api_vpnservices.add(vpnservice_dict)
    TEST.vpnservices.add(vpn.VPNService(vpnservice_dict))

    # 1st IKEPolicy
    ikepolicy_dict = {'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c981',
                      'tenant_id': '1',
                      'name': 'ikepolicy_1',
                      'description': 'ikepolicy description',
                      'auth_algorithm': 'sha1',
                      'encryption_algorithm': 'aes-256',
                      'ike_version': 'v1',
                      'lifetime': {'units': 'seconds', 'value': 3600},
                      'phase1_negotiation_mode': 'main',
                      'pfs': 'group5',
                      'ipsecsiteconns': TEST.ipsecsiteconnections.list()}
    TEST.api_ikepolicies.add(ikepolicy_dict)
    TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict))

    # 2nd IKEPolicy
    ikepolicy_dict = {'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c982',
                      'tenant_id': '1',
                      'name': 'ikepolicy_2',
                      'description': 'ikepolicy description',
                      'auth_algorithm': 'sha1',
                      'encryption_algorithm': 'aes-256',
                      'ike_version': 'v1',
                      'lifetime': {'units': 'seconds', 'value': 3600},
                      'phase1_negotiation_mode': 'main',
                      'pfs': 'group5',
                      'ipsecsiteconns': []}
    TEST.api_ikepolicies.add(ikepolicy_dict)
    TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict))

    # 1st IPSecPolicy
    ipsecpolicy_dict = {'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb8',
                        'tenant_id': '1',
                        'name': 'ipsecpolicy_1',
                        'description': 'ipsecpolicy description',
                        'auth_algorithm': 'sha1',
                        'encapsulation_mode': 'tunnel',
                        'encryption_algorithm': '3des',
                        'lifetime': {'units': 'seconds', 'value': 3600},
                        'pfs': 'group5',
                        'transform_protocol': 'esp',
                        'ipsecsiteconns': TEST.ipsecsiteconnections.list()}
    TEST.api_ipsecpolicies.add(ipsecpolicy_dict)
    TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict))

    # 2nd IPSecPolicy
    ipsecpolicy_dict = {'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb9',
                        'tenant_id': '1',
                        'name': 'ipsecpolicy_2',
                        'description': 'ipsecpolicy description',
                        'auth_algorithm': 'sha1',
                        'encapsulation_mode': 'tunnel',
                        'encryption_algorithm': '3des',
                        'lifetime': {'units': 'seconds', 'value': 3600},
                        'pfs': 'group5',
                        'transform_protocol': 'esp',
                        'ipsecsiteconns': []}
    TEST.api_ipsecpolicies.add(ipsecpolicy_dict)
    TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict))

    # 1st IPSecSiteConnection
    ipsecsiteconnection_dict = {'id': 'dd1dd3a0-f349-49be-b013-245e147763d6',
                                'tenant_id': '1',
                                'name': 'ipsec_connection_1',
                                'description': 'vpn connection description',
                                'dpd': {'action': 'hold',
                                        'interval': 30,
                                        'timeout': 120},
                                'ikepolicy_id': ikepolicy_dict['id'],
                                'initiator': 'bi-directional',
                                'ipsecpolicy_id': ipsecpolicy_dict['id'],
                                'mtu': 1500,
                                'peer_address':
                                '2607:f0d0:4545:3:200:f8ff:fe21:67cf',
                                'peer_cidrs': ['20.1.0.0/24', '21.1.0.0/24'],
                                'peer_id':
                                    '2607:f0d0:4545:3:200:f8ff:fe21:67cf',
                                'psk': 'secret',
                                'vpnservice_id': vpnservice_dict['id'],
                                'admin_state_up': True,
                                'status': 'Active'}
    TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict)
    TEST.ipsecsiteconnections.add(
        vpn.IPSecSiteConnection(ipsecsiteconnection_dict))

    # 2nd IPSecSiteConnection
    ipsecsiteconnection_dict = {'id': 'dd1dd3a0-f349-49be-b013-245e147763d7',
                                'tenant_id': '1',
                                'name': 'ipsec_connection_2',
                                'description': 'vpn connection description',
                                'dpd': {'action': 'hold',
                                        'interval': 30,
                                        'timeout': 120},
                                'ikepolicy_id': ikepolicy_dict['id'],
                                'initiator': 'bi-directional',
                                'ipsecpolicy_id': ipsecpolicy_dict['id'],
                                'mtu': 1500,
                                'peer_address': '172.0.0.2',
                                'peer_cidrs': ['20.1.0.0/24'],
                                'peer_id': '172.0.0.2',
                                'psk': 'secret',
                                'vpnservice_id': vpnservice_dict['id'],
                                'admin_state_up': True,
                                'status': 'Active'}
    TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict)
    TEST.ipsecsiteconnections.add(
        vpn.IPSecSiteConnection(ipsecsiteconnection_dict))

    # FWaaS

    # 1st rule (used by 1st policy)
    rule1_dict = {'id': 'f0881d38-c3eb-4fee-9763-12de3338041d',
                  'tenant_id': '1',
                  'name': 'rule1',
                  'description': 'rule1 description',
                  'protocol': 'tcp',
                  'action': 'allow',
                  'source_ip_address': '1.2.3.0/24',
                  'source_port': '80',
                  'destination_ip_address': '4.5.6.7/32',
                  'destination_port': '1:65535',
                  'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                  'position': 1,
                  'shared': True,
                  'enabled': True,
                  'ip_version': '4'}
    TEST.api_fw_rules.add(rule1_dict)

    rule1 = fwaas.Rule(copy.deepcopy(rule1_dict))
    # NOTE: rule1['policy'] is set below
    TEST.fw_rules.add(rule1)

    # 2nd rule (used by 2nd policy; no name)
    rule2_dict = {'id': 'c6298a93-850f-4f64-b78a-959fd4f1e5df',
                  'tenant_id': '1',
                  'name': '',
                  'description': '',
                  'protocol': 'udp',
                  'action': 'deny',
                  'source_ip_address': '1.2.3.0/24',
                  'source_port': '80',
                  'destination_ip_address': '4.5.6.7/32',
                  'destination_port': '1:65535',
                  'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                  'position': 2,
                  'shared': True,
                  'enabled': True,
                  'ip_version': '6'}
    TEST.api_fw_rules.add(rule2_dict)

    rule2 = fwaas.Rule(copy.deepcopy(rule2_dict))
    # NOTE: rule2['policy'] is set below
    TEST.fw_rules.add(rule2)

    # 3rd rule (not used by any policy)
    rule3_dict = {'id': 'h0881d38-c3eb-4fee-9763-12de3338041d',
                  'tenant_id': '1',
                  'name': 'rule3',
                  'description': 'rule3 description',
                  'protocol': None,
                  'action': 'allow',
                  'source_ip_address': '1.2.3.0/24',
                  'source_port': '80',
                  'destination_ip_address': '4.5.6.7/32',
                  'destination_port': '1:65535',
                  'firewall_policy_id': None,
                  'position': None,
                  'shared': True,
                  'enabled': True,
                  'ip_version': '4'}
    TEST.api_fw_rules.add(rule3_dict)

    rule3 = fwaas.Rule(copy.deepcopy(rule3_dict))
    # rule3 is not associated with any rules
    rule3._apidict['policy'] = None
    TEST.fw_rules.add(rule3)

    # 1st policy (associated with 2 rules)
    policy1_dict = {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'tenant_id': '1',
                    'name': 'policy1',
                    'description': 'policy with two rules',
                    'firewall_rules': [rule1_dict['id'], rule2_dict['id']],
                    'audited': True,
                    'shared': True}
    TEST.api_fw_policies.add(policy1_dict)

    policy1 = fwaas.Policy(copy.deepcopy(policy1_dict))
    policy1._apidict['rules'] = [rule1, rule2]
    TEST.fw_policies.add(policy1)

    # Reverse relations (rule -> policy)
    rule1._apidict['policy'] = policy1
    rule2._apidict['policy'] = policy1

    # 2nd policy (associated with no rules; no name)
    policy2_dict = {'id': 'cf50b331-787a-4623-825e-da794c918d6a',
                    'tenant_id': '1',
                    'name': '',
                    'description': '',
                    'firewall_rules': [],
                    'audited': False,
                    'shared': False}
    TEST.api_fw_policies.add(policy2_dict)

    policy2 = fwaas.Policy(copy.deepcopy(policy2_dict))
    policy2._apidict['rules'] = []
    TEST.fw_policies.add(policy2)

    # 1st firewall
    fw1_dict = {'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                'tenant_id': '1',
                'firewall_policy_id':
                    'abcdef-c3eb-4fee-9763-12de3338041e',
                'name': 'firewall1',
                'router_ids': [TEST.routers.first().id],
                'description': 'firewall description',
                'status': 'PENDING_CREATE',
                'admin_state_up': True}
    TEST.api_firewalls.add(fw1_dict)

    fw1 = fwaas.Firewall(copy.deepcopy(fw1_dict))
    fw1._apidict['policy'] = policy1
    fw1._apidict['routers'] = [TEST.routers.first()]
    TEST.firewalls.add(fw1)

    # 2nd firewall (no name)
    fw2_dict = {'id': '1aa75150-415f-458e-bae5-5a362a4fb1f7',
                'tenant_id': '1',
                'firewall_policy_id':
                    'abcdef-c3eb-4fee-9763-12de3338041e',
                'name': '',
                'router_ids': [],
                'description': '',
                'status': 'PENDING_CREATE',
                'admin_state_up': True}
    TEST.api_firewalls.add(fw2_dict)

    fw2 = fwaas.Firewall(copy.deepcopy(fw2_dict))
    fw2._apidict['policy'] = policy1
    TEST.firewalls.add(fw2)

    # ports on 4th network
    port_dict = {'admin_state_up': True,
                 'device_id': '9872faaa-b2b2-eeee-9911-21332eedaa77',
                 'device_owner': 'network:dhcp',
                 'fixed_ips': [{'ip_address': '11.10.0.3',
                                'subnet_id':
                                TEST.subnets.first().id}],
                 'id': 'a21dcd22-6733-cccc-aa32-22adafaf16a2',
                 'mac_address': '78:22:ff:1a:ba:23',
                 'name': 'port5',
                 'network_id': TEST.networks.first().id,
                 'status': 'ACTIVE',
                 'tenant_id': TEST.networks.first().tenant_id,
                 'binding:vnic_type': 'normal',
                 'binding:host_id': 'host'}
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    availability = {'network_ip_availability': {
        'used_ips': 2,
        'subnet_ip_availability': [{
            'used_ips': 1,
            'subnet_id': '2c90f321-9cc7-41b4-a3cf-88110f120a94',
            'subnet_name': 'ipv6-public-subnet',
            'ip_version': 6,
            'cidr': '2001:db8::/64',
            'total_ips': 18446744073709551614},
            {'used_ips': 1,
             'subnet_id': '4d77d5fb-c26c-4ac5-b2ca-fca2f89b0fc1',
             'subnet_name': 'public-subnet',
             'ip_version': 4,
             'cidr': '172.24.4.0/24',
             'total_ips': 253}],
        'network_id': 'd87d5be5-cfca-486f-8db5-a446330e4513',
        'tenant_id': 'd564b2a4fc0544fb89f8a0434dd96863',
        'network_name': 'public',
        'total_ips': 18446744073709551867}
    }

    TEST.ip_availability.add(availability)
    TEST.api_ip_availability.add(availability)
コード例 #4
0
def data(TEST):
    TEST.servers = utils.TestDataContainer()
    TEST.flavors = utils.TestDataContainer()
    TEST.flavor_access = utils.TestDataContainer()
    TEST.keypairs = utils.TestDataContainer()
    TEST.security_groups = utils.TestDataContainer()
    TEST.security_groups_uuid = utils.TestDataContainer()
    TEST.security_group_rules = utils.TestDataContainer()
    TEST.security_group_rules_uuid = utils.TestDataContainer()
    TEST.volumes = utils.TestDataContainer()
    TEST.quotas = utils.TestDataContainer()
    TEST.quota_usages = utils.TestDataContainer()
    TEST.disabled_quotas = utils.TestDataContainer()
    TEST.floating_ips = utils.TestDataContainer()
    TEST.floating_ips_uuid = utils.TestDataContainer()
    TEST.usages = utils.TestDataContainer()
    TEST.certs = utils.TestDataContainer()
    TEST.volume_snapshots = utils.TestDataContainer()
    TEST.volume_types = utils.TestDataContainer()
    TEST.availability_zones = utils.TestDataContainer()
    TEST.hypervisors = utils.TestDataContainer()
    TEST.services = utils.TestDataContainer()
    TEST.aggregates = utils.TestDataContainer()
    TEST.hosts = utils.TestDataContainer()

    # Data return by novaclient.
    # It is used if API layer does data conversion.
    TEST.api_floating_ips = utils.TestDataContainer()
    TEST.api_floating_ips_uuid = utils.TestDataContainer()

    # Volumes
    volume = volumes.Volume(
        volumes.VolumeManager(None),
        dict(id="41023e92-8008-4c8b-8059-7f2293ff3775",
             name='test_volume',
             status='available',
             size=40,
             display_name='Volume name',
             created_at='2012-04-01 10:30:00',
             volume_type=None,
             attachments=[]))
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None),
        dict(id="3b189ac8-9166-ac7f-90c9-16c8bf9e01ac",
             name='',
             status='in-use',
             size=10,
             display_name='',
             display_description='',
             device="/dev/hda",
             created_at='2010-11-21 18:34:25',
             volume_type='vol_type_1',
             attachments=[{
                 "id": "1",
                 "server_id": '1',
                 "device": "/dev/hda"
             }]))
    attached_volume = volumes.Volume(
        volumes.VolumeManager(None),
        dict(id="8cba67c1-2741-6c79-5ab6-9c2bf8c96ab0",
             name='my_volume',
             status='in-use',
             size=30,
             display_name='My Volume',
             display_description='',
             device="/dev/hdk",
             created_at='2011-05-01 11:54:33',
             volume_type='vol_type_2',
             attachments=[{
                 "id": "2",
                 "server_id": '1',
                 "device": "/dev/hdk"
             }]))
    non_bootable_volume = volumes.Volume(
        volumes.VolumeManager(None),
        dict(id="41023e92-8008-4c8b-8059-7f2293ff3771",
             name='non_bootable_volume',
             status='available',
             size=40,
             display_name='Non Bootable Volume',
             created_at='2012-04-01 10:30:00',
             volume_type=None,
             attachments=[]))

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    attached_volume.bootable = 'true'
    non_bootable_volume.bootable = 'false'

    TEST.volumes.add(volume)
    TEST.volumes.add(nameless_volume)
    TEST.volumes.add(attached_volume)
    TEST.volumes.add(non_bootable_volume)

    vol_type1 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': 1,
        'name': 'vol_type_1'
    })
    vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': 2,
        'name': 'vol_type_2'
    })
    TEST.volume_types.add(vol_type1, vol_type2)

    # Flavors
    flavor_1 = flavors.Flavor(
        flavors.FlavorManager(None), {
            'id': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
            'name': 'm1.tiny',
            'vcpus': 1,
            'disk': 0,
            'ram': 512,
            'swap': 0,
            'extra_specs': {},
            'os-flavor-access:is_public': True,
            'OS-FLV-EXT-DATA:ephemeral': 0
        })
    flavor_2 = flavors.Flavor(
        flavors.FlavorManager(None), {
            'id': "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
            'name': 'm1.massive',
            'vcpus': 1000,
            'disk': 1024,
            'ram': 10000,
            'swap': 0,
            'extra_specs': {
                'Trusted': True,
                'foo': 'bar'
            },
            'os-flavor-access:is_public': True,
            'OS-FLV-EXT-DATA:ephemeral': 2048
        })
    flavor_3 = flavors.Flavor(
        flavors.FlavorManager(None), {
            'id': "dddddddd-dddd-dddd-dddd-dddddddddddd",
            'name': 'm1.secret',
            'vcpus': 1000,
            'disk': 1024,
            'ram': 10000,
            'swap': 0,
            'extra_specs': {},
            'os-flavor-access:is_public': False,
            'OS-FLV-EXT-DATA:ephemeral': 2048
        })
    flavor_4 = flavors.Flavor(
        flavors.FlavorManager(None), {
            'id':
            "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee",
            'name':
            'm1.metadata',
            'vcpus':
            1000,
            'disk':
            1024,
            'ram':
            10000,
            'swap':
            0,
            'extra_specs':
            FlavorExtraSpecs({
                'key': 'key_mock',
                'value': 'value_mock'
            }),
            'os-flavor-access:is_public':
            False,
            'OS-FLV-EXT-DATA:ephemeral':
            2048
        })
    TEST.flavors.add(flavor_1, flavor_2, flavor_3, flavor_4)

    flavor_access_manager = flavor_access.FlavorAccessManager(None)
    flavor_access_1 = flavor_access.FlavorAccess(
        flavor_access_manager, {
            "tenant_id": "1",
            "flavor_id": "dddddddd-dddd-dddd-dddd-dddddddddddd"
        })
    flavor_access_2 = flavor_access.FlavorAccess(
        flavor_access_manager, {
            "tenant_id": "2",
            "flavor_id": "dddddddd-dddd-dddd-dddd-dddddddddddd"
        })
    TEST.flavor_access.add(flavor_access_1, flavor_access_2)

    # Key pairs
    keypair = keypairs.Keypair(keypairs.KeypairManager(None),
                               dict(name='keyName'))
    TEST.keypairs.add(keypair)

    # Security Groups and Rules
    def generate_security_groups(is_uuid=False):
        def get_id(is_uuid):
            global current_int_id
            if is_uuid:
                return str(uuid.uuid4())
            else:
                get_id.current_int_id += 1
                return get_id.current_int_id

        get_id.current_int_id = 0

        sg_manager = sec_groups.SecurityGroupManager(None)
        rule_manager = rules.SecurityGroupRuleManager(None)

        sec_group_1 = sec_groups.SecurityGroup(
            sg_manager, {
                "rules": [],
                "tenant_id": TEST.tenant.id,
                "id": get_id(is_uuid),
                "name": u"default",
                "description": u"default"
            })
        sec_group_2 = sec_groups.SecurityGroup(
            sg_manager, {
                "rules": [],
                "tenant_id": TEST.tenant.id,
                "id": get_id(is_uuid),
                "name": u"other_group",
                "description": u"NotDefault."
            })
        sec_group_3 = sec_groups.SecurityGroup(
            sg_manager, {
                "rules": [],
                "tenant_id": TEST.tenant.id,
                "id": get_id(is_uuid),
                "name": u"another_group",
                "description": u"NotDefault."
            })

        rule = {
            'id': get_id(is_uuid),
            'group': {},
            'ip_protocol': u"tcp",
            'from_port': u"80",
            'to_port': u"80",
            'parent_group_id': sec_group_1.id,
            'ip_range': {
                'cidr': u"0.0.0.0/32"
            }
        }

        icmp_rule = {
            'id': get_id(is_uuid),
            'group': {},
            'ip_protocol': u"icmp",
            'from_port': u"9",
            'to_port': u"5",
            'parent_group_id': sec_group_1.id,
            'ip_range': {
                'cidr': u"0.0.0.0/32"
            }
        }

        group_rule = {
            'id': 3,
            'group': {},
            'ip_protocol': u"tcp",
            'from_port': u"80",
            'to_port': u"80",
            'parent_group_id': sec_group_1.id,
            'source_group_id': sec_group_1.id
        }

        rule_obj = rules.SecurityGroupRule(rule_manager, rule)
        rule_obj2 = rules.SecurityGroupRule(rule_manager, icmp_rule)
        rule_obj3 = rules.SecurityGroupRule(rule_manager, group_rule)

        sec_group_1.rules = [rule_obj]
        sec_group_2.rules = [rule_obj]

        return {
            "rules": [rule_obj, rule_obj2, rule_obj3],
            "groups": [sec_group_1, sec_group_2, sec_group_3]
        }

    sg_data = generate_security_groups()
    TEST.security_group_rules.add(*sg_data["rules"])
    TEST.security_groups.add(*sg_data["groups"])

    sg_uuid_data = generate_security_groups(is_uuid=True)
    TEST.security_group_rules_uuid.add(*sg_uuid_data["rules"])
    TEST.security_groups_uuid.add(*sg_uuid_data["groups"])

    # Quota Sets
    quota_data = dict(metadata_items='1',
                      injected_file_content_bytes='1',
                      volumes='1',
                      gigabytes='1000',
                      ram=10000,
                      floating_ips='1',
                      fixed_ips='10',
                      instances='10',
                      injected_files='1',
                      cores='10',
                      security_groups='10',
                      security_group_rules='20')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.quotas.nova = base.QuotaSet(quota)
    TEST.quotas.add(base.QuotaSet(quota))

    # nova quotas disabled when neutron is enabled
    disabled_quotas_nova = [
        'floating_ips', 'fixed_ips', 'security_groups', 'security_group_rules'
    ]
    TEST.disabled_quotas.add(disabled_quotas_nova)

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'ram': {
            'used': 0,
            'quota': 10000
        },
        'cores': {
            'used': 0,
            'quota': 20
        },
        'floating_ips': {
            'used': 0,
            'quota': 10
        },
        'volumes': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.quota_usages.add(quota_usage)

    # Limits
    limits = {
        "absolute": {
            "maxImageMeta": 128,
            "maxPersonality": 5,
            "maxPersonalitySize": 10240,
            "maxSecurityGroupRules": 20,
            "maxSecurityGroups": 10,
            "maxServerMeta": 128,
            "maxTotalCores": 20,
            "maxTotalFloatingIps": 10,
            "maxTotalInstances": 10,
            "maxTotalKeypairs": 100,
            "maxTotalRAMSize": 10000,
            "totalCoresUsed": 0,
            "totalInstancesUsed": 0,
            "totalKeyPairsUsed": 0,
            "totalRAMUsed": 0,
            "totalSecurityGroupsUsed": 0
        }
    }
    TEST.limits = limits

    # Servers
    tenant3 = TEST.tenants.list()[2]

    vals = {
        "host": "http://nova.example.com:8774",
        "name": "server_1",
        "status": "ACTIVE",
        "tenant_id": TEST.tenants.first().id,
        "user_id": TEST.user.id,
        "server_id": "1",
        "flavor_id": flavor_1.id,
        "image_id": TEST.images.first().id,
        "key_name": keypair.name
    }
    server_1 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    vals.update({"name": "server_2", "status": "BUILD", "server_id": "2"})
    server_2 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    vals.update({
        "name": u'\u4e91\u89c4\u5219',
        "status": "ACTIVE",
        "tenant_id": tenant3.id,
        "server_id": "3"
    })
    server_3 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    TEST.servers.add(server_1, server_2, server_3)

    # VNC Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/vnc_auto.html',
            u'type': u'novnc'
        }
    }
    TEST.servers.vnc_console_data = console
    # SPICE Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/spice_auto.html',
            u'type': u'spice'
        }
    }
    TEST.servers.spice_console_data = console
    # RDP Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/rdp_auto.html',
            u'type': u'rdp'
        }
    }
    TEST.servers.rdp_console_data = console

    # Floating IPs
    def generate_fip(conf):
        return floating_ips.FloatingIP(floating_ips.FloatingIPManager(None),
                                       conf)

    fip_1 = {
        'id': 1,
        'fixed_ip': '10.0.0.4',
        'instance_id': server_1.id,
        'ip': '58.58.58.58',
        'pool': 'pool1'
    }
    fip_2 = {
        'id': 2,
        'fixed_ip': None,
        'instance_id': None,
        'ip': '58.58.58.58',
        'pool': 'pool2'
    }
    TEST.api_floating_ips.add(generate_fip(fip_1), generate_fip(fip_2))

    TEST.floating_ips.add(nova.FloatingIp(generate_fip(fip_1)),
                          nova.FloatingIp(generate_fip(fip_2)))

    # Floating IP with UUID id (for Floating IP with Neutron Proxy)
    fip_3 = {
        'id': str(uuid.uuid4()),
        'fixed_ip': '10.0.0.4',
        'instance_id': server_1.id,
        'ip': '58.58.58.58',
        'pool': 'pool1'
    }
    fip_4 = {
        'id': str(uuid.uuid4()),
        'fixed_ip': None,
        'instance_id': None,
        'ip': '58.58.58.58',
        'pool': 'pool2'
    }
    TEST.api_floating_ips_uuid.add(generate_fip(fip_3), generate_fip(fip_4))

    TEST.floating_ips_uuid.add(nova.FloatingIp(generate_fip(fip_3)),
                               nova.FloatingIp(generate_fip(fip_4)))

    # Usage
    usage_vals = {
        "tenant_id": TEST.tenant.id,
        "instance_name": server_1.name,
        "flavor_name": flavor_1.name,
        "flavor_vcpus": flavor_1.vcpus,
        "flavor_disk": flavor_1.disk,
        "flavor_ram": flavor_1.ram
    }
    usage_obj = usage.Usage(usage.UsageManager(None),
                            json.loads(USAGE_DATA % usage_vals))
    TEST.usages.add(usage_obj)

    usage_2_vals = {
        "tenant_id": tenant3.id,
        "instance_name": server_3.name,
        "flavor_name": flavor_1.name,
        "flavor_vcpus": flavor_1.vcpus,
        "flavor_disk": flavor_1.disk,
        "flavor_ram": flavor_1.ram
    }
    usage_obj_2 = usage.Usage(usage.UsageManager(None),
                              json.loads(USAGE_DATA % usage_2_vals))
    TEST.usages.add(usage_obj_2)

    volume_snapshot = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': '40f3fabf-3613-4f5e-90e5-6c9a08333fc3',
            'display_name': 'test snapshot',
            'display_description': 'vol snap!',
            'size': 40,
            'status': 'available',
            'volume_id': '41023e92-8008-4c8b-8059-7f2293ff3775'
        })
    volume_snapshot2 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31',
            'display_name': '',
            'display_description': 'vol snap 2!',
            'size': 80,
            'status': 'available',
            'volume_id': '3b189ac8-9166-ac7f-90c9-16c8bf9e01ac'
        })
    TEST.volume_snapshots.add(volume_snapshot)
    TEST.volume_snapshots.add(volume_snapshot2)

    cert_data = {'private_key': 'private', 'data': 'certificate_data'}
    certificate = certs.Certificate(certs.CertificateManager(None), cert_data)
    TEST.certs.add(certificate)

    # Availability Zones
    TEST.availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None),
            {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                },
                'hosts': {
                    "host001": {
                        "nova-network": {
                            "active": True,
                            "available": True,
                        },
                    },
                },
            },
        ))

    # hypervisors
    hypervisor_1 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {
                "host": "devstack001",
                "id": 3
            },
            "vcpus_used":
            1,
            "hypervisor_type":
            "QEMU",
            "local_gb_used":
            20,
            "hypervisor_hostname":
            "devstack001",
            "memory_mb_used":
            1500,
            "memory_mb":
            2000,
            "current_workload":
            0,
            "vcpus":
            1,
            "cpu_info":
            '{"vendor": "Intel", "model": "core2duo",'
            '"arch": "x86_64", "features": ["lahf_lm"'
            ', "rdtscp"], "topology": {"cores": 1, "t'
            'hreads": 1, "sockets": 1}}',
            "running_vms":
            1,
            "free_disk_gb":
            9,
            "hypervisor_version":
            1002000,
            "disk_available_least":
            6,
            "local_gb":
            29,
            "free_ram_mb":
            500,
            "id":
            1,
        },
    )

    hypervisor_2 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {
                "host": "devstack002",
                "id": 4
            },
            "vcpus_used":
            1,
            "hypervisor_type":
            "QEMU",
            "local_gb_used":
            20,
            "hypervisor_hostname":
            "devstack002",
            "memory_mb_used":
            1500,
            "memory_mb":
            2000,
            "current_workload":
            0,
            "vcpus":
            1,
            "cpu_info":
            '{"vendor": "Intel", "model": "core2duo",'
            '"arch": "x86_64", "features": ["lahf_lm"'
            ', "rdtscp"], "topology": {"cores": 1, "t'
            'hreads": 1, "sockets": 1}}',
            "running_vms":
            1,
            "free_disk_gb":
            9,
            "hypervisor_version":
            1002000,
            "disk_available_least":
            6,
            "local_gb":
            29,
            "free_ram_mb":
            500,
            "id":
            2,
        },
    )
    hypervisor_3 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {
                "host": "instance-host",
                "id": 5
            },
            "vcpus_used":
            1,
            "hypervisor_type":
            "QEMU",
            "local_gb_used":
            20,
            "hypervisor_hostname":
            "devstack003",
            "memory_mb_used":
            1500,
            "memory_mb":
            2000,
            "current_workload":
            0,
            "vcpus":
            1,
            "cpu_info":
            '{"vendor": "Intel", "model": "core2duo",'
            '"arch": "x86_64", "features": ["lahf_lm"'
            ', "rdtscp"], "topology": {"cores": 1, "t'
            'hreads": 1, "sockets": 1}}',
            "running_vms":
            1,
            "free_disk_gb":
            9,
            "hypervisor_version":
            1002000,
            "disk_available_least":
            6,
            "local_gb":
            29,
            "free_ram_mb":
            500,
            "id":
            3,
        },
    )
    TEST.hypervisors.add(hypervisor_1)
    TEST.hypervisors.add(hypervisor_2)
    TEST.hypervisors.add(hypervisor_3)

    TEST.hypervisors.stats = {
        "hypervisor_statistics": {
            "count": 5,
            "vcpus_used": 3,
            "local_gb_used": 15,
            "memory_mb": 483310,
            "current_workload": 0,
            "vcpus": 160,
            "running_vms": 3,
            "free_disk_gb": 12548,
            "disk_available_least": 12556,
            "local_gb": 12563,
            "free_ram_mb": 428014,
            "memory_mb_used": 55296,
        }
    }

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "status": "enabled",
            "binary": "nova-conductor",
            "zone": "internal",
            "state": "up",
            "updated_at": "2013-07-08T05:21:00.000000",
            "host": "devstack001",
            "disabled_reason": None,
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "status": "enabled",
            "binary": "nova-compute",
            "zone": "nova",
            "state": "up",
            "updated_at": "2013-07-08T05:20:51.000000",
            "host": "devstack001",
            "disabled_reason": None,
        })

    service_3 = services.Service(
        services.ServiceManager(None), {
            "status": "enabled",
            "binary": "nova-compute",
            "zone": "nova",
            "state": "down",
            "updated_at": "2013-07-08T04:20:51.000000",
            "host": "devstack002",
            "disabled_reason": None,
        })

    TEST.services.add(service_1)
    TEST.services.add(service_2)
    TEST.services.add(service_3)

    # Aggregates
    aggregate_1 = aggregates.Aggregate(
        aggregates.AggregateManager(None), {
            "name": "foo",
            "availability_zone": "testing",
            "deleted": 0,
            "created_at": "2013-07-04T13:34:38.000000",
            "updated_at": None,
            "hosts": ["foo", "bar"],
            "deleted_at": None,
            "id": 1,
            "metadata": {
                "foo": "testing",
                "bar": "testing"
            },
        })

    aggregate_2 = aggregates.Aggregate(
        aggregates.AggregateManager(None), {
            "name": "bar",
            "availability_zone": "testing",
            "deleted": 0,
            "created_at": "2013-07-04T13:34:38.000000",
            "updated_at": None,
            "hosts": ["foo", "bar"],
            "deleted_at": None,
            "id": 2,
            "metadata": {
                "foo": "testing",
                "bar": "testing"
            },
        })

    TEST.aggregates.add(aggregate_1)
    TEST.aggregates.add(aggregate_2)

    host1 = hosts.Host(hosts.HostManager(None), {
        "host_name": "devstack001",
        "service": "compute",
        "zone": "testing",
    })

    host2 = hosts.Host(
        hosts.HostManager(None), {
            "host_name": "devstack002",
            "service": "nova-conductor",
            "zone": "testing",
        })

    host3 = hosts.Host(hosts.HostManager(None), {
        "host_name": "devstack003",
        "service": "compute",
        "zone": "testing",
    })

    host4 = hosts.Host(hosts.HostManager(None), {
        "host_name": "devstack004",
        "service": "compute",
        "zone": "testing",
    })

    TEST.hosts.add(host1)
    TEST.hosts.add(host2)
    TEST.hosts.add(host3)
    TEST.hosts.add(host4)
コード例 #5
0
def data(TEST):
    TEST.servers = utils.TestDataContainer()
    TEST.flavors = utils.TestDataContainer()
    TEST.flavor_access = utils.TestDataContainer()
    TEST.keypairs = utils.TestDataContainer()
    TEST.volumes = utils.TestDataContainer()
    TEST.quotas = utils.TestDataContainer()
    TEST.quota_usages = utils.TestDataContainer()
    TEST.usages = utils.TestDataContainer()
    TEST.availability_zones = utils.TestDataContainer()
    TEST.hypervisors = utils.TestDataContainer()
    TEST.services = utils.TestDataContainer()
    TEST.aggregates = utils.TestDataContainer()
    TEST.server_groups = utils.TestDataContainer()

    # Volumes
    volume = volumes.Volume(
        volumes.VolumeManager(None),
        {"id": "41023e92-8008-4c8b-8059-7f2293ff3775",
         "name": 'test_volume',
         "status": 'available',
         "size": 40,
         "display_name": 'Volume name',
         "created_at": '2012-04-01 10:30:00',
         "volume_type": None,
         "attachments": []})
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None),
        {"id": "3b189ac8-9166-ac7f-90c9-16c8bf9e01ac",
         "name": '',
         "status": 'in-use',
         "size": 10,
         "display_name": '',
         "display_description": '',
         "device": "/dev/hda",
         "created_at": '2010-11-21 18:34:25',
         "volume_type": 'vol_type_1',
         "attachments": [{"id": "1", "server_id": '1',
                          "device": "/dev/hda"}]})
    attached_volume = volumes.Volume(
        volumes.VolumeManager(None),
        {"id": "8cba67c1-2741-6c79-5ab6-9c2bf8c96ab0",
         "name": 'my_volume',
         "status": 'in-use',
         "size": 30,
         "display_name": 'My Volume',
         "display_description": '',
         "device": "/dev/hdk",
         "created_at": '2011-05-01 11:54:33',
         "volume_type": 'vol_type_2',
         "attachments": [{"id": "2", "server_id": '1',
                          "device": "/dev/hdk"}]})
    non_bootable_volume = volumes.Volume(
        volumes.VolumeManager(None),
        {"id": "41023e92-8008-4c8b-8059-7f2293ff3771",
         "name": 'non_bootable_volume',
         "status": 'available',
         "size": 40,
         "display_name": 'Non Bootable Volume',
         "created_at": '2012-04-01 10:30:00',
         "volume_type": None,
         "attachments": []})

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    attached_volume.bootable = 'true'
    non_bootable_volume.bootable = 'false'

    TEST.volumes.add(volume)
    TEST.volumes.add(nameless_volume)
    TEST.volumes.add(attached_volume)
    TEST.volumes.add(non_bootable_volume)

    # Flavors
    flavor_1 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
                               'name': 'm1.tiny',
                               'vcpus': 1,
                               'disk': 0,
                               'ram': 512,
                               'swap': 0,
                               'rxtx_factor': 1,
                               'extra_specs': {},
                               'os-flavor-access:is_public': True,
                               'OS-FLV-EXT-DATA:ephemeral': 0})
    flavor_2 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
                               'name': 'm1.massive',
                               'vcpus': 1000,
                               'disk': 1024,
                               'ram': 10000,
                               'swap': 0,
                               'rxtx_factor': 1,
                               'extra_specs': {'Trusted': True, 'foo': 'bar'},
                               'os-flavor-access:is_public': True,
                               'OS-FLV-EXT-DATA:ephemeral': 2048})
    flavor_3 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': "dddddddd-dddd-dddd-dddd-dddddddddddd",
                               'name': 'm1.secret',
                               'vcpus': 1000,
                               'disk': 1024,
                               'ram': 10000,
                               'swap': 0,
                               'rxtx_factor': 1,
                               'extra_specs': {},
                               'os-flavor-access:is_public': False,
                               'OS-FLV-EXT-DATA:ephemeral': 2048})
    flavor_4 = flavors.Flavor(flavors.FlavorManager(None),
                              {'id': "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee",
                               'name': 'm1.metadata',
                               'vcpus': 1000,
                               'disk': 1024,
                               'ram': 10000,
                               'swap': 0,
                               'rxtx_factor': 1,
                               'extra_specs': FlavorExtraSpecs(
                                   {'key': 'key_mock',
                                    'value': 'value_mock'}),
                               'os-flavor-access:is_public': False,
                               'OS-FLV-EXT-DATA:ephemeral': 2048})
    TEST.flavors.add(flavor_1, flavor_2, flavor_3, flavor_4)

    flavor_access_manager = flavor_access.FlavorAccessManager(None)
    flavor_access_1 = flavor_access.FlavorAccess(
        flavor_access_manager,
        {"tenant_id": "1",
         "flavor_id": "dddddddd-dddd-dddd-dddd-dddddddddddd"})
    flavor_access_2 = flavor_access.FlavorAccess(
        flavor_access_manager,
        {"tenant_id": "2",
         "flavor_id": "dddddddd-dddd-dddd-dddd-dddddddddddd"})
    TEST.flavor_access.add(flavor_access_1, flavor_access_2)

    # Key pairs
    keypair = keypairs.Keypair(keypairs.KeypairManager(None),
                               dict(name='keyName'))
    TEST.keypairs.add(keypair)

    # Quota Sets
    quota_data = {
        'metadata_items': '1',
        'injected_file_content_bytes': '1',
        'ram': 10000,
        'instances': '10',
        'injected_files': '1',
        'cores': '10',
        'key_pairs': 100,
        'server_groups': 10,
        'server_group_members': 10,
        'injected_file_path_bytes': 255,
    }
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.quotas.nova = base.QuotaSet(quota)
    TEST.quotas.add(base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {'gigabytes': {'used': 0,
                                      'quota': 1000},
                        'instances': {'used': 0,
                                      'quota': 10},
                        'ram': {'used': 0,
                                'quota': 10000},
                        'cores': {'used': 0,
                                  'quota': 20},
                        'volumes': {'used': 0,
                                    'quota': 10}}
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.quota_usages.add(quota_usage)

    # Limits
    limits = {"absolute": {"maxImageMeta": 128,
                           "maxPersonality": 5,
                           "maxPersonalitySize": 10240,
                           "maxSecurityGroupRules": 20,
                           "maxSecurityGroups": 10,
                           "maxServerMeta": 128,
                           "maxTotalCores": 20,
                           "maxTotalFloatingIps": 10,
                           "maxTotalInstances": 10,
                           "maxTotalKeypairs": 100,
                           "maxTotalRAMSize": 10000,
                           "totalCoresUsed": 2,
                           "totalInstancesUsed": 2,
                           "totalKeyPairsUsed": 0,
                           "totalRAMUsed": 1024,
                           "totalSecurityGroupsUsed": 0}}
    TEST.limits = limits

    # Servers
    tenant3 = TEST.tenants.list()[2]

    vals = {"host": "http://nova.example.com:8774",
            "name": "server_1",
            "status": "ACTIVE",
            "tenant_id": TEST.tenants.first().id,
            "user_id": TEST.user.id,
            "server_id": "1",
            "flavor_id": flavor_1.id,
            "image_id": TEST.images.first().id,
            "key_name": keypair.name}
    server_1 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    vals.update({"name": "server_2",
                 "status": "BUILD",
                 "server_id": "2"})
    server_2 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    vals.update({"name": u'\u4e91\u89c4\u5219',
                 "status": "ACTIVE",
                 "tenant_id": tenant3.id,
                "server_id": "3"})
    server_3 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    vals.update({"name": "server_4",
                 "status": "PAUSED",
                 "server_id": "4"})
    server_4 = servers.Server(servers.ServerManager(None),
                              json.loads(SERVER_DATA % vals)['server'])
    TEST.servers.add(server_1, server_2, server_3, server_4)

    # VNC Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/vnc_auto.html',
            u'type': u'novnc'
        }
    }
    TEST.servers.vnc_console_data = console
    # SPICE Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/spice_auto.html',
            u'type': u'spice'
        }
    }
    TEST.servers.spice_console_data = console
    # RDP Console Data
    console = {
        u'console': {
            u'url': u'http://example.com:6080/rdp_auto.html',
            u'type': u'rdp'
        }
    }
    TEST.servers.rdp_console_data = console
    # MKS Console Data
    console = {
        u'remote_console': {
            u'url': u'http://example.com:6080/mks_auto.html',
            u'type': u'mks'
        }
    }
    TEST.servers.mks_console_data = console

    # Usage
    usage_vals = {"tenant_id": TEST.tenant.id,
                  "instance_name": server_1.name,
                  "flavor_name": flavor_1.name,
                  "flavor_vcpus": flavor_1.vcpus,
                  "flavor_disk": flavor_1.disk,
                  "flavor_ram": flavor_1.ram}
    usage_obj = usage.Usage(usage.UsageManager(None),
                            json.loads(USAGE_DATA % usage_vals))
    TEST.usages.add(usage_obj)

    usage_2_vals = {"tenant_id": tenant3.id,
                    "instance_name": server_3.name,
                    "flavor_name": flavor_1.name,
                    "flavor_vcpus": flavor_1.vcpus,
                    "flavor_disk": flavor_1.disk,
                    "flavor_ram": flavor_1.ram}
    usage_obj_2 = usage.Usage(usage.UsageManager(None),
                              json.loads(USAGE_DATA % usage_2_vals))
    TEST.usages.add(usage_obj_2)

    # Availability Zones
    TEST.availability_zones.add(availability_zones.AvailabilityZone(
        availability_zones.AvailabilityZoneManager(None),
        {
            'zoneName': 'nova',
            'zoneState': {'available': True},
            'hosts': {
                "host001": {
                    "nova-network": {
                        "active": True,
                        "available": True,
                    },
                },
            },
        },
    ))

    # hypervisors
    hypervisor_1 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {"host": "devstack001", "id": 3},
            "vcpus_used": 1,
            "hypervisor_type": "QEMU",
            "local_gb_used": 20,
            "hypervisor_hostname": "devstack001",
            "memory_mb_used": 1500,
            "memory_mb": 2000,
            "current_workload": 0,
            "vcpus": 1,
            "cpu_info": '{"vendor": "Intel", "model": "core2duo",'
                        '"arch": "x86_64", "features": ["lahf_lm"'
                        ', "rdtscp"], "topology": {"cores": 1, "t'
                        'hreads": 1, "sockets": 1}}',
            "running_vms": 1,
            "free_disk_gb": 9,
            "hypervisor_version": 1002000,
            "disk_available_least": 6,
            "local_gb": 29,
            "free_ram_mb": 500,
            "id": 1,
            "servers": [{"name": "test_name", "uuid": "test_uuid"}]
        },
    )

    hypervisor_2 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {"host": "devstack002", "id": 4},
            "vcpus_used": 1,
            "hypervisor_type": "QEMU",
            "local_gb_used": 20,
            "hypervisor_hostname": "devstack002",
            "memory_mb_used": 1500,
            "memory_mb": 2000,
            "current_workload": 0,
            "vcpus": 1,
            "cpu_info": '{"vendor": "Intel", "model": "core2duo",'
                        '"arch": "x86_64", "features": ["lahf_lm"'
                        ', "rdtscp"], "topology": {"cores": 1, "t'
                        'hreads": 1, "sockets": 1}}',
            "running_vms": 1,
            "free_disk_gb": 9,
            "hypervisor_version": 1002000,
            "disk_available_least": 6,
            "local_gb": 29,
            "free_ram_mb": 500,
            "id": 2,
            "servers": [{"name": "test_name_2", "uuid": "test_uuid_2"}]
        },
    )
    hypervisor_3 = hypervisors.Hypervisor(
        hypervisors.HypervisorManager(None),
        {
            "service": {"host": "instance-host", "id": 5},
            "vcpus_used": 1,
            "hypervisor_type": "QEMU",
            "local_gb_used": 20,
            "hypervisor_hostname": "instance-host",
            "memory_mb_used": 1500,
            "memory_mb": 2000,
            "current_workload": 0,
            "vcpus": 1,
            "cpu_info": '{"vendor": "Intel", "model": "core2duo",'
                        '"arch": "x86_64", "features": ["lahf_lm"'
                        ', "rdtscp"], "topology": {"cores": 1, "t'
                        'hreads": 1, "sockets": 1}}',
            "running_vms": 1,
            "free_disk_gb": 9,
            "hypervisor_version": 1002000,
            "disk_available_least": 6,
            "local_gb": 29,
            "free_ram_mb": 500,
            "id": 3,
        },
    )
    TEST.hypervisors.add(hypervisor_1)
    TEST.hypervisors.add(hypervisor_2)
    TEST.hypervisors.add(hypervisor_3)

    TEST.hypervisors.stats = {
        "hypervisor_statistics": {
            "count": 5,
            "vcpus_used": 3,
            "local_gb_used": 15,
            "memory_mb": 483310,
            "current_workload": 0,
            "vcpus": 160,
            "running_vms": 3,
            "free_disk_gb": 12548,
            "disk_available_least": 12556,
            "local_gb": 12563,
            "free_ram_mb": 428014,
            "memory_mb_used": 55296,
        }
    }

    # Services
    service_1 = services.Service(services.ServiceManager(None), {
        "status": "enabled",
        "binary": "nova-conductor",
        "zone": "internal",
        "state": "up",
        "updated_at": "2013-07-08T05:21:00.000000",
        "host": "devstack001",
        "disabled_reason": None,
    })

    service_2 = services.Service(services.ServiceManager(None), {
        "status": "enabled",
        "binary": "nova-compute",
        "zone": "nova",
        "state": "up",
        "updated_at": "2013-07-08T05:20:51.000000",
        "host": "devstack001",
        "disabled_reason": None,
    })

    service_3 = services.Service(services.ServiceManager(None), {
        "status": "enabled",
        "binary": "nova-compute",
        "zone": "nova",
        "state": "down",
        "updated_at": "2013-07-08T04:20:51.000000",
        "host": "devstack002",
        "disabled_reason": None,
    })

    service_4 = services.Service(services.ServiceManager(None), {
        "status": "disabled",
        "binary": "nova-compute",
        "zone": "nova",
        "state": "up",
        "updated_at": "2013-07-08T04:20:51.000000",
        "host": "devstack003",
        "disabled_reason": None,
    })

    TEST.services.add(service_1)
    TEST.services.add(service_2)
    TEST.services.add(service_3)
    TEST.services.add(service_4)

    # Aggregates
    aggregate_1 = aggregates.Aggregate(aggregates.AggregateManager(None), {
        "name": "foo",
        "availability_zone": "testing",
        "deleted": 0,
        "created_at": "2013-07-04T13:34:38.000000",
        "updated_at": None,
        "hosts": ["foo", "bar"],
        "deleted_at": None,
        "id": 1,
        "metadata": {"foo": "testing", "bar": "testing"},
    })

    aggregate_2 = aggregates.Aggregate(aggregates.AggregateManager(None), {
        "name": "bar",
        "availability_zone": "testing",
        "deleted": 0,
        "created_at": "2013-07-04T13:34:38.000000",
        "updated_at": None,
        "hosts": ["foo", "bar"],
        "deleted_at": None,
        "id": 2,
        "metadata": {"foo": "testing", "bar": "testing"},
    })

    TEST.aggregates.add(aggregate_1)
    TEST.aggregates.add(aggregate_2)

    server_group_1 = server_groups.ServerGroup(
        server_groups.ServerGroupsManager(None),
        {
            "id": "1",
            "name": "server_group_1",
            "policies": [],
        },
    )

    server_group_2 = server_groups.ServerGroup(
        server_groups.ServerGroupsManager(None),
        {
            "id": "2",
            "name": "server_group_2",
            "policies": ["affinity", "some_other_policy"],
        },
    )

    server_group_3 = server_groups.ServerGroup(
        server_groups.ServerGroupsManager(None),
        {
            "id": "3",
            "name": "server_group_3",
            "policies": ["anti-affinity", "some_other_policy"],
        },
    )

    TEST.server_groups.add(server_group_1)
    TEST.server_groups.add(server_group_2)
    TEST.server_groups.add(server_group_3)
コード例 #6
0
def data(TEST):
    TEST.cinder_services = utils.TestDataContainer()
    TEST.cinder_volumes = utils.TestDataContainer()
    TEST.cinder_volume_backups = utils.TestDataContainer()
    TEST.cinder_volume_encryption_types = utils.TestDataContainer()
    TEST.cinder_volume_types = utils.TestDataContainer()
    TEST.cinder_volume_encryption = utils.TestDataContainer()
    TEST.cinder_bootable_volumes = utils.TestDataContainer()
    TEST.cinder_qos_specs = utils.TestDataContainer()
    TEST.cinder_qos_spec_associations = utils.TestDataContainer()
    TEST.cinder_volume_snapshots = utils.TestDataContainer()
    TEST.cinder_quotas = utils.TestDataContainer()
    TEST.cinder_quota_usages = utils.TestDataContainer()
    TEST.cinder_availability_zones = utils.TestDataContainer()
    TEST.cinder_volume_transfers = utils.TestDataContainer()
    TEST.cinder_pools = utils.TestDataContainer()

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-scheduler",
            "status": "enabled",
            "binary": "cinder-scheduler",
            "zone": "internal",
            "state": "up",
            "updated_at": "2013-07-08T05:21:00.000000",
            "host": "devstack001",
            "disabled_reason": None
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-volume",
            "status": "enabled",
            "binary": "cinder-volume",
            "zone": "nova",
            "state": "up",
            "updated_at": "2013-07-08T05:20:51.000000",
            "host": "devstack001",
            "disabled_reason": None
        })
    TEST.cinder_services.add(service_1)
    TEST.cinder_services.add(service_2)

    # Volumes - Cinder v1
    volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
            'status': 'available',
            'size': 40,
            'display_name': 'Volume name',
            'display_description': 'Volume description',
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'attachments': []
        })
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            "id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce",
            "status": 'available',
            "size": 10,
            "display_name": '',
            "display_description": '',
            "device": "/dev/hda",
            "created_at": '2010-11-21 18:34:25',
            "volume_type": 'vol_type_1',
            "attachments": []
        })
    other_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "21023e92-8008-1234-8059-7f2293ff3889",
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': None,
            'attachments': [{
                "id": "1",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })
    volume_with_type = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "7dcb47fd-07d9-42c2-9647-be5eab799ebe",
            'name': 'my_volume2',
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume2',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': 'vol_type_2',
            'attachments': [{
                "id": "2",
                "server_id": '2',
                "device": "/dev/hdb"
            }]
        })
    non_bootable_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "21023e92-8008-1234-8059-7f2293ff3890",
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': None,
            'bootable': False,
            'attachments': [{
                "id": "1",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    other_volume.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume))
    TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(other_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(volume_with_type))

    TEST.cinder_bootable_volumes.add(api.cinder.Volume(non_bootable_volume))

    vol_type1 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': u'1',
        'name': u'vol_type_1',
        'extra_specs': {
            'foo': 'bar'
        }
    })
    vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': u'2',
        'name': u'vol_type_2'
    })
    TEST.cinder_volume_types.add(vol_type1, vol_type2)

    # Volumes - Cinder v2
    volume_v2 = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "31023e92-8008-4c8b-8059-7f2293ff1234",
            'name': 'v2_volume',
            'description': "v2 Volume Description",
            'status': 'available',
            'size': 20,
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'os-vol-host-attr:host': 'host@backend-name#pool',
            'bootable': 'true',
            'attachments': []
        })
    volume_v2.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume_v2))

    snapshot = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d',
            'display_name': 'test snapshot',
            'display_description': 'volume snapshot',
            'size': 40,
            'status': 'available',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })
    snapshot2 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f',
            'name': '',
            'description': 'v2 volume snapshot description',
            'size': 80,
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    snapshot.bootable = 'true'
    snapshot2.bootable = 'true'

    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))
    TEST.cinder_volume_snapshots.first()._volume = volume

    # Volume Type Encryption
    vol_enc_type1 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {
            'volume_type_id': u'1',
            'control_location': "front-end",
            'key_size': 512,
            'provider': "a-provider",
            'cipher': "a-cipher"
        })
    vol_enc_type2 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {
            'volume_type_id': u'2',
            'control_location': "front-end",
            'key_size': 256,
            'provider': "a-provider",
            'cipher': "a-cipher"
        })
    vol_unenc_type1 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {})
    TEST.cinder_volume_encryption_types.add(vol_enc_type1, vol_enc_type2,
                                            vol_unenc_type1)

    volume_backup1 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31',
            'name': 'backup1',
            'description': 'volume backup 1',
            'size': 10,
            'status': 'available',
            'container_name': 'volumebackups',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })

    volume_backup2 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e52',
            'name': 'backup2',
            'description': 'volume backup 2',
            'size': 20,
            'status': 'available',
            'container_name': 'volumebackups',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    TEST.cinder_volume_backups.add(volume_backup1)
    TEST.cinder_volume_backups.add(volume_backup2)

    # Volume Encryption
    vol_enc_metadata1 = volumes.Volume(
        volumes.VolumeManager(None), {
            'cipher': 'test-cipher',
            'key_size': 512,
            'provider': 'test-provider',
            'control_location': 'front-end'
        })
    vol_unenc_metadata1 = volumes.Volume(volumes.VolumeManager(None), {})
    TEST.cinder_volume_encryption.add(vol_enc_metadata1)
    TEST.cinder_volume_encryption.add(vol_unenc_metadata1)

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.cinder_quotas.add(api.base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(api.base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)

    # Availability Zones
    # Cinder returns the following structure from os-availability-zone
    # {"availabilityZoneInfo":
    # [{"zoneState": {"available": true}, "zoneName": "nova"}]}
    # Note that the default zone is still "nova" even though this is cinder
    TEST.cinder_availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None), {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                }
            }))
    # Cinder Limits
    limits = {
        "absolute": {
            "totalVolumesUsed": 1,
            "totalGigabytesUsed": 5,
            "maxTotalVolumeGigabytes": 1000,
            "maxTotalVolumes": 10
        }
    }
    TEST.cinder_limits = limits

    # QOS Specs
    qos_spec1 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "418db45d-6992-4674-b226-80aacad2073c",
            "name": "high_iops",
            "consumer": "back-end",
            "specs": {
                "minIOPS": "1000",
                "maxIOPS": '100000'
            }
        })
    qos_spec2 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "6ed7035f-992e-4075-8ed6-6eff19b3192d",
            "name": "high_bws",
            "consumer": "back-end",
            "specs": {
                "maxBWS": '5000'
            }
        })

    TEST.cinder_qos_specs.add(qos_spec1, qos_spec2)
    vol_type1.associated_qos_spec = qos_spec1.name
    TEST.cinder_qos_spec_associations.add(vol_type1)

    # volume_transfers
    transfer_1 = volume_transfers.VolumeTransfer(
        volume_transfers.VolumeTransferManager(None), {
            'id': '99999999-8888-7777-6666-555555555555',
            'name': 'test transfer',
            'volume_id': volume.id,
            'auth_key': 'blah',
            'created_at': ''
        })
    TEST.cinder_volume_transfers.add(transfer_1)

    # Pools
    pool1 = pools.Pool(
        pools.PoolManager(None), {
            "QoS_support": False,
            "allocated_capacity_gb": 0,
            "driver_version": "3.0.0",
            "free_capacity_gb": 10,
            "extra_specs": {
                "description": "LVM Extra specs",
                "display_name": "LVMDriver",
                "namespace": "OS::Cinder::LVMDriver",
                "type": "object",
            },
            "name": "devstack@lvmdriver-1#lvmdriver-1",
            "pool_name": "lvmdriver-1",
            "reserved_percentage": 0,
            "storage_protocol": "iSCSI",
            "total_capacity_gb": 10,
            "vendor_name": "Open Source",
            "volume_backend_name": "lvmdriver-1"
        })

    pool2 = pools.Pool(
        pools.PoolManager(None), {
            "QoS_support": False,
            "allocated_capacity_gb": 2,
            "driver_version": "3.0.0",
            "free_capacity_gb": 15,
            "extra_specs": {
                "description": "LVM Extra specs",
                "display_name": "LVMDriver",
                "namespace": "OS::Cinder::LVMDriver",
                "type": "object",
            },
            "name": "devstack@lvmdriver-2#lvmdriver-2",
            "pool_name": "lvmdriver-2",
            "reserved_percentage": 0,
            "storage_protocol": "iSCSI",
            "total_capacity_gb": 10,
            "vendor_name": "Open Source",
            "volume_backend_name": "lvmdriver-2"
        })

    TEST.cinder_pools.add(pool1)
    TEST.cinder_pools.add(pool2)
コード例 #7
0
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.agents = utils.TestDataContainer()
    TEST.networks = utils.TestDataContainer()
    TEST.subnets = utils.TestDataContainer()
    TEST.subnetpools = utils.TestDataContainer()
    TEST.ports = utils.TestDataContainer()
    TEST.trunks = utils.TestDataContainer()
    TEST.routers = utils.TestDataContainer()
    TEST.routers_with_rules = utils.TestDataContainer()
    TEST.routers_with_routes = utils.TestDataContainer()
    TEST.floating_ips = utils.TestDataContainer()
    TEST.security_groups = utils.TestDataContainer()
    TEST.security_group_rules = utils.TestDataContainer()
    TEST.providers = utils.TestDataContainer()
    TEST.pools = utils.TestDataContainer()
    TEST.vips = utils.TestDataContainer()
    TEST.members = utils.TestDataContainer()
    TEST.monitors = utils.TestDataContainer()
    TEST.neutron_quotas = utils.TestDataContainer()
    TEST.neutron_quota_usages = utils.TestDataContainer()
    TEST.ip_availability = utils.TestDataContainer()
    TEST.qos_policies = utils.TestDataContainer()
    TEST.tp_ports = utils.TestDataContainer()
    TEST.neutron_availability_zones = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_agents = utils.TestDataContainer()
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = utils.TestDataContainer()
    TEST.api_subnetpools = utils.TestDataContainer()
    TEST.api_ports = utils.TestDataContainer()
    TEST.api_trunks = utils.TestDataContainer()
    TEST.api_routers = utils.TestDataContainer()
    TEST.api_routers_with_routes = utils.TestDataContainer()
    TEST.api_floating_ips = utils.TestDataContainer()
    TEST.api_security_groups = utils.TestDataContainer()
    TEST.api_security_group_rules = utils.TestDataContainer()
    TEST.api_pools = utils.TestDataContainer()
    TEST.api_vips = utils.TestDataContainer()
    TEST.api_members = utils.TestDataContainer()
    TEST.api_monitors = utils.TestDataContainer()
    TEST.api_extensions = utils.TestDataContainer()
    TEST.api_ip_availability = utils.TestDataContainer()
    TEST.api_qos_policies = utils.TestDataContainer()
    TEST.api_tp_trunks = utils.TestDataContainer()
    TEST.api_tp_ports = utils.TestDataContainer()

    # 1st network.
    network_dict = {
        'admin_state_up':
        True,
        'id':
        '82288d84-e0a5-42ac-95be-e6af08727e42',
        'name':
        'net1',
        'status':
        'ACTIVE',
        'subnets': [
            'e8abc972-eb0c-41f1-9edd-4bc6e3bcd8c9',
            '41e53a49-442b-4307-9e9a-88967a6b6657'
        ],
        'tenant_id':
        '1',
        'router:external':
        False,
        'shared':
        False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': '10.0.0.254',
            'start': '10.0.0.2'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': '10.0.0.0/24',
        'enable_dhcp': True,
        'gateway_ip': '10.0.0.1',
        'id': network_dict['subnets'][0],
        'ip_version': 4,
        'name': 'mysubnet1',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id']
    }
    subnetv6_dict = {
        'allocation_pools': [{
            'start': 'fdb6:b88a:488e::2',
            'end': 'fdb6:b88a:488e:0:ffff:ffff:ffff:ffff'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr':
        'fdb6:b88a:488e::/64',
        'enable_dhcp':
        True,
        'gateway_ip':
        'fdb6:b88a:488e::1',
        'id':
        network_dict['subnets'][1],
        'ip_version':
        6,
        'name':
        'myv6subnet',
        'network_id':
        network_dict['id'],
        'tenant_id':
        network_dict['tenant_id'],
        'ipv6_ra_mode':
        'slaac',
        'ipv6_address_mode':
        'slaac'
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)
    TEST.api_subnets.add(subnetv6_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    subnetv6 = neutron.Subnet(subnetv6_dict)
    network['subnets'] = [subnet, subnetv6]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)
    TEST.subnets.add(subnetv6)

    # Ports on 1st network.
    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        'af75c8e5-a1cc-4567-8d04-44fcd6922890',
        'device_owner':
        'network:dhcp',
        'fixed_ips': [{
            'ip_address': '10.0.0.3',
            'subnet_id': subnet_dict['id']
        }],
        'id':
        '063cf7f3-ded1-4297-bc4c-31eae876cc91',
        'mac_address':
        'fa:16:3e:9c:d5:7e',
        'name':
        '',
        'network_id':
        network_dict['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        network_dict['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'allowed_address_pairs': [{
            'ip_address': '174.0.0.201',
            'mac_address': 'fa:16:3e:7a:7b:18'
        }],
        'port_security_enabled':
        True,
        'security_groups': [],
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '1',
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': '10.0.0.4',
            'subnet_id': subnet_dict['id']
        }, {
            'ip_address': 'fdb6:b88a:488e:0:f816:3eff:fe9d:e62f',
            'subnet_id': subnetv6_dict['id']
        }],
        'id':
        '7e6ce62c-7ea2-44f8-b6b4-769af90a8406',
        'mac_address':
        'fa:16:3e:9d:e6:2f',
        'name':
        '',
        'network_id':
        network_dict['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        network_dict['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'port_security_enabled':
        True,
        'security_groups': [
            # sec_group_1 ID below
            'faad7c80-3b62-4440-967c-13808c37131d',
            # sec_group_2 ID below
            '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d'
        ],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))
    assoc_port = port_dict

    port_dict = {
        'admin_state_up': True,
        'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'device_owner': 'network:router_interface',
        'fixed_ips': [{
            'ip_address': '10.0.0.1',
            'subnet_id': subnet_dict['id']
        }],
        'id': '9036eedb-e7fa-458e-bc6e-d9d06d9d1bc4',
        'mac_address': 'fa:16:3e:9c:d5:7f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))
    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'device_owner':
        'network:router_interface',
        'fixed_ips': [{
            'ip_address': 'fdb6:b88a:488e::1',
            'subnet_id': subnetv6_dict['id']
        }],
        'id':
        '8047e0d5-5ef5-4b6e-a1a7-d3a52ad980f7',
        'mac_address':
        'fa:16:3e:69:6e:e9',
        'name':
        '',
        'network_id':
        network_dict['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        network_dict['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # 2nd network.
    network_dict = {
        'admin_state_up': True,
        'id': '72c3ab6c-c80f-4341-9dc5-210fa31ac6c2',
        'name': 'net2',
        'status': 'ACTIVE',
        'subnets': ['3f7c5d79-ee55-47b0-9213-8e669fb03009'],
        'tenant_id': '2',
        'router:external': False,
        'shared': True
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': '172.16.88.254',
            'start': '172.16.88.2'
        }],
        'dns_nameservers': ['10.56.1.20', '10.56.1.21'],
        'host_routes': [{
            'destination': '192.168.20.0/24',
            'nexthop': '172.16.88.253'
        }, {
            'destination': '192.168.21.0/24',
            'nexthop': '172.16.88.252'
        }],
        'cidr':
        '172.16.88.0/24',
        'enable_dhcp':
        True,
        'gateway_ip':
        '172.16.88.1',
        'id':
        '3f7c5d79-ee55-47b0-9213-8e669fb03009',
        'ip_version':
        4,
        'name':
        'aaaa',
        'network_id':
        network_dict['id'],
        'tenant_id':
        network_dict['tenant_id']
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '2',
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': '172.16.88.3',
            'subnet_id': subnet_dict['id']
        }],
        'id':
        '1db2cc37-3553-43fa-b7e2-3fc4eb4f9905',
        'mac_address':
        'fa:16:3e:56:e6:2f',
        'name':
        '',
        'network_id':
        network_dict['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        network_dict['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [
            # sec_group_1 ID below
            'faad7c80-3b62-4440-967c-13808c37131d',
        ],
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # External network.
    network_dict = {
        'admin_state_up': True,
        'id': '9b466b94-213a-4cda-badf-72c102a874da',
        'name': 'ext_net',
        'status': 'ACTIVE',
        'subnets': ['d6bdc71c-7566-4d32-b3ff-36441ce746e8'],
        'tenant_id': '3',
        'router:external': True,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'start': '172.24.4.226.',
            'end': '172.24.4.238'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': '172.24.4.0/28',
        'enable_dhcp': False,
        'gateway_ip': '172.24.4.225',
        'id': 'd6bdc71c-7566-4d32-b3ff-36441ce746e8',
        'ip_version': 4,
        'name': 'ext_subnet',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id']
    }
    ext_net = network_dict

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 1st v6 network.
    network_dict = {
        'admin_state_up': True,
        'id': '96688ea1-ffa5-78ec-22ca-33aaabfaf775',
        'name': 'v6_net1',
        'status': 'ACTIVE',
        'subnets': ['88ddd443-4377-ab1f-87dd-4bc4a662dbb6'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': 'ff09::ff',
            'start': 'ff09::02'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': 'ff09::/64',
        'enable_dhcp': True,
        'gateway_ip': 'ff09::1',
        'id': network_dict['subnets'][0],
        'ip_version': 6,
        'name': 'v6_subnet1',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id'],
        'ipv6_modes': 'none/none'
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 2nd v6 network - slaac.
    network_dict = {
        'admin_state_up': True,
        'id': 'c62e4bb3-296a-4cd1-8f6b-aaa7a0092326',
        'name': 'v6_net2',
        'status': 'ACTIVE',
        'subnets': ['5d736a21-0036-4779-8f8b-eed5f98077ec'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': 'ff09::ff',
            'start': 'ff09::02'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': 'ff09::/64',
        'enable_dhcp': True,
        'gateway_ip': 'ff09::1',
        'id': network_dict['subnets'][0],
        'ip_version': 6,
        'name': 'v6_subnet2',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id'],
        'ipv6_modes': 'slaac/slaac'
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Set up router data.
    port_dict = {
        'admin_state_up': True,
        'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
        'device_owner': 'network:router_gateway',
        'fixed_ips': [{
            'ip_address': '10.0.0.3',
            'subnet_id': subnet_dict['id']
        }],
        'id': '44ec6726-4bdc-48c5-94d4-df8d1fbf613b',
        'mac_address': 'fa:16:3e:9c:d5:7e',
        'name': '',
        'network_id': TEST.networks.get(name="ext_net")['id'],
        'status': 'ACTIVE',
        'tenant_id': '1',
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    trunk_dict = {
        'status': 'UP',
        'sub_ports': [],
        'name': 'trunk1',
        'admin_state_up': True,
        'tenant_id': '1',
        'project_id': '1',
        'port_id': '895d375c-1447-11e7-a52f-f7f280bbc809',
        'id': '94fcb9e8-1447-11e7-bed6-8b8c4ac74491'
    }

    TEST.api_trunks.add(trunk_dict)
    TEST.trunks.add(neutron.Trunk(trunk_dict))

    router_dict = {
        'id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'name': 'router1',
        'status': 'ACTIVE',
        'admin_state_up': True,
        'distributed': True,
        'external_gateway_info': {
            'network_id': ext_net['id']
        },
        'tenant_id': '1',
        'availability_zone_hints': ['nova']
    }
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {
        'id': '10e3dc42-1ce1-4d48-87cf-7fc333055d6c',
        'name': 'router2',
        'status': 'ACTIVE',
        'admin_state_up': False,
        'distributed': False,
        'external_gateway_info': None,
        'tenant_id': '1'
    }
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {
        'id':
        '7180cede-bcd8-4334-b19f-f7ef2f331f53',
        'name':
        'rulerouter',
        'status':
        'ACTIVE',
        'admin_state_up':
        True,
        'distributed':
        False,
        'external_gateway_info': {
            'network_id': ext_net['id']
        },
        'tenant_id':
        '1',
        'router_rules': [{
            'id': '101',
            'action': 'deny',
            'source': 'any',
            'destination': 'any',
            'nexthops': []
        }, {
            'id': '102',
            'action': 'permit',
            'source': 'any',
            'destination': '8.8.8.8/32',
            'nexthops': ['1.0.0.2', '1.0.0.1']
        }]
    }
    TEST.api_routers.add(router_dict)
    TEST.routers_with_rules.add(neutron.Router(router_dict))
    router_dict_with_route = {
        'id':
        '725c24c9-061b-416b-b9d4-012392b32fd9',
        'name':
        'routerouter',
        'status':
        'ACTIVE',
        'admin_state_up':
        True,
        'distributed':
        False,
        'external_gateway_info': {
            'network_id': ext_net['id']
        },
        'tenant_id':
        '1',
        'routes': [{
            'nexthop': '10.0.0.1',
            'destination': '172.0.0.0/24'
        }, {
            'nexthop': '10.0.0.2',
            'destination': '172.1.0.0/24'
        }]
    }
    TEST.api_routers_with_routes.add(router_dict_with_route)
    TEST.routers_with_routes.add(neutron.Router(router_dict_with_route))

    # Floating IP.
    # Unassociated.
    fip_dict = {
        'tenant_id': '1',
        'floating_ip_address': '172.16.88.227',
        'floating_network_id': ext_net['id'],
        'id': '9012cd70-cfae-4e46-b71e-6a409e9e0063',
        'fixed_ip_address': None,
        'port_id': None,
        'router_id': None
    }
    TEST.api_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': None, 'instance_type': None})
    TEST.floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Associated (with compute port on 1st network).
    fip_dict = {
        'tenant_id': '1',
        'floating_ip_address': '172.16.88.228',
        'floating_network_id': ext_net['id'],
        'id': 'a97af8f2-3149-4b97-abbd-e49ad19510f7',
        'fixed_ip_address': assoc_port['fixed_ips'][0]['ip_address'],
        'port_id': assoc_port['id'],
        'router_id': router_dict['id']
    }
    TEST.api_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': '1', 'instance_type': 'compute'})
    TEST.floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Security group.

    sec_group_1 = {
        'tenant_id': '1',
        'description': 'default',
        'id': 'faad7c80-3b62-4440-967c-13808c37131d',
        'name': 'default'
    }
    sec_group_2 = {
        'tenant_id': '1',
        'description': 'NotDefault',
        'id': '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d',
        'name': 'other_group'
    }
    sec_group_3 = {
        'tenant_id': '1',
        'description': 'NotDefault',
        'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95',
        'name': 'another_group'
    }

    def add_rule_to_group(secgroup, default_only=True):
        rule_egress_ipv4 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress',
            'ethertype': u'IPv4',
            'port_range_min': None,
            'port_range_max': None,
            'protocol': None,
            'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_egress_ipv6 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress',
            'ethertype': u'IPv6',
            'port_range_min': None,
            'port_range_max': None,
            'protocol': None,
            'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }

        rule_tcp_80 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 80,
            'port_range_max': 80,
            'protocol': u'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_icmp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 5,
            'port_range_max': 8,
            'protocol': u'icmp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_group = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 80,
            'port_range_max': 80,
            'protocol': u'tcp',
            'remote_group_id': sec_group_1['id'],
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_all_tcp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress',
            'ethertype': u'IPv4',
            'port_range_min': 1,
            'port_range_max': 65535,
            'protocol': u'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/24',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }

        rules = []
        if not default_only:
            rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp]
        rules += [rule_egress_ipv4, rule_egress_ipv6]
        secgroup['security_group_rules'] = rules

    add_rule_to_group(sec_group_1, default_only=False)
    add_rule_to_group(sec_group_2)
    add_rule_to_group(sec_group_3)

    groups = [sec_group_1, sec_group_2, sec_group_3]
    sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups])
    for sg in groups:
        # Neutron API.
        TEST.api_security_groups.add(sg)
        for rule in sg['security_group_rules']:
            TEST.api_security_group_rules.add(copy.copy(rule))
        # OpenStack Dashboard internaly API.
        TEST.security_groups.add(
            neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))
        for rule in sg['security_group_rules']:
            TEST.security_group_rules.add(
                neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict))

    # Subnetpools

    # 1st subnetpool
    subnetpool_dict = {
        'default_prefixlen': 24,
        'default_quota': None,
        'id': '419eb314-e244-4088-aed7-851af9d9500d',
        'ip_version': 4,
        'max_prefixlen': 32,
        'min_prefixlen': 12,
        'name': 'mysubnetpool1',
        'prefixes': ['172.16.0.0/12'],
        'shared': False,
        'tenant_id': '1'
    }

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # 2nd subnetpool (v6)
    subnetpool_dict = {
        'default_prefixlen': 64,
        'default_quota': None,
        'id': 'dcdad289-46f3-4298-bec6-41d91c942efa',
        'ip_version': 6,
        'max_prefixlen': 64,
        'min_prefixlen': 60,
        'name': 'mysubnetpool2',
        'prefixes': ['2001:db8:42::/48'],
        'shared': False,
        'tenant_id': '1'
    }

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # Quotas.
    quota_data = {
        'network': '10',
        'subnet': '10',
        'port': '50',
        'router': '10',
        'floatingip': '50',
        'security_group': '20',
        'security_group_rule': '100',
    }
    TEST.neutron_quotas.add(base.QuotaSet(quota_data))

    # Quota Usages
    quota_usage_data = {
        'networks': {
            'used': 0,
            'quota': 5
        },
        'subnets': {
            'used': 0,
            'quota': 5
        },
        'ports': {
            'used': 0,
            'quota': 5
        },
        'routers': {
            'used': 0,
            'quota': 5
        },
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.neutron_quota_usages.add(quota_usage)

    # Extensions.
    extension_1 = {
        "name": "security-group",
        "alias": "security-group",
        "description": "The security groups extension."
    }
    extension_2 = {
        "name": "Quota management support",
        "alias": "quotas",
        "description": "Expose functions for quotas management"
    }
    extension_3 = {
        "name": "Provider network",
        "alias": "provider",
        "description": "Provider network extension"
    }
    extension_4 = {
        "name": "Distributed Virtual Router",
        "alias": "dvr",
        "description": "Enables configuration of Distributed Virtual Routers."
    }
    extension_5 = {
        "name": "HA Router extension",
        "alias": "l3-ha",
        "description": "Add HA capability to routers."
    }
    extension_6 = {
        "name": "Trunks",
        "alias": "trunk",
        "description": "Provides support for trunk ports."
    }
    TEST.api_extensions.add(extension_1)
    TEST.api_extensions.add(extension_2)
    TEST.api_extensions.add(extension_3)
    TEST.api_extensions.add(extension_4)
    TEST.api_extensions.add(extension_5)
    TEST.api_extensions.add(extension_6)

    # 1st agent.
    agent_dict = {
        "binary": "neutron-openvswitch-agent",
        "description": None,
        "admin_state_up": True,
        "heartbeat_timestamp": "2013-07-26 06:51:47",
        "alive": True,
        "id": "c876ff05-f440-443e-808c-1d34cda3e88a",
        "topic": "N/A",
        "host": "devstack001",
        "agent_type": "Open vSwitch agent",
        "started_at": "2013-07-26 05:23:28",
        "created_at": "2013-07-26 05:23:28",
        "configurations": {
            "devices": 2
        }
    }
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # 2nd agent.
    agent_dict = {
        "binary": "neutron-dhcp-agent",
        "description": None,
        "admin_state_up": True,
        "heartbeat_timestamp": "2013-07-26 06:51:48",
        "alive": True,
        "id": "f0d12e3d-1973-41a2-b977-b95693f9a8aa",
        "topic": "dhcp_agent",
        "host": "devstack001",
        "agent_type": "DHCP agent",
        "started_at": "2013-07-26 05:23:30",
        "created_at": "2013-07-26 05:23:30",
        "configurations": {
            "subnets": 1,
            "use_namespaces": True,
            "dhcp_lease_duration": 120,
            "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq",
            "networks": 1,
            "ports": 1
        }
    }
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # Service providers.
    provider_1 = {
        "service_type": "LOADBALANCER",
        "name": "haproxy",
        "default": True
    }
    TEST.providers.add(provider_1)

    # ports on 4th network
    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '9872faaa-b2b2-eeee-9911-21332eedaa77',
        'device_owner':
        'network:dhcp',
        'fixed_ips': [{
            'ip_address': '11.10.0.3',
            'subnet_id': TEST.subnets.first().id
        }],
        'id':
        'a21dcd22-6733-cccc-aa32-22adafaf16a2',
        'mac_address':
        '78:22:ff:1a:ba:23',
        'name':
        'port5',
        'network_id':
        TEST.networks.first().id,
        'status':
        'ACTIVE',
        'tenant_id':
        TEST.networks.first().tenant_id,
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    availability = {
        'network_ip_availability': {
            'used_ips':
            2,
            'subnet_ip_availability': [{
                'used_ips': 1,
                'subnet_id': '2c90f321-9cc7-41b4-a3cf-88110f120a94',
                'subnet_name': 'ipv6-public-subnet',
                'ip_version': 6,
                'cidr': '2001:db8::/64',
                'total_ips': 18446744073709551614
            }, {
                'used_ips': 1,
                'subnet_id': '4d77d5fb-c26c-4ac5-b2ca-fca2f89b0fc1',
                'subnet_name': 'public-subnet',
                'ip_version': 4,
                'cidr': '172.24.4.0/24',
                'total_ips': 253
            }],
            'network_id':
            'd87d5be5-cfca-486f-8db5-a446330e4513',
            'tenant_id':
            'd564b2a4fc0544fb89f8a0434dd96863',
            'network_name':
            'public',
            'total_ips':
            18446744073709551867
        }
    }

    TEST.ip_availability.add(availability)
    TEST.api_ip_availability.add(availability)

    # qos policies
    policy_dict = {
        'id': 'a21dcd22-7189-cccc-aa32-22adafaf16a7',
        'name': 'policy 1',
        'tenant_id': '1'
    }
    TEST.api_qos_policies.add(policy_dict)
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict))
    policy_dict1 = {
        'id': 'a21dcd22-7189-ssss-aa32-22adafaf16a7',
        'name': 'policy 2',
        'tenant_id': '1'
    }
    TEST.api_qos_policies.add(policy_dict1)
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict1))

    # TRUNKPORT
    #
    #  The test setup was created by the following command sequence:
    #    openstack network create tst
    #    openstack subnet create tstsub --network tst\
    #    --subnet-range 10.10.16.128/26
    #    openstack network create tstalt
    #    openstack subnet create tstaltsub --network tstalt\
    #    --subnet-range 10.10.17.128/26
    #    openstack port create --network tst plain
    #    openstack port create --network tst parent
    #    openstack port create --network tst child1
    #    openstack port create --network tstalt child2
    #    openstack network trunk create --parent-port parent trunk
    #    openstack network trunk set\
    #    --subport port=child1,segmentation-type=vlan,segmentation-id=100 trunk
    #    openstack network trunk set\
    #    --subport port=child2,segmentation-type=vlan,segmentation-id=200 trunk
    #   ids/uuids are captured from a live setup.

    # This collection holds the test setup.
    tdata = {
        'tenant_id': '19c9123a944644cb9e923497a018d0b7',
        'trunk_id': '920625a3-13de-46b4-b6c9-8b35f29b3cfe',
        'security_group': '3fd8c007-9093-4aa3-b475-a0c178d4e1e4',
        'tag_1': 100,
        'tag_2': 200,
        'net': {
            'tst_id': '5a340332-cc92-42aa-8980-15f47c0d0f3d',
            'tstalt_id': '0fb41ffd-3933-4da4-8a83-025d328aedf3'
        },
        'subnet': {
            'tst_id': '0b883baf-5a21-4605-ab56-229a24ec585b',
            'tstalt_id': '0e184cf2-97dc-4738-b4b3-1871faf5d685'
        },
        'child1': {
            'id': '9c151ffb-d7a6-4f15-8eae-d0950999fdfe',
            'ip': '10.10.16.140',
            'mac': 'fa:16:3e:22:63:6f',
            'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61'
        },
        'child2': {
            'id': 'cedb145f-c163-4630-98a3-e1990744bdef',
            'ip': '10.10.17.137',
            'mac': 'fa:16:3e:0d:ca:eb',
            'device_id': '9872faaa-b2b2-eeee-9911-21332eedaa77'
        },
        'parent': {
            'id': '5b27429d-048b-40fa-88f9-8e2c4ff7d28b',
            'ip': '10.10.16.141',
            'mac': 'fa:16:3e:ab:a8:22',
            'device_id': 'af75c8e5-a1cc-4567-8d04-44fcd6922890'
        },
        'plain': {
            'id': 'bc04da56-d7fc-461e-b95d-a2c66e77ad9a',
            'ip': '10.10.16.135',
            'mac': 'fa:16:3e:9c:d5:7f',
            'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53'
        }
    }

    #  network tst

    #    trunk
    tp_trunk_dict = {
        'status':
        'UP',
        'sub_ports': [{
            'segmentation_type': 'vlan',
            'segmentation_id': tdata['tag_1'],
            'port_id': tdata['child1']['id']
        }, {
            'segmentation_type': u'vlan',
            'segmentation_id': tdata['tag_2'],
            'port_id': tdata['child2']['id']
        }],
        'name':
        'trunk',
        'admin_state_up':
        True,
        'tenant_id':
        tdata['tenant_id'],
        'project_id':
        tdata['tenant_id'],
        'port_id':
        tdata['parent']['id'],
        'id':
        tdata['trunk_id']
    }
    TEST.api_tp_trunks.add(tp_trunk_dict)

    #    port parent
    parent_port_dict = {
        'admin_state_up':
        True,
        'device_id':
        tdata['parent']['device_id'],
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': tdata['parent']['ip'],
            'subnet_id': tdata['subnet']['tst_id']
        }],
        'id':
        tdata['parent']['id'],
        'mac_address':
        tdata['parent']['mac'],
        'name':
        'parent',
        'network_id':
        tdata['net']['tst_id'],
        'status':
        'ACTIVE',
        'tenant_id':
        tdata['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [tdata['security_group']],
        'trunk_details': {
            'sub_ports': [{
                'segmentation_type': 'vlan',
                'mac_address': tdata['child1']['mac'],
                'segmentation_id': tdata['tag_1'],
                'port_id': tdata['child1']['id']
            }, {
                'segmentation_type': 'vlan',
                'mac_address': tdata['child2']['mac'],
                'segmentation_id': tdata['tag_2'],
                'port_id': tdata['child2']['id']
            }],
            'trunk_id':
            tdata['trunk_id']
        }
    }
    TEST.api_tp_ports.add(parent_port_dict)
    TEST.tp_ports.add(neutron.PortTrunkParent(parent_port_dict))

    #    port child1
    child1_port_dict = {
        'admin_state_up':
        True,
        'device_id':
        tdata['child1']['device_id'],
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': tdata['child1']['ip'],
            'subnet_id': tdata['subnet']['tst_id']
        }],
        'id':
        tdata['child1']['id'],
        'mac_address':
        tdata['child1']['mac'],
        'name':
        'child1',
        'network_id':
        tdata['net']['tst_id'],
        'status':
        'ACTIVE',
        'tenant_id':
        tdata['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [tdata['security_group']]
    }
    TEST.api_tp_ports.add(child1_port_dict)
    TEST.tp_ports.add(
        neutron.PortTrunkSubport(
            child1_port_dict, {
                'trunk_id': tdata['trunk_id'],
                'segmentation_type': 'vlan',
                'segmentation_id': tdata['tag_1']
            }))

    #    port plain
    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        tdata['plain']['device_id'],
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': tdata['plain']['ip'],
            'subnet_id': tdata['subnet']['tst_id']
        }],
        'id':
        tdata['plain']['id'],
        'mac_address':
        tdata['plain']['mac'],
        'name':
        'plain',
        'network_id':
        tdata['net']['tst_id'],
        'status':
        'ACTIVE',
        'tenant_id':
        tdata['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [tdata['security_group']]
    }
    TEST.api_tp_ports.add(port_dict)
    TEST.tp_ports.add(neutron.Port(port_dict))

    #  network tstalt

    #    port child2
    child2_port_dict = {
        'admin_state_up':
        True,
        'device_id':
        tdata['child2']['device_id'],
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': tdata['child2']['ip'],
            'subnet_id': tdata['subnet']['tstalt_id']
        }],
        'id':
        tdata['child2']['id'],
        'mac_address':
        tdata['child2']['mac'],
        'name':
        'child2',
        'network_id':
        tdata['net']['tstalt_id'],
        'status':
        'ACTIVE',
        'tenant_id':
        tdata['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host',
        'security_groups': [tdata['security_group']]
    }
    TEST.api_tp_ports.add(child2_port_dict)
    TEST.tp_ports.add(
        neutron.PortTrunkSubport(
            child2_port_dict, {
                'trunk_id': tdata['trunk_id'],
                'segmentation_type': 'vlan',
                'segmentation_id': tdata['tag_2']
            }))

    # Availability Zones
    TEST.neutron_availability_zones.add({
        'state': 'available',
        'resource': 'router',
        'name': 'nova'
    })
コード例 #8
0
ファイル: cinder_data.py プロジェクト: tomascribb10/horizon
def data(TEST):
    TEST.cinder_messages = utils.TestDataContainer()
    TEST.cinder_services = utils.TestDataContainer()
    TEST.cinder_volumes = utils.TestDataContainer()
    TEST.cinder_volume_backups = utils.TestDataContainer()
    TEST.cinder_volume_encryption_types = utils.TestDataContainer()
    TEST.cinder_volume_types = utils.TestDataContainer()
    TEST.cinder_type_access = utils.TestDataContainer()
    TEST.cinder_volume_encryption = utils.TestDataContainer()
    TEST.cinder_bootable_volumes = utils.TestDataContainer()
    TEST.cinder_qos_specs = utils.TestDataContainer()
    TEST.cinder_qos_spec_associations = utils.TestDataContainer()
    TEST.cinder_volume_snapshots = utils.TestDataContainer()
    TEST.cinder_extensions = utils.TestDataContainer()
    TEST.cinder_quotas = utils.TestDataContainer()
    TEST.cinder_quota_usages = utils.TestDataContainer()
    TEST.cinder_availability_zones = utils.TestDataContainer()
    TEST.cinder_volume_transfers = utils.TestDataContainer()
    TEST.cinder_pools = utils.TestDataContainer()
    TEST.cinder_groups = utils.TestDataContainer()
    TEST.cinder_group_types = utils.TestDataContainer()
    TEST.cinder_group_snapshots = utils.TestDataContainer()
    TEST.cinder_group_volumes = utils.TestDataContainer()
    TEST.cinder_volume_snapshots_with_groups = utils.TestDataContainer()

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-scheduler",
            "status": "enabled",
            "binary": "cinder-scheduler",
            "zone": "internal",
            "state": "up",
            "updated_at": "2013-07-08T05:21:00.000000",
            "host": "devstack001",
            "disabled_reason": None
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-volume",
            "status": "enabled",
            "binary": "cinder-volume",
            "zone": "nova",
            "state": "up",
            "updated_at": "2013-07-08T05:20:51.000000",
            "host": "devstack001",
            "disabled_reason": None
        })
    TEST.cinder_services.add(service_1)
    TEST.cinder_services.add(service_2)

    # Volumes - Cinder v1
    volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
            'status': 'available',
            'size': 40,
            'name': 'Volume name',
            'display_description': 'Volume description',
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'bootable': 'false',
            'attachments': []
        })
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            "id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce",
            "status": 'available',
            "size": 10,
            "name": '',
            "display_description": '',
            "device": "/dev/hda",
            "created_at": '2010-11-21 18:34:25',
            "volume_type": 'vol_type_1',
            'bootable': 'true',
            "attachments": []
        })
    other_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id':
            "21023e92-8008-1234-8059-7f2293ff3889",
            'status':
            'in-use',
            'size':
            10,
            'name':
            u'my_volume',
            'display_description':
            '',
            'created_at':
            '2013-04-01 10:30:00',
            'volume_type':
            None,
            'bootable':
            'true',
            'attachments': [{
                "id": "21023e92-8008-1234-8059-7f2293ff3889",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })
    volume_with_type = volumes.Volume(
        volumes.VolumeManager(None), {
            'id':
            "7dcb47fd-07d9-42c2-9647-be5eab799ebe",
            'name':
            'my_volume2',
            'status':
            'in-use',
            'size':
            10,
            'name':
            u'my_volume2',
            'display_description':
            '',
            'created_at':
            '2013-04-01 10:30:00',
            'volume_type':
            'vol_type_2',
            'bootable':
            'false',
            'attachments': [{
                "id": "7dcb47fd-07d9-42c2-9647-be5eab799ebe",
                "server_id": '2',
                "device": "/dev/hdb"
            }]
        })
    non_bootable_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id':
            "21023e92-8008-1234-8059-7f2293ff3890",
            'status':
            'in-use',
            'size':
            10,
            'name':
            u'my_volume',
            'display_description':
            '',
            'created_at':
            '2013-04-01 10:30:00',
            'volume_type':
            None,
            'bootable':
            'false',
            'attachments': [{
                "id": "21023e92-8008-1234-8059-7f2293ff3890",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    other_volume.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume))
    TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(other_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(volume_with_type))

    TEST.cinder_bootable_volumes.add(api.cinder.Volume(non_bootable_volume))

    vol_type1 = volume_types.VolumeType(
        volume_types.VolumeTypeManager(None), {
            'id': u'1',
            'name': u'vol_type_1',
            'description': 'type 1 description',
            'extra_specs': {
                'foo': 'bar',
                'volume_backend_name': 'backend_1'
            }
        })
    vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': u'2',
        'name': u'vol_type_2',
        'description': 'type 2 description'
    })
    vol_type3 = volume_types.VolumeType(
        volume_types.VolumeTypeManager(None), {
            'id': u'3',
            'name': u'vol_type_3',
            'is_public': False,
            'description': 'type 3 description'
        })
    TEST.cinder_volume_types.add(vol_type1, vol_type2, vol_type3)
    vol_type_access1 = volume_type_access.VolumeTypeAccess(
        volume_type_access.VolumeTypeAccessManager(None), {
            'volume_type_id': u'1',
            'project_id': u'1'
        })
    TEST.cinder_type_access.add(vol_type_access1)

    # Volumes - Cinder v2
    volume_v2 = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "31023e92-8008-4c8b-8059-7f2293ff1234",
            'name': 'v2_volume',
            'description': "v2 Volume Description",
            'status': 'available',
            'size': 20,
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'os-vol-host-attr:host': 'host@backend-name#pool',
            'bootable': 'true',
            'attachments': []
        })
    volume_v2.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume_v2))

    snapshot = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d',
            'display_name': 'test snapshot',
            'display_description': 'volume snapshot',
            'size': 40,
            'created_at': '2014-01-27 10:30:00',
            'status': 'available',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })
    snapshot2 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f',
            'name': '',
            'description': 'v2 volume snapshot description',
            'size': 80,
            'created_at': '2014-01-27 10:30:00',
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })
    snapshot3 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0e',
            'name': '',
            'description': 'v2 volume snapshot description 2',
            'size': 80,
            'created_at': '2014-01-27 10:30:00',
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })
    snapshot4 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'cd6be1eb-82ca-4587-8036-13c37c00c2b1',
            'name': '',
            'description': 'v2 volume snapshot with metadata description',
            'size': 80,
            'created_at': '2014-01-27 10:30:00',
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234',
            'metadata': {
                'snapshot_meta_key': 'snapshot_meta_value'
            }
        })

    snapshot.bootable = 'true'
    snapshot2.bootable = 'true'

    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot3))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot4))
    TEST.cinder_volume_snapshots.first()._volume = volume

    # Volume Type Encryption
    vol_enc_type1 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {
            'volume_type_id': u'1',
            'control_location': "front-end",
            'key_size': 512,
            'provider': "a-provider",
            'cipher': "a-cipher"
        })
    vol_enc_type2 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {
            'volume_type_id': u'2',
            'control_location': "front-end",
            'key_size': 256,
            'provider': "a-provider",
            'cipher': "a-cipher"
        })
    vol_unenc_type1 = vol_enc_types.VolumeEncryptionType(
        vol_enc_types.VolumeEncryptionTypeManager(None), {})
    TEST.cinder_volume_encryption_types.add(vol_enc_type1, vol_enc_type2,
                                            vol_unenc_type1)

    volume_backup1 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31',
            'name': 'backup1',
            'description': 'volume backup 1',
            'size': 10,
            'status': 'available',
            'container_name': 'volumebackups',
            'snapshot_id': None,
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })

    volume_backup2 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e52',
            'name': 'backup2',
            'description': 'volume backup 2',
            'size': 20,
            'status': 'available',
            'snapshot_id': snapshot2.id,
            'container_name': 'volumebackups',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    volume_backup3 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e53',
            'name': 'backup3',
            'description': 'volume backup 3',
            'size': 20,
            'snapshot_id': None,
            'status': 'available',
            'container_name': 'volumebackups',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    TEST.cinder_volume_backups.add(volume_backup1)
    TEST.cinder_volume_backups.add(volume_backup2)
    TEST.cinder_volume_backups.add(volume_backup3)

    # Volume Encryption
    vol_enc_metadata1 = volumes.Volume(
        volumes.VolumeManager(None), {
            'cipher': 'test-cipher',
            'key_size': 512,
            'provider': 'test-provider',
            'control_location': 'front-end'
        })
    vol_unenc_metadata1 = volumes.Volume(volumes.VolumeManager(None), {})
    TEST.cinder_volume_encryption.add(vol_enc_metadata1)
    TEST.cinder_volume_encryption.add(vol_unenc_metadata1)

    # v2 extensions

    extensions = [
        {
            'alias': 'os-services',
            'description': 'Services support.',
            'links': '[]',
            'name': 'Services',
            'updated': '2012-10-28T00:00:00-00:00'
        },
        {
            'alias': 'os-admin-actions',
            'description': 'Enable admin actions.',
            'links': '[]',
            'name': 'AdminActions',
            'updated': '2012-08-25T00:00:00+00:00'
        },
        {
            'alias': 'os-volume-transfer',
            'description': 'Volume transfer management support.',
            'links': '[]',
            'name': 'VolumeTransfer',
            'updated': '2013-05-29T00:00:00+00:00'
        },
    ]
    extensions = [
        cinder_list_extensions.ListExtResource(
            cinder_list_extensions.ListExtManager(None), ext)
        for ext in extensions
    ]
    TEST.cinder_extensions.add(*extensions)

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.cinder_quotas.add(api.base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'volumes': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(api.base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)

    # Availability Zones
    # Cinder returns the following structure from os-availability-zone
    # {"availabilityZoneInfo":
    # [{"zoneState": {"available": true}, "zoneName": "nova"}]}
    # Note that the default zone is still "nova" even though this is cinder
    TEST.cinder_availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None), {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                }
            }))
    # Cinder Limits
    limits = {
        "absolute": {
            "totalVolumesUsed": 4,
            "totalGigabytesUsed": 400,
            'totalSnapshotsUsed': 3,
            "maxTotalVolumes": 20,
            "maxTotalVolumeGigabytes": 1000,
            'maxTotalSnapshots': 10,
        }
    }

    TEST.cinder_limits = limits

    # QOS Specs
    qos_spec1 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "418db45d-6992-4674-b226-80aacad2073c",
            "name": "high_iops",
            "consumer": "back-end",
            "specs": {
                "minIOPS": "1000",
                "maxIOPS": '100000'
            }
        })
    qos_spec2 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "6ed7035f-992e-4075-8ed6-6eff19b3192d",
            "name": "high_bws",
            "consumer": "back-end",
            "specs": {
                "maxBWS": '5000'
            }
        })

    TEST.cinder_qos_specs.add(qos_spec1, qos_spec2)
    vol_type1.associated_qos_spec = qos_spec1.name
    TEST.cinder_qos_spec_associations.add(vol_type1)

    # volume_transfers
    transfer_1 = volume_transfers.VolumeTransfer(
        volume_transfers.VolumeTransferManager(None), {
            'id': '99999999-8888-7777-6666-555555555555',
            'name': 'test transfer',
            'volume_id': volume.id,
            'auth_key': 'blah',
            'created_at': ''
        })
    TEST.cinder_volume_transfers.add(transfer_1)

    # Pools
    pool1 = pools.Pool(
        pools.PoolManager(None), {
            "QoS_support": False,
            "allocated_capacity_gb": 0,
            "driver_version": "3.0.0",
            "free_capacity_gb": 10,
            "extra_specs": {
                "description": "LVM Extra specs",
                "display_name": "LVMDriver",
                "namespace": "OS::Cinder::LVMDriver",
                "type": "object",
            },
            "name": "devstack@lvmdriver-1#lvmdriver-1",
            "pool_name": "lvmdriver-1",
            "reserved_percentage": 0,
            "storage_protocol": "iSCSI",
            "total_capacity_gb": 10,
            "vendor_name": "Open Source",
            "volume_backend_name": "lvmdriver-1"
        })

    pool2 = pools.Pool(
        pools.PoolManager(None), {
            "QoS_support": False,
            "allocated_capacity_gb": 2,
            "driver_version": "3.0.0",
            "free_capacity_gb": 5,
            "extra_specs": {
                "description": "LVM Extra specs",
                "display_name": "LVMDriver",
                "namespace": "OS::Cinder::LVMDriver",
                "type": "object",
            },
            "name": "devstack@lvmdriver-2#lvmdriver-2",
            "pool_name": "lvmdriver-2",
            "reserved_percentage": 0,
            "storage_protocol": "iSCSI",
            "total_capacity_gb": 10,
            "vendor_name": "Open Source",
            "volume_backend_name": "lvmdriver-2"
        })

    TEST.cinder_pools.add(pool1)
    TEST.cinder_pools.add(pool2)

    group_type_1 = group_types.GroupType(
        group_types.GroupTypeManager(None), {
            "is_public": True,
            "group_specs": {},
            "id": "4645cbf7-8aa6-4d42-a5f7-24e6ebe5ba79",
            "name": "group-type-1",
            "description": None,
        })
    TEST.cinder_group_types.add(group_type_1)

    group_1 = groups.Group(
        groups.GroupManager(None), {
            "availability_zone": "nova",
            "created_at": "2018-01-09T07:27:22.000000",
            "description": "description for group1",
            "group_snapshot_id": None,
            "group_type": group_type_1.id,
            "id": "f64646ac-9bf7-483f-bd85-96c34050a528",
            "name": "group1",
            "replication_status": "disabled",
            "source_group_id": None,
            "status": "available",
            "volume_types": [
                vol_type1.id,
            ]
        })
    TEST.cinder_groups.add(cinder_api.Group(group_1))

    group_snapshot_1 = group_snapshots.GroupSnapshot(
        group_snapshots.GroupSnapshotManager(None), {
            "created_at": "2018-01-09T07:46:03.000000",
            "description": "",
            "group_id": group_1.id,
            "group_type_id": group_type_1.id,
            "id": "1036d913-9cb8-46a1-9f56-2f99dc1f14ed",
            "name": "group-snap1",
            "status": "available",
        })
    TEST.cinder_group_snapshots.add(group_snapshot_1)

    group_volume_1 = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "fe9a2664-0f49-4354-bab6-11b2ad352630",
            'status': 'available',
            'size': 2,
            'name': 'group1-volume1',
            'display_description': 'Volume 1 in Group 1',
            'created_at': '2014-01-27 10:30:00',
            'volume_type': 'vol_type_1',
            'group_id': group_1.id,
            'attachments': []
        })

    group_volume_2 = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "a7fb0402-88dc-45a3-970c-d732da63466e",
            'status': 'available',
            'size': 1,
            'name': 'group1-volume2',
            'display_description': 'Volume 2 in Group 1',
            'created_at': '2014-01-30 10:31:00',
            'volume_type': 'vol_type_1',
            'group_id': group_1.id,
            'attachments': []
        })
    TEST.cinder_group_volumes.add(group_volume_1)
    TEST.cinder_group_volumes.add(group_volume_2)

    snapshot5 = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': 'cd6be1eb-82ca-4587-8036-13c37c00c2b1',
            'name': '',
            'description': 'v2 volume snapshot with metadata description',
            'size': 80,
            'status': 'available',
            'volume_id': '7e4efa56-9ca1-45ff-b83c-2efb2383930d',
            'metadata': {
                'snapshot_meta_key': 'snapshot_meta_value'
            },
            'group_snapshot_id': group_snapshot_1.id
        })

    TEST.cinder_volume_snapshots_with_groups.add(
        api.cinder.VolumeSnapshot(snapshot5))

    # Cinder Messages
    messages_1 = messages.Message(
        messages.MessageManager(None), {
            'created_at': '2020-07-08T17:12:06.000000',
            'event_id': 'VOLUME_VOLUME_001_001',
            'guaranteed_until': '2020-08-07T17:12:06.000000',
            'id': '2d2bb0d7-af28-4566-9a65-6d987c19093c',
            'resource_type': 'VOLUME',
            'resource_uuid': '6d53d143-e10f-440a-a65f-16a6b6d068f7',
            'message_level': 'ERROR',
            'user_message':
            'schedule allocate volume:An unknown error occurred.'
        })
    messages_2 = messages.Message(
        messages.MessageManager(None), {
            'created_at': '2020-07-12T12:56:43.000000',
            'event_id': 'VOLUME_VOLUME_SNAPSHOT_009_015',
            'guaranteed_until': '2020-08-11T12:56:43.000000',
            'id': 'd360b4e2-bda5-4289-b673-714a90cde80b',
            'resource_type': 'VOLUME_SNAPSHOT',
            'resource_uuid': '761634b0-fa1c-4e59-b8ad-d720807cb355',
            'message_level': 'ERROR',
            'user_message': 'create snapshot:Snapshot is busy.'
        })
    messages_3 = messages.Message(
        messages.MessageManager(None), {
            'created_at':
            '2020-09-24T11:03:31.000000',
            'event_id':
            'VOLUME_VOLUME_001_003',
            'guaranteed_until':
            '2020-10-24T11:03:31.000000',
            'id':
            '1f481885-9e1b-4d67-bdb5-b9db461391d3',
            'resource_type':
            'VOLUME',
            'resource_uuid':
            'f227c02d-91d7-4c3f-90d8-d8f261d0331a',
            'message_level':
            'ERROR',
            'user_message': ('schedule allocate volume:'
                             'Could not find any available weighted backend.'),
        })
    TEST.cinder_messages.add(api.cinder.Message(messages_1))
    TEST.cinder_messages.add(api.cinder.Message(messages_2))
    TEST.cinder_messages.add(api.cinder.Message(messages_3))
コード例 #9
0
ファイル: cinder_data.py プロジェクト: yashbathia/horizon
def data(TEST):
    TEST.cinder_services = utils.TestDataContainer()
    TEST.cinder_volumes = utils.TestDataContainer()
    TEST.cinder_volume_backups = utils.TestDataContainer()
    TEST.cinder_volume_types = utils.TestDataContainer()
    TEST.cinder_qos_specs = utils.TestDataContainer()
    TEST.cinder_qos_spec_associations = utils.TestDataContainer()
    TEST.cinder_volume_snapshots = utils.TestDataContainer()
    TEST.cinder_quotas = utils.TestDataContainer()
    TEST.cinder_quota_usages = utils.TestDataContainer()
    TEST.cinder_availability_zones = utils.TestDataContainer()

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-scheduler",
            "status": "enabled",
            "binary": "cinder-scheduler",
            "zone": "internal",
            "state": "up",
            "updated_at": "2013-07-08T05:21:00.000000",
            "host": "devstack001",
            "disabled_reason": None
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-volume",
            "status": "enabled",
            "binary": "cinder-volume",
            "zone": "nova",
            "state": "up",
            "updated_at": "2013-07-08T05:20:51.000000",
            "host": "devstack001",
            "disabled_reason": None
        })
    TEST.cinder_services.add(service_1)
    TEST.cinder_services.add(service_2)

    # Volumes - Cinder v1
    volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
            'status': 'available',
            'size': 40,
            'display_name': 'Volume name',
            'display_description': 'Volume description',
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'attachments': []
        })
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            "id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce",
            "status": 'available',
            "size": 10,
            "display_name": '',
            "display_description": '',
            "device": "/dev/hda",
            "created_at": '2010-11-21 18:34:25',
            "volume_type": 'vol_type_1',
            "attachments": []
        })
    other_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "21023e92-8008-1234-8059-7f2293ff3889",
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': None,
            'attachments': [{
                "id": "1",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })
    volume_with_type = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "7dcb47fd-07d9-42c2-9647-be5eab799ebe",
            'name': 'my_volume2',
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume2',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': 'vol_type_2',
            'attachments': [{
                "id": "2",
                "server_id": '2',
                "device": "/dev/hdb"
            }]
        })

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    other_volume.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume))
    TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(other_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(volume_with_type))

    vol_type1 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': u'1',
        'name': u'vol_type_1',
        'extra_specs': {
            'foo': 'bar'
        }
    })
    vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), {
        'id': u'2',
        'name': u'vol_type_2'
    })
    TEST.cinder_volume_types.add(vol_type1, vol_type2)

    # Volumes - Cinder v2
    volume_v2 = volumes_v2.Volume(
        volumes_v2.VolumeManager(None), {
            'id': "31023e92-8008-4c8b-8059-7f2293ff1234",
            'name': 'v2_volume',
            'description': "v2 Volume Description",
            'status': 'available',
            'size': 20,
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'bootable': 'true',
            'attachments': []
        })
    volume_v2.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume_v2))

    snapshot = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d',
            'display_name': 'test snapshot',
            'display_description': 'volume snapshot',
            'size': 40,
            'status': 'available',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })
    snapshot2 = vol_snaps_v2.Snapshot(
        vol_snaps_v2.SnapshotManager(None), {
            'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f',
            'name': '',
            'description': 'v2 volume snapshot description',
            'size': 80,
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    snapshot.bootable = 'true'
    snapshot2.bootable = 'true'

    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))
    TEST.cinder_volume_snapshots.first()._volume = volume

    volume_backup1 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31',
            'name': 'backup1',
            'description': 'volume backup 1',
            'size': 10,
            'status': 'available',
            'container_name': 'volumebackups',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })

    volume_backup2 = vol_backups.VolumeBackup(
        vol_backups.VolumeBackupManager(None), {
            'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e52',
            'name': 'backup2',
            'description': 'volume backup 2',
            'size': 20,
            'status': 'available',
            'container_name': 'volumebackups',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    TEST.cinder_volume_backups.add(volume_backup1)
    TEST.cinder_volume_backups.add(volume_backup2)

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.cinder_quotas.add(api.base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(api.base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)

    # Availability Zones
    # Cinder returns the following structure from os-availability-zone
    # {"availabilityZoneInfo":
    # [{"zoneState": {"available": true}, "zoneName": "nova"}]}
    # Note that the default zone is still "nova" even though this is cinder
    TEST.cinder_availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None), {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                }
            }))
    # Cinder Limits
    limits = {
        "absolute": {
            "totalVolumesUsed": 1,
            "totalGigabytesUsed": 5,
            "maxTotalVolumeGigabytes": 1000,
            "maxTotalVolumes": 10
        }
    }
    TEST.cinder_limits = limits

    # QOS Specs
    qos_spec1 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "418db45d-6992-4674-b226-80aacad2073c",
            "name": "high_iops",
            "consumer": "back-end",
            "specs": {
                "minIOPS": "1000",
                "maxIOPS": '100000'
            }
        })
    qos_spec2 = qos_specs.QoSSpecs(
        qos_specs.QoSSpecsManager(None), {
            "id": "6ed7035f-992e-4075-8ed6-6eff19b3192d",
            "name": "high_bws",
            "consumer": "back-end",
            "specs": {
                "maxBWS": '5000'
            }
        })

    TEST.cinder_qos_specs.add(qos_spec1, qos_spec2)
    vol_type1.associated_qos_spec = qos_spec1.name
    TEST.cinder_qos_spec_associations.add(vol_type1)
コード例 #10
0
ファイル: cinder_data.py プロジェクト: sfdlut/horizon
def data(TEST):
    TEST.cinder_services = utils.TestDataContainer()
    TEST.cinder_volumes = utils.TestDataContainer()
    TEST.cinder_volume_snapshots = utils.TestDataContainer()
    TEST.cinder_quotas = utils.TestDataContainer()
    TEST.cinder_quota_usages = utils.TestDataContainer()
    TEST.cinder_availability_zones = utils.TestDataContainer()

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-scheduler",
            "status": "enabled",
            "binary": "cinder-scheduler",
            "zone": "internal",
            "state": "up",
            "updated_at": "2013-07-08T05:21:00.000000",
            "host": "devstack001",
            "disabled_reason": None
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "service": "cinder-volume",
            "status": "enabled",
            "binary": "cinder-volume",
            "zone": "nova",
            "state": "up",
            "updated_at": "2013-07-08T05:20:51.000000",
            "host": "devstack001",
            "disabled_reason": None
        })
    TEST.cinder_services.add(service_1)
    TEST.cinder_services.add(service_2)

    # Volumes - Cinder v1
    volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
            'status': 'available',
            'size': 40,
            'display_name': 'Volume name',
            'display_description': 'Volume description',
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'attachments': []
        })
    nameless_volume = volumes.Volume(
        volumes.VolumeManager(None),
        dict(id="4b069dd0-6eaa-4272-8abc-5448a68f1cce",
             status='available',
             size=10,
             display_name='',
             display_description='',
             device="/dev/hda",
             created_at='2010-11-21 18:34:25',
             volume_type='vol_type_1',
             attachments=[]))
    other_volume = volumes.Volume(
        volumes.VolumeManager(None), {
            'id': "21023e92-8008-1234-8059-7f2293ff3889",
            'status': 'in-use',
            'size': 10,
            'display_name': u'my_volume',
            'display_description': '',
            'created_at': '2013-04-01 10:30:00',
            'volume_type': None,
            'attachments': [{
                "id": "1",
                "server_id": '1',
                "device": "/dev/hda"
            }]
        })

    volume.bootable = 'true'
    nameless_volume.bootable = 'true'
    other_volume.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume))
    TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume))
    TEST.cinder_volumes.add(api.cinder.Volume(other_volume))

    # Volumes - Cinder v2
    volume_v2 = volumes_v2.Volume(
        volumes_v2.VolumeManager(None), {
            'id': "31023e92-8008-4c8b-8059-7f2293ff1234",
            'name': 'v2_volume',
            'description': "v2 Volume Description",
            'status': 'available',
            'size': 20,
            'created_at': '2014-01-27 10:30:00',
            'volume_type': None,
            'bootable': 'true',
            'attachments': []
        })
    volume_v2.bootable = 'true'

    TEST.cinder_volumes.add(api.cinder.Volume(volume_v2))

    snapshot = vol_snaps.Snapshot(
        vol_snaps.SnapshotManager(None), {
            'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d',
            'display_name': 'test snapshot',
            'display_description': 'volume snapshot',
            'size': 40,
            'status': 'available',
            'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'
        })
    snapshot2 = vol_snaps_v2.Snapshot(
        vol_snaps_v2.SnapshotManager(None), {
            'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f',
            'name': '',
            'description': 'v2 volume snapshot description',
            'size': 80,
            'status': 'available',
            'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'
        })

    snapshot.bootable = 'true'
    snapshot2.bootable = 'true'

    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
    TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))

    # Quota Sets
    quota_data = dict(volumes='1', snapshots='1', gigabytes='1000')
    quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
    TEST.cinder_quotas.add(api.base.QuotaSet(quota))

    # Quota Usages
    quota_usage_data = {
        'gigabytes': {
            'used': 0,
            'quota': 1000
        },
        'instances': {
            'used': 0,
            'quota': 10
        },
        'snapshots': {
            'used': 0,
            'quota': 10
        }
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(api.base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.cinder_quota_usages.add(quota_usage)

    # Availability Zones
    # Cinder returns the following structure from os-availability-zone
    # {"availabilityZoneInfo":
    # [{"zoneState": {"available": true}, "zoneName": "nova"}]}
    # Note that the default zone is still "nova" even though this is cinder
    TEST.cinder_availability_zones.add(
        availability_zones.AvailabilityZone(
            availability_zones.AvailabilityZoneManager(None), {
                'zoneName': 'nova',
                'zoneState': {
                    'available': True
                }
            }))
    # Cinder Limits
    limits = {
        "absolute": {
            "totalVolumesUsed": 1,
            "totalGigabytesUsed": 5,
            "maxTotalVolumeGigabytes": 1000,
            "maxTotalVolumes": 10
        }
    }
    TEST.cinder_limits = limits
コード例 #11
0
        'used': 0,
        'quota': 1000
    },
    'shares': {
        'used': 0,
        'quota': 10
    },
    'snapshots': {
        'used': 0,
        'quota': 10
    },
    'share_networks': {
        'used': 0,
        'quota': 10
    }
}
quota_usage = usage_quotas.QuotaUsage()
for k, v in quota_usage_data.items():
    quota_usage.add_quota(api.base.Quota(k, v['quota']))
    quota_usage.tally(k, v['used'])

# Manila Limits
limits = {
    "absolute": {
        "totalSharesUsed": 1,
        "totalShareGigabytesUsed": 5,
        "maxTotalShareGigabytes": 1000,
        "maxTotalShares": 10
    }
}
コード例 #12
0
ファイル: neutron_data.py プロジェクト: yhu6/stx-horizon
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.agents = utils.TestDataContainer()
    TEST.networks = utils.TestDataContainer()
    TEST.subnets = utils.TestDataContainer()
    TEST.subnetpools = utils.TestDataContainer()
    TEST.ports = utils.TestDataContainer()
    TEST.trunks = utils.TestDataContainer()
    TEST.routers = utils.TestDataContainer()
    TEST.routers_with_rules = utils.TestDataContainer()
    TEST.routers_with_routes = utils.TestDataContainer()
    TEST.floating_ips = utils.TestDataContainer()
    TEST.security_groups = utils.TestDataContainer()
    TEST.security_group_rules = utils.TestDataContainer()
    TEST.providers = utils.TestDataContainer()
    TEST.pools = utils.TestDataContainer()
    TEST.vips = utils.TestDataContainer()
    TEST.members = utils.TestDataContainer()
    TEST.monitors = utils.TestDataContainer()
    TEST.neutron_quotas = utils.TestDataContainer()
    TEST.neutron_quota_usages = utils.TestDataContainer()
    TEST.ip_availability = utils.TestDataContainer()
    TEST.qos_policies = utils.TestDataContainer()
    TEST.qoses = utils.TestDataContainer()
    TEST.providernets = utils.TestDataContainer()
    TEST.providernettypes = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_agents = utils.TestDataContainer()
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = utils.TestDataContainer()
    TEST.api_subnetpools = utils.TestDataContainer()
    TEST.api_ports = utils.TestDataContainer()
    TEST.api_trunks = utils.TestDataContainer()
    TEST.api_routers = utils.TestDataContainer()
    TEST.api_routers_with_routes = utils.TestDataContainer()
    TEST.api_floating_ips = utils.TestDataContainer()
    TEST.api_security_groups = utils.TestDataContainer()
    TEST.api_security_group_rules = utils.TestDataContainer()
    TEST.api_pools = utils.TestDataContainer()
    TEST.api_vips = utils.TestDataContainer()
    TEST.api_members = utils.TestDataContainer()
    TEST.api_monitors = utils.TestDataContainer()
    TEST.api_extensions = utils.TestDataContainer()
    TEST.api_ip_availability = utils.TestDataContainer()
    TEST.api_qos_policies = utils.TestDataContainer()
    TEST.api_qoses = utils.TestDataContainer()
    TEST.api_providernets = utils.TestDataContainer()

    qos_dict = {'id': 'e8abc972-eb0c-47f1-9edd-4bc6e3bcd8c9',
                'description': 'test',
                'type': '8',
                'name': 'My name',
                'tenant_id': '82278d84-e0a5-42ac-95be-e6af08727e42',
                'policies': dict(scheduler=dict(weight="8"))}
    TEST.api_qoses.add(qos_dict)
    qos = copy.deepcopy(qos_dict)
    TEST.qoses.add(neutron.QoSPolicy(qos))

    pnt_dict = {
        'id': 'e6g7c9fc-a0d1-4be3-95f3-587dbc875815',
        'name': 'vlan',
        'type': 'vlan',
    }

    TEST.providernettypes.add(neutron.ProviderNetworkType(pnt_dict))

    pnr_dict = {
        'description': 'tenant2 reserved networks',
        'id': 'e6g7c9fc-a0d1-4be3-95f3-587dbc875815',
        'maximum': 631,
        'minimum': 616,
        'name': 'roup0-tenant',
        'providernet_id': 'e6f7c9fc-a0d1-4be3-95f3-587dbc875815',
        'providernet_name': 'roup0-data1',
        'shared': False,
        'tenant_id': 'fe09a916d70242f4a5f06df52e814b4',
    }

    pn_dict = {'id': 'e8abc972-eb0c-47f1-9edd-4bc6e3bcd8c9',
               'description': 'test',
               'type': '8',
               'name': 'My name',
               'status': 'DOWN',
               'mtu': '1500',
               'ranges': [neutron.ProviderNetworkRange(pnr_dict)]}
    TEST.api_providernets.add(pn_dict)
    pn = copy.deepcopy(pn_dict)
    TEST.providernets.add(neutron.ProviderNetwork(pn))

    # 1st network.
    network_dict = {'admin_state_up': True,
                    'id': '82288d84-e0a5-42ac-95be-e6af08727e42',
                    'name': 'net1',
                    'status': 'ACTIVE',
                    'subnets': ['e8abc972-eb0c-41f1-9edd-4bc6e3bcd8c9'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False,
                    'vlan_transparent': False,
                    'wrs-tm__qos': None}
    subnet_dict = {'allocation_pools': [{'end': '10.0.0.254',
                                         'start': '10.0.0.2'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': '10.0.0.0/24',
                   'enable_dhcp': True,
                   'gateway_ip': '10.0.0.1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 4,
                   'wrs-net__managed': False,
                   'wrs-net__vlan_id': None,
                   'wrs-provider__network_type': 'test',
                   'wrs-provider__physical_network': 'test',
                   'wrs-provider__segmentation_id': 'test',
                   'name': 'mysubnet1',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Ports on 1st network.
    port_dict = {
        'admin_state_up': True,
        'device_id': 'af75c8e5-a1cc-4567-8d04-44fcd6922890',
        'device_owner': 'network:dhcp',
        'fixed_ips': [{'ip_address': '10.0.0.3',
                       'subnet_id': subnet_dict['id']}],
        'id': '063cf7f3-ded1-4297-bc4c-31eae876cc91',
        'mac_address': 'fa:16:3e:9c:d5:7e',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'allowed_address_pairs': [
            {'ip_address': '174.0.0.201',
             'mac_address': 'fa:16:3e:7a:7b:18'}
        ],
        'security_groups': [],
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    port_dict = {
        'admin_state_up': True,
        'device_id': '1',
        'device_owner': 'compute:nova',
        'fixed_ips': [{'ip_address': '10.0.0.4',
                       'subnet_id': subnet_dict['id']}],
        'id': '7e6ce62c-7ea2-44f8-b6b4-769af90a8406',
        'mac_address': 'fa:16:3e:9d:e6:2f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [
            # sec_group_1 ID below
            'faad7c80-3b62-4440-967c-13808c37131d',
            # sec_group_2 ID below
            '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d'
        ],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))
    assoc_port = port_dict

    port_dict = {
        'admin_state_up': True,
        'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'device_owner': 'network:router_interface',
        'fixed_ips': [{'ip_address': '10.0.0.1',
                       'subnet_id': subnet_dict['id']}],
        'id': '9036eedb-e7fa-458e-bc6e-d9d06d9d1bc4',
        'mac_address': 'fa:16:3e:9c:d5:7f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # 2nd network.
    network_dict = {'admin_state_up': True,
                    'id': '72c3ab6c-c80f-4341-9dc5-210fa31ac6c2',
                    'name': 'net2',
                    'status': 'ACTIVE',
                    'subnets': ['3f7c5d79-ee55-47b0-9213-8e669fb03009'],
                    'tenant_id': '2',
                    'router:external': False,
                    'shared': True,
                    'vlan_transparent': True,
                    'wrs-tm__qos': None}
    subnet_dict = {'allocation_pools': [{'end': '172.16.88.254',
                                         'start': '172.16.88.2'}],
                   'dns_nameservers': ['10.56.1.20', '10.56.1.21'],
                   'host_routes': [{'destination': '192.168.20.0/24',
                                    'nexthop': '172.16.88.253'},
                                   {'destination': '192.168.21.0/24',
                                    'nexthop': '172.16.88.252'}],
                   'cidr': '172.16.88.0/24',
                   'enable_dhcp': True,
                   'gateway_ip': '172.16.88.1',
                   'id': '3f7c5d79-ee55-47b0-9213-8e669fb03009',
                   'ip_version': 4,
                   'wrs-net__managed': False,
                   'wrs-net__vlan_id': None,
                   'wrs-provider__network_type': 'test',
                   'wrs-provider__physical_network': 'test',
                   'wrs-provider__segmentation_id': 'test',
                   'name': 'aaaa',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    port_dict = {
        'admin_state_up': True,
        'device_id': '2',
        'device_owner': 'compute:nova',
        'fixed_ips': [{'ip_address': '172.16.88.3',
                       'subnet_id': subnet_dict['id']}],
        'id': '1db2cc37-3553-43fa-b7e2-3fc4eb4f9905',
        'mac_address': 'fa:16:3e:56:e6:2f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [
            # sec_group_1 ID below
            'faad7c80-3b62-4440-967c-13808c37131d',
        ],
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # External network.
    network_dict = {'admin_state_up': True,
                    'id': '9b466b94-213a-4cda-badf-72c102a874da',
                    'name': 'ext_net',
                    'status': 'ACTIVE',
                    'subnets': ['d6bdc71c-7566-4d32-b3ff-36441ce746e8'],
                    'tenant_id': '3',
                    'router:external': True,
                    'shared': False,
                    'vlan_transparent': True,
                    'wrs-tm__qos': None}
    subnet_dict = {'allocation_pools': [{'start': '172.24.4.226.',
                                         'end': '172.24.4.238'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': '172.24.4.0/28',
                   'enable_dhcp': False,
                   'gateway_ip': '172.24.4.225',
                   'id': 'd6bdc71c-7566-4d32-b3ff-36441ce746e8',
                   'ip_version': 4,
                   'wrs-net__managed': False,
                   'wrs-net__vlan_id': None,
                   'wrs-provider__network_type': 'test',
                   'wrs-provider__physical_network': 'test',
                   'wrs-provider__segmentation_id': 'test',
                   'name': 'ext_subnet',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id']}
    ext_net = network_dict

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 1st v6 network.
    network_dict = {'admin_state_up': True,
                    'id': '96688ea1-ffa5-78ec-22ca-33aaabfaf775',
                    'name': 'v6_net1',
                    'status': 'ACTIVE',
                    'subnets': ['88ddd443-4377-ab1f-87dd-4bc4a662dbb6'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False,
                    'vlan_transparent': True,
                    'wrs-tm__qos': None}
    subnet_dict = {'allocation_pools': [{'end': 'ff09::ff',
                                         'start': 'ff09::02'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': 'ff09::/64',
                   'enable_dhcp': True,
                   'gateway_ip': 'ff09::1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 6,
                   'wrs-net__managed': False,
                   'wrs-net__vlan_id': None,
                   'wrs-provider__network_type': 'test',
                   'wrs-provider__physical_network': 'test',
                   'wrs-provider__segmentation_id': 'test',
                   'name': 'v6_subnet1',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id'],
                   'ipv6_modes': 'none/none'}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 2nd v6 network - slaac.
    network_dict = {'admin_state_up': True,
                    'id': 'c62e4bb3-296a-4cd1-8f6b-aaa7a0092326',
                    'name': 'v6_net2',
                    'status': 'ACTIVE',
                    'subnets': ['5d736a21-0036-4779-8f8b-eed5f98077ec'],
                    'tenant_id': '1',
                    'router:external': False,
                    'shared': False,
                    'vlan_transparent': True,
                    'wrs-tm__qos': None}
    subnet_dict = {'allocation_pools': [{'end': 'ff09::ff',
                                         'start': 'ff09::02'}],
                   'dns_nameservers': [],
                   'host_routes': [],
                   'cidr': 'ff09::/64',
                   'enable_dhcp': True,
                   'gateway_ip': 'ff09::1',
                   'id': network_dict['subnets'][0],
                   'ip_version': 6,
                   'wrs-net__managed': False,
                   'wrs-net__vlan_id': None,
                   'wrs-provider__network_type': 'test',
                   'wrs-provider__physical_network': 'test',
                   'wrs-provider__segmentation_id': 'test',
                   'name': 'v6_subnet2',
                   'network_id': network_dict['id'],
                   'tenant_id': network_dict['tenant_id'],
                   'ipv6_modes': 'slaac/slaac'}

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Set up router data.
    port_dict = {
        'admin_state_up': True,
        'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
        'device_owner': 'network:router_gateway',
        'fixed_ips': [{'ip_address': '10.0.0.3',
                       'subnet_id': subnet_dict['id']}],
        'id': '44ec6726-4bdc-48c5-94d4-df8d1fbf613b',
        'mac_address': 'fa:16:3e:9c:d5:7e',
        'name': '',
        'network_id': TEST.networks.get(name="ext_net")['id'],
        'status': 'ACTIVE',
        'tenant_id': '1',
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    trunk_dict = {'status': 'UP',
                  'sub_ports': [],
                  'name': 'trunk1',
                  'admin_state_up': True,
                  'tenant_id': '1',
                  'project_id': '1',
                  'port_id': '895d375c-1447-11e7-a52f-f7f280bbc809',
                  'id': '94fcb9e8-1447-11e7-bed6-8b8c4ac74491'}

    TEST.api_trunks.add(trunk_dict)
    TEST.trunks.add(neutron.Trunk(trunk_dict))

    router_dict = {'id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
                   'name': 'router1',
                   'status': 'ACTIVE',
                   'admin_state_up': True,
                   'distributed': True,
                   'external_gateway_info':
                       {'network_id': ext_net['id']},
                   'tenant_id': '1'}
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {'id': '10e3dc42-1ce1-4d48-87cf-7fc333055d6c',
                   'name': 'router2',
                   'status': 'ACTIVE',
                   'admin_state_up': False,
                   'distributed': False,
                   'external_gateway_info': None,
                   'tenant_id': '1'}
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {'id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
                   'name': 'rulerouter',
                   'status': 'ACTIVE',
                   'admin_state_up': True,
                   'distributed': False,
                   'external_gateway_info':
                       {'network_id': ext_net['id']},
                   'tenant_id': '1',
                   'router_rules': [{'id': '101',
                                     'action': 'deny',
                                     'source': 'any',
                                     'destination': 'any',
                                     'nexthops': []},
                                    {'id': '102',
                                     'action': 'permit',
                                     'source': 'any',
                                     'destination': '8.8.8.8/32',
                                     'nexthops': ['1.0.0.2', '1.0.0.1']}]}
    TEST.api_routers.add(router_dict)
    TEST.routers_with_rules.add(neutron.Router(router_dict))
    router_dict_with_route = {'id': '725c24c9-061b-416b-b9d4-012392b32fd9',
                              'name': 'routerouter',
                              'status': 'ACTIVE',
                              'admin_state_up': True,
                              'distributed': False,
                              'external_gateway_info':
                                  {'network_id': ext_net['id']},
                              'tenant_id': '1',
                              'routes': [{'nexthop': '10.0.0.1',
                                          'destination': '172.0.0.0/24'},
                                         {'nexthop': '10.0.0.2',
                                          'destination': '172.1.0.0/24'}]}
    TEST.api_routers_with_routes.add(router_dict_with_route)
    TEST.routers_with_routes.add(neutron.Router(router_dict_with_route))

    # Floating IP.
    # Unassociated.
    fip_dict = {'tenant_id': '1',
                'floating_ip_address': '172.16.88.227',
                'floating_network_id': ext_net['id'],
                'id': '9012cd70-cfae-4e46-b71e-6a409e9e0063',
                'fixed_ip_address': None,
                'port_id': None,
                'router_id': None}
    TEST.api_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': None,
                              'instance_type': None})
    TEST.floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Associated (with compute port on 1st network).
    fip_dict = {'tenant_id': '1',
                'floating_ip_address': '172.16.88.228',
                'floating_network_id': ext_net['id'],
                'id': 'a97af8f2-3149-4b97-abbd-e49ad19510f7',
                'fixed_ip_address': assoc_port['fixed_ips'][0]['ip_address'],
                'port_id': assoc_port['id'],
                'router_id': router_dict['id']}
    TEST.api_floating_ips.add(fip_dict)
    fip_with_instance = copy.deepcopy(fip_dict)
    fip_with_instance.update({'instance_id': '1',
                              'instance_type': 'compute'})
    TEST.floating_ips.add(neutron.FloatingIp(fip_with_instance))

    # Security group.

    sec_group_1 = {'tenant_id': '1',
                   'description': 'default',
                   'id': 'faad7c80-3b62-4440-967c-13808c37131d',
                   'name': 'default'}
    sec_group_2 = {'tenant_id': '1',
                   'description': 'NotDefault',
                   'id': '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d',
                   'name': 'other_group'}
    sec_group_3 = {'tenant_id': '1',
                   'description': 'NotDefault',
                   'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95',
                   'name': 'another_group'}

    def add_rule_to_group(secgroup, default_only=True):
        rule_egress_ipv4 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv4',
            'port_range_min': None, 'port_range_max': None,
            'protocol': None, 'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_egress_ipv6 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv6',
            'port_range_min': None, 'port_range_max': None,
            'protocol': None, 'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}

        rule_tcp_80 = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 80, 'port_range_max': 80,
            'protocol': u'tcp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_icmp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 5, 'port_range_max': 8,
            'protocol': u'icmp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_group = {
            'id': uuidutils.generate_uuid(),
            'direction': u'ingress', 'ethertype': u'IPv4',
            'port_range_min': 80, 'port_range_max': 80,
            'protocol': u'tcp', 'remote_group_id': sec_group_1['id'],
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}
        rule_all_tcp = {
            'id': uuidutils.generate_uuid(),
            'direction': u'egress', 'ethertype': u'IPv4',
            'port_range_min': 1, 'port_range_max': 65535,
            'protocol': u'tcp', 'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/24',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']}

        rules = []
        if not default_only:
            rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp]
        rules += [rule_egress_ipv4, rule_egress_ipv6]
        secgroup['security_group_rules'] = rules

    add_rule_to_group(sec_group_1, default_only=False)
    add_rule_to_group(sec_group_2)
    add_rule_to_group(sec_group_3)

    groups = [sec_group_1, sec_group_2, sec_group_3]
    sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups])
    for sg in groups:
        # Neutron API.
        TEST.api_security_groups.add(sg)
        for rule in sg['security_group_rules']:
            TEST.api_security_group_rules.add(copy.copy(rule))
        # OpenStack Dashboard internaly API.
        TEST.security_groups.add(
            neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))
        for rule in sg['security_group_rules']:
            TEST.security_group_rules.add(
                neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict))

    # Subnetpools

    # 1st subnetpool
    subnetpool_dict = {'default_prefixlen': 24,
                       'default_quota': None,
                       'id': '419eb314-e244-4088-aed7-851af9d9500d',
                       'ip_version': 4,
                       'max_prefixlen': 32,
                       'min_prefixlen': 12,
                       'name': 'mysubnetpool1',
                       'prefixes': ['172.16.0.0/12'],
                       'shared': False,
                       'tenant_id': '1'}

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # 2nd subnetpool (v6)
    subnetpool_dict = {'default_prefixlen': 64,
                       'default_quota': None,
                       'id': 'dcdad289-46f3-4298-bec6-41d91c942efa',
                       'ip_version': 6,
                       'max_prefixlen': 64,
                       'min_prefixlen': 60,
                       'name': 'mysubnetpool2',
                       'prefixes': ['2001:db8:42::/48'],
                       'shared': False,
                       'tenant_id': '1'}

    TEST.api_subnetpools.add(subnetpool_dict)
    subnetpool = neutron.SubnetPool(subnetpool_dict)
    TEST.subnetpools.add(subnetpool)

    # Quotas.
    quota_data = {'network': '10',
                  'subnet': '10',
                  'port': '50',
                  'router': '10',
                  'floatingip': '50',
                  'security_group': '20',
                  'security_group_rule': '100',
                  }
    TEST.neutron_quotas.add(base.QuotaSet(quota_data))

    # Quota Usages
    quota_usage_data = {'networks': {'used': 0, 'quota': 5},
                        'subnets': {'used': 0, 'quota': 5},
                        'routers': {'used': 0, 'quota': 5},
                        }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.neutron_quota_usages.add(quota_usage)

    # Extensions.
    extension_1 = {"name": "security-group",
                   "alias": "security-group",
                   "description": "The security groups extension."}
    extension_2 = {"name": "Quota management support",
                   "alias": "quotas",
                   "description": "Expose functions for quotas management"}
    extension_3 = {"name": "Provider network",
                   "alias": "provider",
                   "description": "Provider network extension"}
    extension_4 = {"name": "Distributed Virtual Router",
                   "alias": "dvr",
                   "description":
                   "Enables configuration of Distributed Virtual Routers."}
    extension_5 = {"name": "HA Router extension",
                   "alias": "l3-ha",
                   "description": "Add HA capability to routers."}
    extension_6 = {"name": "Trunks",
                   "alias": "trunk",
                   "description": "Provides support for trunk ports."}
    TEST.api_extensions.add(extension_1)
    TEST.api_extensions.add(extension_2)
    TEST.api_extensions.add(extension_3)
    TEST.api_extensions.add(extension_4)
    TEST.api_extensions.add(extension_5)
    TEST.api_extensions.add(extension_6)

    # 1st agent.
    agent_dict = {"binary": "neutron-openvswitch-agent",
                  "description": None,
                  "admin_state_up": True,
                  "heartbeat_timestamp": "2013-07-26 06:51:47",
                  "alive": True,
                  "id": "c876ff05-f440-443e-808c-1d34cda3e88a",
                  "topic": "N/A",
                  "host": "devstack001",
                  "agent_type": "Open vSwitch agent",
                  "started_at": "2013-07-26 05:23:28",
                  "created_at": "2013-07-26 05:23:28",
                  "configurations": {"devices": 2}}
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # 2nd agent.
    agent_dict = {"binary": "neutron-dhcp-agent",
                  "description": None,
                  "admin_state_up": True,
                  "heartbeat_timestamp": "2013-07-26 06:51:48",
                  "alive": True,
                  "id": "f0d12e3d-1973-41a2-b977-b95693f9a8aa",
                  "topic": "dhcp_agent",
                  "host": "devstack001",
                  "agent_type": "DHCP agent",
                  "started_at": "2013-07-26 05:23:30",
                  "created_at": "2013-07-26 05:23:30",
                  "configurations": {
                      "subnets": 1,
                      "use_namespaces": True,
                      "dhcp_lease_duration": 120,
                      "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq",
                      "networks": 1,
                      "ports": 1}}
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # Service providers.
    provider_1 = {"service_type": "LOADBALANCER",
                  "name": "haproxy",
                  "default": True}
    TEST.providers.add(provider_1)

    # ports on 4th network
    port_dict = {
        'admin_state_up': True,
        'device_id': '9872faaa-b2b2-eeee-9911-21332eedaa77',
        'device_owner': 'network:dhcp',
        'fixed_ips': [{'ip_address': '11.10.0.3',
                       'subnet_id':
                       TEST.subnets.first().id}],
        'id': 'a21dcd22-6733-cccc-aa32-22adafaf16a2',
        'mac_address': '78:22:ff:1a:ba:23',
        'name': 'port5',
        'network_id': TEST.networks.first().id,
        'status': 'ACTIVE',
        'tenant_id': TEST.networks.first().tenant_id,
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host',
        'security_groups': [],
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    availability = {'network_ip_availability': {
        'used_ips': 2,
        'subnet_ip_availability': [{
            'used_ips': 1,
            'subnet_id': '2c90f321-9cc7-41b4-a3cf-88110f120a94',
            'subnet_name': 'ipv6-public-subnet',
            'ip_version': 6,
            'cidr': '2001:db8::/64',
            'total_ips': 18446744073709551614},
            {'used_ips': 1,
             'subnet_id': '4d77d5fb-c26c-4ac5-b2ca-fca2f89b0fc1',
             'subnet_name': 'public-subnet',
             'ip_version': 4,
             'cidr': '172.24.4.0/24',
             'total_ips': 253}],
        'network_id': 'd87d5be5-cfca-486f-8db5-a446330e4513',
        'tenant_id': 'd564b2a4fc0544fb89f8a0434dd96863',
        'network_name': 'public',
        'total_ips': 18446744073709551867}
    }

    TEST.ip_availability.add(availability)
    TEST.api_ip_availability.add(availability)

    # qos policies
    policy_dict = {'id': 'a21dcd22-7189-cccc-aa32-22adafaf16a7',
                   'name': 'policy 1',
                   'tenant_id': '1'}
    TEST.api_qos_policies.add(policy_dict)
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict))
    policy_dict1 = {'id': 'a21dcd22-7189-ssss-aa32-22adafaf16a7',
                    'name': 'policy 2',
                    'tenant_id': '1'}
    TEST.api_qos_policies.add(policy_dict1)
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict1))
コード例 #13
0
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.agents = utils.TestDataContainer()
    TEST.networks = utils.TestDataContainer()
    TEST.subnets = utils.TestDataContainer()
    TEST.ports = utils.TestDataContainer()
    TEST.routers = utils.TestDataContainer()
    TEST.routers_with_rules = utils.TestDataContainer()
    TEST.q_floating_ips = utils.TestDataContainer()
    TEST.q_secgroups = utils.TestDataContainer()
    TEST.q_secgroup_rules = utils.TestDataContainer()
    TEST.providers = utils.TestDataContainer()
    TEST.pools = utils.TestDataContainer()
    TEST.vips = utils.TestDataContainer()
    TEST.members = utils.TestDataContainer()
    TEST.monitors = utils.TestDataContainer()
    TEST.neutron_quotas = utils.TestDataContainer()
    TEST.neutron_quota_usages = utils.TestDataContainer()
    TEST.net_profiles = utils.TestDataContainer()
    TEST.policy_profiles = utils.TestDataContainer()
    TEST.network_profile_binding = utils.TestDataContainer()
    TEST.policy_profile_binding = utils.TestDataContainer()
    TEST.vpnservices = utils.TestDataContainer()
    TEST.ikepolicies = utils.TestDataContainer()
    TEST.ipsecpolicies = utils.TestDataContainer()
    TEST.ipsecsiteconnections = utils.TestDataContainer()
    TEST.firewalls = utils.TestDataContainer()
    TEST.fw_policies = utils.TestDataContainer()
    TEST.fw_rules = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_agents = utils.TestDataContainer()
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = utils.TestDataContainer()
    TEST.api_ports = utils.TestDataContainer()
    TEST.api_routers = utils.TestDataContainer()
    TEST.api_q_floating_ips = utils.TestDataContainer()
    TEST.api_q_secgroups = utils.TestDataContainer()
    TEST.api_q_secgroup_rules = utils.TestDataContainer()
    TEST.api_pools = utils.TestDataContainer()
    TEST.api_vips = utils.TestDataContainer()
    TEST.api_members = utils.TestDataContainer()
    TEST.api_monitors = utils.TestDataContainer()
    TEST.api_extensions = utils.TestDataContainer()
    TEST.api_net_profiles = utils.TestDataContainer()
    TEST.api_policy_profiles = utils.TestDataContainer()
    TEST.api_network_profile_binding = utils.TestDataContainer()
    TEST.api_policy_profile_binding = utils.TestDataContainer()
    TEST.api_vpnservices = utils.TestDataContainer()
    TEST.api_ikepolicies = utils.TestDataContainer()
    TEST.api_ipsecpolicies = utils.TestDataContainer()
    TEST.api_ipsecsiteconnections = utils.TestDataContainer()
    TEST.api_firewalls = utils.TestDataContainer()
    TEST.api_fw_policies = utils.TestDataContainer()
    TEST.api_fw_rules = utils.TestDataContainer()

    # 1st network.
    network_dict = {
        'admin_state_up': True,
        'id': '82288d84-e0a5-42ac-95be-e6af08727e42',
        'name': 'net1',
        'status': 'ACTIVE',
        'subnets': ['e8abc972-eb0c-41f1-9edd-4bc6e3bcd8c9'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': '10.0.0.254',
            'start': '10.0.0.2'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': '10.0.0.0/24',
        'enable_dhcp': True,
        'gateway_ip': '10.0.0.1',
        'id': network_dict['subnets'][0],
        'ip_version': 4,
        'name': 'mysubnet1',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id']
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Network profile for network when using the cisco n1k plugin.
    net_profile_dict = {
        'name': 'net_profile_test1',
        'segment_type': 'vlan',
        'physical_network': 'phys1',
        'segment_range': '3000-3100',
        'id': '00000000-1111-1111-1111-000000000000',
        'project': TEST.networks.get(name="net1")['tenant_id'],
        # vlan profiles have no sub_type or multicast_ip_range
        'multicast_ip_range': None,
        'sub_type': None
    }

    TEST.api_net_profiles.add(net_profile_dict)
    TEST.net_profiles.add(neutron.Profile(net_profile_dict))

    # Policy profile for port when using the cisco n1k plugin.
    policy_profile_dict = {
        'name': 'policy_profile_test1',
        'id': '00000000-9999-9999-9999-000000000000'
    }

    TEST.api_policy_profiles.add(policy_profile_dict)
    TEST.policy_profiles.add(neutron.Profile(policy_profile_dict))

    # Network profile binding.
    network_profile_binding_dict = {
        'profile_id': '00000000-1111-1111-1111-000000000000',
        'tenant_id': network_dict['tenant_id']
    }

    TEST.api_network_profile_binding.add(network_profile_binding_dict)
    TEST.network_profile_binding.add(
        neutron.Profile(network_profile_binding_dict))

    # Policy profile binding.
    policy_profile_binding_dict = {
        'profile_id': '00000000-9999-9999-9999-000000000000',
        'tenant_id': network_dict['tenant_id']
    }

    TEST.api_policy_profile_binding.add(policy_profile_binding_dict)
    TEST.policy_profile_binding.add(
        neutron.Profile(policy_profile_binding_dict))

    # Ports on 1st network.
    port_dict = {
        'admin_state_up': True,
        'device_id': 'af75c8e5-a1cc-4567-8d04-44fcd6922890',
        'device_owner': 'network:dhcp',
        'fixed_ips': [{
            'ip_address': '10.0.0.3',
            'subnet_id': subnet_dict['id']
        }],
        'id': '063cf7f3-ded1-4297-bc4c-31eae876cc91',
        'mac_address': 'fa:16:3e:9c:d5:7e',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host'
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    port_dict = {
        'admin_state_up': True,
        'device_id': '1',
        'device_owner': 'compute:nova',
        'fixed_ips': [{
            'ip_address': '10.0.0.4',
            'subnet_id': subnet_dict['id']
        }],
        'id': '7e6ce62c-7ea2-44f8-b6b4-769af90a8406',
        'mac_address': 'fa:16:3e:9d:e6:2f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host'
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))
    assoc_port = port_dict

    port_dict = {
        'admin_state_up': True,
        'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'device_owner': 'network:router_interface',
        'fixed_ips': [{
            'ip_address': '10.0.0.1',
            'subnet_id': subnet_dict['id']
        }],
        'id': '9036eedb-e7fa-458e-bc6e-d9d06d9d1bc4',
        'mac_address': 'fa:16:3e:9c:d5:7f',
        'name': '',
        'network_id': network_dict['id'],
        'status': 'ACTIVE',
        'tenant_id': network_dict['tenant_id'],
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host'
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # 2nd network.
    network_dict = {
        'admin_state_up': True,
        'id': '72c3ab6c-c80f-4341-9dc5-210fa31ac6c2',
        'name': 'net2',
        'status': 'ACTIVE',
        'subnets': ['3f7c5d79-ee55-47b0-9213-8e669fb03009'],
        'tenant_id': '2',
        'router:external': False,
        'shared': True
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': '172.16.88.254',
            'start': '172.16.88.2'
        }],
        'dns_nameservers': ['10.56.1.20', '10.56.1.21'],
        'host_routes': [{
            'destination': '192.168.20.0/24',
            'nexthop': '172.16.88.253'
        }, {
            'destination': '192.168.21.0/24',
            'nexthop': '172.16.88.252'
        }],
        'cidr':
        '172.16.88.0/24',
        'enable_dhcp':
        True,
        'gateway_ip':
        '172.16.88.1',
        'id':
        '3f7c5d79-ee55-47b0-9213-8e669fb03009',
        'ip_version':
        4,
        'name':
        'aaaa',
        'network_id':
        network_dict['id'],
        'tenant_id':
        network_dict['tenant_id']
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '2',
        'device_owner':
        'compute:nova',
        'fixed_ips': [{
            'ip_address': '172.16.88.3',
            'subnet_id': subnet_dict['id']
        }],
        'id':
        '1db2cc37-3553-43fa-b7e2-3fc4eb4f9905',
        'mac_address':
        'fa:16:3e:56:e6:2f',
        'name':
        '',
        'network_id':
        network_dict['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        network_dict['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host'
    }

    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    # External network.
    network_dict = {
        'admin_state_up': True,
        'id': '9b466b94-213a-4cda-badf-72c102a874da',
        'name': 'ext_net',
        'status': 'ACTIVE',
        'subnets': ['d6bdc71c-7566-4d32-b3ff-36441ce746e8'],
        'tenant_id': '3',
        'router:external': True,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'start': '172.24.4.226.',
            'end': '172.24.4.238'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': '172.24.4.0/28',
        'enable_dhcp': False,
        'gateway_ip': '172.24.4.225',
        'id': 'd6bdc71c-7566-4d32-b3ff-36441ce746e8',
        'ip_version': 4,
        'name': 'ext_subnet',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id']
    }
    ext_net = network_dict

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 1st v6 network.
    network_dict = {
        'admin_state_up': True,
        'id': '96688ea1-ffa5-78ec-22ca-33aaabfaf775',
        'name': 'v6_net1',
        'status': 'ACTIVE',
        'subnets': ['88ddd443-4377-ab1f-87dd-4bc4a662dbb6'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': 'ff09::ff',
            'start': 'ff09::02'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': 'ff09::/64',
        'enable_dhcp': True,
        'gateway_ip': 'ff09::1',
        'id': network_dict['subnets'][0],
        'ip_version': 6,
        'name': 'v6_subnet1',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id'],
        'ipv6_modes': 'none/none'
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 2nd v6 network - slaac.
    network_dict = {
        'admin_state_up': True,
        'id': 'c62e4bb3-296a-4cd1-8f6b-aaa7a0092326',
        'name': 'v6_net2',
        'status': 'ACTIVE',
        'subnets': ['5d736a21-0036-4779-8f8b-eed5f98077ec'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': 'ff09::ff',
            'start': 'ff09::02'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': 'ff09::/64',
        'enable_dhcp': True,
        'gateway_ip': 'ff09::1',
        'id': network_dict['subnets'][0],
        'ip_version': 6,
        'name': 'v6_subnet2',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id'],
        'ipv6_modes': 'slaac/slaac'
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # Set up router data.
    port_dict = {
        'admin_state_up': True,
        'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53',
        'device_owner': 'network:router_gateway',
        'fixed_ips': [{
            'ip_address': '10.0.0.3',
            'subnet_id': subnet_dict['id']
        }],
        'id': '44ec6726-4bdc-48c5-94d4-df8d1fbf613b',
        'mac_address': 'fa:16:3e:9c:d5:7e',
        'name': '',
        'network_id': TEST.networks.get(name="ext_net")['id'],
        'status': 'ACTIVE',
        'tenant_id': '1',
        'binding:vnic_type': 'normal',
        'binding:host_id': 'host'
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))

    router_dict = {
        'id': '279989f7-54bb-41d9-ba42-0d61f12fda61',
        'name': 'router1',
        'status': 'ACTIVE',
        'admin_state_up': True,
        'distributed': True,
        'external_gateway_info': {
            'network_id': ext_net['id']
        },
        'tenant_id': '1'
    }
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {
        'id': '10e3dc42-1ce1-4d48-87cf-7fc333055d6c',
        'name': 'router2',
        'status': 'ACTIVE',
        'admin_state_up': False,
        'distributed': False,
        'external_gateway_info': None,
        'tenant_id': '1'
    }
    TEST.api_routers.add(router_dict)
    TEST.routers.add(neutron.Router(router_dict))
    router_dict = {
        'id':
        '7180cede-bcd8-4334-b19f-f7ef2f331f53',
        'name':
        'rulerouter',
        'status':
        'ACTIVE',
        'admin_state_up':
        True,
        'distributed':
        False,
        'external_gateway_info': {
            'network_id': ext_net['id']
        },
        'tenant_id':
        '1',
        'router_rules': [{
            'id': '101',
            'action': 'deny',
            'source': 'any',
            'destination': 'any',
            'nexthops': []
        }, {
            'id': '102',
            'action': 'permit',
            'source': 'any',
            'destination': '8.8.8.8/32',
            'nexthops': ['1.0.0.2', '1.0.0.1']
        }]
    }
    TEST.api_routers.add(router_dict)
    TEST.routers_with_rules.add(neutron.Router(router_dict))

    # Floating IP.
    # Unassociated.
    fip_dict = {
        'tenant_id': '1',
        'floating_ip_address': '172.16.88.227',
        'floating_network_id': ext_net['id'],
        'id': '9012cd70-cfae-4e46-b71e-6a409e9e0063',
        'fixed_ip_address': None,
        'port_id': None,
        'router_id': None
    }
    TEST.api_q_floating_ips.add(fip_dict)
    TEST.q_floating_ips.add(neutron.FloatingIp(fip_dict))

    # Associated (with compute port on 1st network).
    fip_dict = {
        'tenant_id': '1',
        'floating_ip_address': '172.16.88.228',
        'floating_network_id': ext_net['id'],
        'id': 'a97af8f2-3149-4b97-abbd-e49ad19510f7',
        'fixed_ip_address': assoc_port['fixed_ips'][0]['ip_address'],
        'port_id': assoc_port['id'],
        'router_id': router_dict['id']
    }
    TEST.api_q_floating_ips.add(fip_dict)
    TEST.q_floating_ips.add(neutron.FloatingIp(fip_dict))

    # Security group.

    sec_group_1 = {
        'tenant_id': '1',
        'description': 'default',
        'id': 'faad7c80-3b62-4440-967c-13808c37131d',
        'name': 'default'
    }
    sec_group_2 = {
        'tenant_id': '1',
        'description': 'NotDefault',
        'id': '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d',
        'name': 'other_group'
    }
    sec_group_3 = {
        'tenant_id': '1',
        'description': 'NotDefault',
        'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95',
        'name': 'another_group'
    }

    def add_rule_to_group(secgroup, default_only=True):
        rule_egress_ipv4 = {
            'id': str(uuid.uuid4()),
            'direction': u'egress',
            'ethertype': u'IPv4',
            'port_range_min': None,
            'port_range_max': None,
            'protocol': None,
            'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_egress_ipv6 = {
            'id': str(uuid.uuid4()),
            'direction': u'egress',
            'ethertype': u'IPv6',
            'port_range_min': None,
            'port_range_max': None,
            'protocol': None,
            'remote_group_id': None,
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }

        rule_tcp_80 = {
            'id': str(uuid.uuid4()),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 80,
            'port_range_max': 80,
            'protocol': u'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_icmp = {
            'id': str(uuid.uuid4()),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 5,
            'port_range_max': 8,
            'protocol': u'icmp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/0',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_group = {
            'id': str(uuid.uuid4()),
            'direction': u'ingress',
            'ethertype': u'IPv4',
            'port_range_min': 80,
            'port_range_max': 80,
            'protocol': u'tcp',
            'remote_group_id': sec_group_1['id'],
            'remote_ip_prefix': None,
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }
        rule_all_tcp = {
            'id': str(uuid.uuid4()),
            'direction': u'egress',
            'ethertype': u'IPv4',
            'port_range_min': 1,
            'port_range_max': 65535,
            'protocol': u'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': u'0.0.0.0/24',
            'security_group_id': secgroup['id'],
            'tenant_id': secgroup['tenant_id']
        }

        rules = []
        if not default_only:
            rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp]
        rules += [rule_egress_ipv4, rule_egress_ipv6]
        secgroup['security_group_rules'] = rules

    add_rule_to_group(sec_group_1, default_only=False)
    add_rule_to_group(sec_group_2)
    add_rule_to_group(sec_group_3)

    groups = [sec_group_1, sec_group_2, sec_group_3]
    sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups])
    for sg in groups:
        # Neutron API.
        TEST.api_q_secgroups.add(sg)
        for rule in sg['security_group_rules']:
            TEST.api_q_secgroup_rules.add(copy.copy(rule))
        # OpenStack Dashboard internaly API.
        TEST.q_secgroups.add(
            neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))
        for rule in sg['security_group_rules']:
            TEST.q_secgroup_rules.add(
                neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict))

    # LBaaS.

    # 1st pool.
    pool_dict = {
        'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
        'tenant_id': '1',
        'vip_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'name': 'pool1',
        'description': 'pool description',
        'subnet_id': TEST.subnets.first().id,
        'protocol': 'HTTP',
        'lb_method': 'ROUND_ROBIN',
        'health_monitors': TEST.monitors.list(),
        'members': ['78a46e5e-eb1a-418a-88c7-0e3f5968b08'],
        'admin_state_up': True,
        'status': 'ACTIVE',
        'provider': 'haproxy'
    }
    TEST.api_pools.add(pool_dict)
    TEST.pools.add(lbaas.Pool(pool_dict))

    # 2nd pool.
    pool_dict = {
        'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d50',
        'tenant_id': '1',
        'vip_id': 'f0881d38-c3eb-4fee-9763-12de3338041d',
        'name': 'pool2',
        'description': 'pool description',
        'subnet_id': TEST.subnets.first().id,
        'protocol': 'HTTPS',
        'lb_method': 'ROUND_ROBIN',
        'health_monitors': TEST.monitors.list()[0:1],
        'members': [],
        'status': 'PENDING_CREATE',
        'admin_state_up': True
    }
    TEST.api_pools.add(pool_dict)
    TEST.pools.add(lbaas.Pool(pool_dict))

    # 1st vip.
    vip_dict = {
        'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'name': 'vip1',
        'address': '10.0.0.100',
        'description': 'vip description',
        'subnet_id': TEST.subnets.first().id,
        'port_id': TEST.ports.first().id,
        'subnet': TEST.subnets.first().cidr,
        'protocol_port': 80,
        'protocol': pool_dict['protocol'],
        'pool_id': pool_dict['id'],
        'session_persistence': {
            'type': 'APP_COOKIE',
            'cookie_name': 'jssessionid'
        },
        'connection_limit': 10,
        'admin_state_up': True
    }
    TEST.api_vips.add(vip_dict)
    TEST.vips.add(lbaas.Vip(vip_dict))

    # 2nd vip.
    vip_dict = {
        'id': 'f0881d38-c3eb-4fee-9763-12de3338041d',
        'name': 'vip2',
        'address': '10.0.0.110',
        'description': 'vip description',
        'subnet_id': TEST.subnets.first().id,
        'port_id': TEST.ports.list()[0].id,
        'subnet': TEST.subnets.first().cidr,
        'protocol_port': 80,
        'protocol': pool_dict['protocol'],
        'pool_id': pool_dict['id'],
        'session_persistence': {
            'type': 'APP_COOKIE',
            'cookie_name': 'jssessionid'
        },
        'connection_limit': 10,
        'admin_state_up': True
    }
    TEST.api_vips.add(vip_dict)
    TEST.vips.add(lbaas.Vip(vip_dict))

    # 1st member.
    member_dict = {
        'id': '78a46e5e-eb1a-418a-88c7-0e3f5968b08',
        'tenant_id': '1',
        'pool_id': pool_dict['id'],
        'address': '10.0.0.11',
        'protocol_port': 80,
        'weight': 10,
        'status': 'ACTIVE',
        'admin_state_up': True
    }
    TEST.api_members.add(member_dict)
    TEST.members.add(lbaas.Member(member_dict))

    # 2nd member.
    member_dict = {
        'id': '41ac1f8d-6d9c-49a4-a1bf-41955e651f91',
        'tenant_id': '1',
        'pool_id': pool_dict['id'],
        'address': '10.0.0.12',
        'protocol_port': 80,
        'weight': 10,
        'status': 'ACTIVE',
        'admin_state_up': True
    }
    TEST.api_members.add(member_dict)
    TEST.members.add(lbaas.Member(member_dict))

    # 1st monitor.
    monitor_dict = {
        'id':
        'd4a0500f-db2b-4cc4-afcf-ec026febff96',
        'type':
        'http',
        'delay':
        10,
        'timeout':
        10,
        'max_retries':
        10,
        'http_method':
        'GET',
        'url_path':
        '/',
        'expected_codes':
        '200',
        'admin_state_up':
        True,
        "pools": [{
            "pool_id": TEST.pools.list()[0].id
        }, {
            "pool_id": TEST.pools.list()[1].id
        }],
    }
    TEST.api_monitors.add(monitor_dict)
    TEST.monitors.add(lbaas.PoolMonitor(monitor_dict))

    # 2nd monitor.
    monitor_dict = {
        'id': 'd4a0500f-db2b-4cc4-afcf-ec026febff97',
        'type': 'ping',
        'delay': 10,
        'timeout': 10,
        'max_retries': 10,
        'admin_state_up': True,
        'pools': [],
    }
    TEST.api_monitors.add(monitor_dict)
    TEST.monitors.add(lbaas.PoolMonitor(monitor_dict))

    # Quotas.
    quota_data = {
        'network': '10',
        'subnet': '10',
        'port': '50',
        'router': '10',
        'floatingip': '50',
        'security_group': '20',
        'security_group_rule': '100',
    }
    TEST.neutron_quotas.add(base.QuotaSet(quota_data))

    # Quota Usages
    quota_usage_data = {
        'networks': {
            'used': 0,
            'quota': 5
        },
        'subnets': {
            'used': 0,
            'quota': 5
        },
        'routers': {
            'used': 0,
            'quota': 5
        },
    }
    quota_usage = usage_quotas.QuotaUsage()
    for k, v in quota_usage_data.items():
        quota_usage.add_quota(base.Quota(k, v['quota']))
        quota_usage.tally(k, v['used'])

    TEST.neutron_quota_usages.add(quota_usage)

    # Extensions.
    extension_1 = {
        "name": "security-group",
        "alias": "security-group",
        "description": "The security groups extension."
    }
    extension_2 = {
        "name": "Quota management support",
        "alias": "quotas",
        "description": "Expose functions for quotas management"
    }
    extension_3 = {
        "name": "Provider network",
        "alias": "provider",
        "description": "Provider network extension"
    }
    extension_4 = {
        "name": "Distributed Virtual Router",
        "alias": "dvr",
        "description": "Enables configuration of Distributed Virtual Routers."
    }
    extension_5 = {
        "name": "HA Router extension",
        "alias": "l3-ha",
        "description": "Add HA capability to routers."
    }
    extension_6 = {
        "name": "LoadBalancing service",
        "alias": "lbaas",
        "description": "Extension for LoadBalancing service"
    }
    TEST.api_extensions.add(extension_1)
    TEST.api_extensions.add(extension_2)
    TEST.api_extensions.add(extension_3)
    TEST.api_extensions.add(extension_4)
    TEST.api_extensions.add(extension_5)
    TEST.api_extensions.add(extension_6)

    # 1st agent.
    agent_dict = {
        "binary": "neutron-openvswitch-agent",
        "description": None,
        "admin_state_up": True,
        "heartbeat_timestamp": "2013-07-26 06:51:47",
        "alive": True,
        "id": "c876ff05-f440-443e-808c-1d34cda3e88a",
        "topic": "N/A",
        "host": "devstack001",
        "agent_type": "Open vSwitch agent",
        "started_at": "2013-07-26 05:23:28",
        "created_at": "2013-07-26 05:23:28",
        "configurations": {
            "devices": 2
        }
    }
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # 2nd agent.
    agent_dict = {
        "binary": "neutron-dhcp-agent",
        "description": None,
        "admin_state_up": True,
        "heartbeat_timestamp": "2013-07-26 06:51:48",
        "alive": True,
        "id": "f0d12e3d-1973-41a2-b977-b95693f9a8aa",
        "topic": "dhcp_agent",
        "host": "devstack001",
        "agent_type": "DHCP agent",
        "started_at": "2013-07-26 05:23:30",
        "created_at": "2013-07-26 05:23:30",
        "configurations": {
            "subnets": 1,
            "use_namespaces": True,
            "dhcp_lease_duration": 120,
            "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq",
            "networks": 1,
            "ports": 1
        }
    }
    TEST.api_agents.add(agent_dict)
    TEST.agents.add(neutron.Agent(agent_dict))

    # Service providers.
    provider_1 = {
        "service_type": "LOADBALANCER",
        "name": "haproxy",
        "default": True
    }
    TEST.providers.add(provider_1)

    # VPNaaS.

    # 1st VPNService.
    vpnservice_dict = {
        'id': '09a26949-6231-4f72-942a-0c8c0ddd4d61',
        'tenant_id': '1',
        'name': 'cloud_vpn1',
        'description': 'vpn description',
        'subnet_id': TEST.subnets.first().id,
        'router_id': TEST.routers.first().id,
        'vpn_type': 'ipsec',
        'ipsecsiteconnections': [],
        'admin_state_up': True,
        'status': 'Active',
        'ipsecsiteconns': TEST.ipsecsiteconnections.list()
    }
    TEST.api_vpnservices.add(vpnservice_dict)
    TEST.vpnservices.add(vpn.VPNService(vpnservice_dict))

    # 2nd VPNService.
    vpnservice_dict = {
        'id': '09a26949-6231-4f72-942a-0c8c0ddd4d62',
        'tenant_id': '1',
        'name': 'cloud_vpn2',
        'description': 'vpn description',
        'subnet_id': TEST.subnets.first().id,
        'router_id': TEST.routers.first().id,
        'vpn_type': 'ipsec',
        'ipsecsiteconnections': [],
        'admin_state_up': True,
        'status': 'Active',
        'ipsecsiteconns': []
    }
    TEST.api_vpnservices.add(vpnservice_dict)
    TEST.vpnservices.add(vpn.VPNService(vpnservice_dict))

    # 1st IKEPolicy
    ikepolicy_dict = {
        'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c981',
        'tenant_id': '1',
        'name': 'ikepolicy_1',
        'description': 'ikepolicy description',
        'auth_algorithm': 'sha1',
        'encryption_algorithm': 'aes-256',
        'ike_version': 'v1',
        'lifetime': {
            'units': 'seconds',
            'value': 3600
        },
        'phase1_negotiation_mode': 'main',
        'pfs': 'group5',
        'ipsecsiteconns': TEST.ipsecsiteconnections.list()
    }
    TEST.api_ikepolicies.add(ikepolicy_dict)
    TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict))

    # 2nd IKEPolicy
    ikepolicy_dict = {
        'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c982',
        'tenant_id': '1',
        'name': 'ikepolicy_2',
        'description': 'ikepolicy description',
        'auth_algorithm': 'sha1',
        'encryption_algorithm': 'aes-256',
        'ike_version': 'v1',
        'lifetime': {
            'units': 'seconds',
            'value': 3600
        },
        'phase1_negotiation_mode': 'main',
        'pfs': 'group5',
        'ipsecsiteconns': []
    }
    TEST.api_ikepolicies.add(ikepolicy_dict)
    TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict))

    # 1st IPSecPolicy
    ipsecpolicy_dict = {
        'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb8',
        'tenant_id': '1',
        'name': 'ipsecpolicy_1',
        'description': 'ipsecpolicy description',
        'auth_algorithm': 'sha1',
        'encapsulation_mode': 'tunnel',
        'encryption_algorithm': '3des',
        'lifetime': {
            'units': 'seconds',
            'value': 3600
        },
        'pfs': 'group5',
        'transform_protocol': 'esp',
        'ipsecsiteconns': TEST.ipsecsiteconnections.list()
    }
    TEST.api_ipsecpolicies.add(ipsecpolicy_dict)
    TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict))

    # 2nd IPSecPolicy
    ipsecpolicy_dict = {
        'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb9',
        'tenant_id': '1',
        'name': 'ipsecpolicy_2',
        'description': 'ipsecpolicy description',
        'auth_algorithm': 'sha1',
        'encapsulation_mode': 'tunnel',
        'encryption_algorithm': '3des',
        'lifetime': {
            'units': 'seconds',
            'value': 3600
        },
        'pfs': 'group5',
        'transform_protocol': 'esp',
        'ipsecsiteconns': []
    }
    TEST.api_ipsecpolicies.add(ipsecpolicy_dict)
    TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict))

    # 1st IPSecSiteConnection
    ipsecsiteconnection_dict = {
        'id': 'dd1dd3a0-f349-49be-b013-245e147763d6',
        'tenant_id': '1',
        'name': 'ipsec_connection_1',
        'description': 'vpn connection description',
        'dpd': {
            'action': 'hold',
            'interval': 30,
            'timeout': 120
        },
        'ikepolicy_id': ikepolicy_dict['id'],
        'initiator': 'bi-directional',
        'ipsecpolicy_id': ipsecpolicy_dict['id'],
        'mtu': 1500,
        'peer_address': '2607:f0d0:4545:3:200:f8ff:fe21:67cf',
        'peer_cidrs': ['20.1.0.0/24', '21.1.0.0/24'],
        'peer_id': '2607:f0d0:4545:3:200:f8ff:fe21:67cf',
        'psk': 'secret',
        'vpnservice_id': vpnservice_dict['id'],
        'admin_state_up': True,
        'status': 'Active'
    }
    TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict)
    TEST.ipsecsiteconnections.add(
        vpn.IPSecSiteConnection(ipsecsiteconnection_dict))

    # 2nd IPSecSiteConnection
    ipsecsiteconnection_dict = {
        'id': 'dd1dd3a0-f349-49be-b013-245e147763d7',
        'tenant_id': '1',
        'name': 'ipsec_connection_2',
        'description': 'vpn connection description',
        'dpd': {
            'action': 'hold',
            'interval': 30,
            'timeout': 120
        },
        'ikepolicy_id': ikepolicy_dict['id'],
        'initiator': 'bi-directional',
        'ipsecpolicy_id': ipsecpolicy_dict['id'],
        'mtu': 1500,
        'peer_address': '172.0.0.2',
        'peer_cidrs': ['20.1.0.0/24'],
        'peer_id': '172.0.0.2',
        'psk': 'secret',
        'vpnservice_id': vpnservice_dict['id'],
        'admin_state_up': True,
        'status': 'Active'
    }
    TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict)
    TEST.ipsecsiteconnections.add(
        vpn.IPSecSiteConnection(ipsecsiteconnection_dict))

    # FWaaS

    # 1st rule (used by 1st policy)
    rule1_dict = {
        'id': 'f0881d38-c3eb-4fee-9763-12de3338041d',
        'tenant_id': '1',
        'name': 'rule1',
        'description': 'rule1 description',
        'protocol': 'tcp',
        'action': 'allow',
        'source_ip_address': '1.2.3.0/24',
        'source_port': '80',
        'destination_ip_address': '4.5.6.7/32',
        'destination_port': '1:65535',
        'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'position': 1,
        'shared': True,
        'enabled': True
    }
    TEST.api_fw_rules.add(rule1_dict)

    rule1 = fwaas.Rule(copy.deepcopy(rule1_dict))
    # NOTE: rule1['policy'] is set below
    TEST.fw_rules.add(rule1)

    # 2nd rule (used by 2nd policy; no name)
    rule2_dict = {
        'id': 'c6298a93-850f-4f64-b78a-959fd4f1e5df',
        'tenant_id': '1',
        'name': '',
        'description': '',
        'protocol': 'udp',
        'action': 'deny',
        'source_ip_address': '1.2.3.0/24',
        'source_port': '80',
        'destination_ip_address': '4.5.6.7/32',
        'destination_port': '1:65535',
        'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'position': 2,
        'shared': True,
        'enabled': True
    }
    TEST.api_fw_rules.add(rule2_dict)

    rule2 = fwaas.Rule(copy.deepcopy(rule2_dict))
    # NOTE: rule2['policy'] is set below
    TEST.fw_rules.add(rule2)

    # 3rd rule (not used by any policy)
    rule3_dict = {
        'id': 'h0881d38-c3eb-4fee-9763-12de3338041d',
        'tenant_id': '1',
        'name': 'rule3',
        'description': 'rule3 description',
        'protocol': None,
        'action': 'allow',
        'source_ip_address': '1.2.3.0/24',
        'source_port': '80',
        'destination_ip_address': '4.5.6.7/32',
        'destination_port': '1:65535',
        'firewall_policy_id': None,
        'position': None,
        'shared': True,
        'enabled': True
    }
    TEST.api_fw_rules.add(rule3_dict)

    rule3 = fwaas.Rule(copy.deepcopy(rule3_dict))
    # rule3 is not associated with any rules
    rule3._apidict['policy'] = None
    TEST.fw_rules.add(rule3)

    # 1st policy (associated with 2 rules)
    policy1_dict = {
        'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'tenant_id': '1',
        'name': 'policy1',
        'description': 'policy with two rules',
        'firewall_rules': [rule1_dict['id'], rule2_dict['id']],
        'audited': True,
        'shared': True
    }
    TEST.api_fw_policies.add(policy1_dict)

    policy1 = fwaas.Policy(copy.deepcopy(policy1_dict))
    policy1._apidict['rules'] = [rule1, rule2]
    TEST.fw_policies.add(policy1)

    # Reverse relations (rule -> policy)
    rule1._apidict['policy'] = policy1
    rule2._apidict['policy'] = policy1

    # 2nd policy (associated with no rules; no name)
    policy2_dict = {
        'id': 'cf50b331-787a-4623-825e-da794c918d6a',
        'tenant_id': '1',
        'name': '',
        'description': '',
        'firewall_rules': [],
        'audited': False,
        'shared': False
    }
    TEST.api_fw_policies.add(policy2_dict)

    policy2 = fwaas.Policy(copy.deepcopy(policy2_dict))
    policy2._apidict['rules'] = []
    TEST.fw_policies.add(policy2)

    # 1st firewall
    fw1_dict = {
        'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
        'tenant_id': '1',
        'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'name': 'firewall1',
        'router_ids': [TEST.routers.first().id],
        'description': 'firewall description',
        'status': 'PENDING_CREATE',
        'admin_state_up': True
    }
    TEST.api_firewalls.add(fw1_dict)

    fw1 = fwaas.Firewall(copy.deepcopy(fw1_dict))
    fw1._apidict['policy'] = policy1
    fw1._apidict['routers'] = [TEST.routers.first()]
    TEST.firewalls.add(fw1)

    # 2nd firewall (no name)
    fw2_dict = {
        'id': '1aa75150-415f-458e-bae5-5a362a4fb1f7',
        'tenant_id': '1',
        'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
        'name': '',
        'description': '',
        'status': 'PENDING_CREATE',
        'admin_state_up': True
    }
    TEST.api_firewalls.add(fw1_dict)

    fw2 = fwaas.Firewall(copy.deepcopy(fw2_dict))
    fw2._apidict['policy'] = policy1
    TEST.firewalls.add(fw1)

    # Additional Cisco N1K profiles.

    # 2nd network profile for network when using the cisco n1k plugin.
    # Profile applied on 1st network.
    net_profile_dict = {
        'name': 'net_profile_test2',
        'segment_type': 'overlay',
        'sub_type': 'native_vxlan',
        'segment_range': '10000-10100',
        'multicast_ip_range': '144.0.0.0-144.0.0.100',
        'id': '00000000-2222-2222-2222-000000000000',
        'project': '1',
        # overlay profiles have no physical_network
        'physical_network': None
    }

    TEST.api_net_profiles.add(net_profile_dict)
    TEST.net_profiles.add(neutron.Profile(net_profile_dict))

    # 2nd network profile binding.
    network_profile_binding_dict = {
        'profile_id': '00000000-2222-2222-2222-000000000000',
        'tenant_id': '1'
    }

    TEST.api_network_profile_binding.add(network_profile_binding_dict)
    TEST.network_profile_binding.add(
        neutron.Profile(network_profile_binding_dict))

    # 3rd network profile for network when using the cisco n1k plugin
    # Profile applied on 1st network
    net_profile_dict = {
        'name': 'net_profile_test3',
        'segment_type': 'overlay',
        'sub_type': 'other',
        'other_subtype': 'GRE',
        'segment_range': '11000-11100',
        'id': '00000000-3333-3333-3333-000000000000',
        'project': '1'
    }

    TEST.api_net_profiles.add(net_profile_dict)
    TEST.net_profiles.add(neutron.Profile(net_profile_dict))

    # 3rd network profile binding
    network_profile_binding_dict = {
        'profile_id': '00000000-3333-3333-3333-000000000000',
        'tenant_id': '1'
    }

    TEST.api_network_profile_binding.add(network_profile_binding_dict)
    TEST.network_profile_binding.add(
        neutron.Profile(network_profile_binding_dict))

    # 4th network profile for network when using the cisco n1k plugin
    # Profile applied on 1st network
    net_profile_dict = {
        'name': 'net_profile_test4',
        'segment_type': 'trunk',
        'sub_type_trunk': 'vlan',
        'id': '00000000-4444-4444-4444-000000000000',
        'project': '1'
    }

    TEST.api_net_profiles.add(net_profile_dict)
    TEST.net_profiles.add(neutron.Profile(net_profile_dict))

    # 4th network profile binding
    network_profile_binding_dict = {
        'profile_id': '00000000-4444-4444-4444-000000000000',
        'tenant_id': '1'
    }

    TEST.api_network_profile_binding.add(network_profile_binding_dict)
    TEST.network_profile_binding.add(
        neutron.Profile(network_profile_binding_dict))

    # Adding a new network and new network and policy profile
    # similar to the first to test launching an instance with multiple
    # nics and multiple profiles.

    # 4th network to use for testing instances with multiple-nics & profiles
    network_dict = {
        'admin_state_up': True,
        'id': '7aa23d91-ffff-abab-dcdc-3411ae767e8a',
        'name': 'net4',
        'status': 'ACTIVE',
        'subnets': ['31be4a21-aadd-73da-6422-821ff249a4bb'],
        'tenant_id': '1',
        'router:external': False,
        'shared': False
    }
    subnet_dict = {
        'allocation_pools': [{
            'end': '11.10.0.254',
            'start': '11.10.0.2'
        }],
        'dns_nameservers': [],
        'host_routes': [],
        'cidr': '11.10.0.0/24',
        'enable_dhcp': True,
        'gateway_ip': '11.10.0.1',
        'id': network_dict['subnets'][0],
        'ip_version': 4,
        'name': 'mysubnet4',
        'network_id': network_dict['id'],
        'tenant_id': network_dict['tenant_id']
    }

    TEST.api_networks.add(network_dict)
    TEST.api_subnets.add(subnet_dict)

    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    # 5th network profile for network when using the cisco n1k plugin
    # Network Profile applied on 4th network
    net_profile_dict = {
        'name': 'net_profile_test5',
        'segment_type': 'vlan',
        'physical_network': 'phys5',
        'segment_range': '400-450',
        'id': '00000000-5555-5555-5555-000000000000',
        'project': TEST.networks.get(name="net4")['tenant_id']
    }

    TEST.api_net_profiles.add(net_profile_dict)
    TEST.net_profiles.add(neutron.Profile(net_profile_dict))

    # 2nd policy profile for port when using the cisco n1k plugin
    policy_profile_dict = {
        'name': 'policy_profile_test2',
        'id': '11111111-9999-9999-9999-111111111111'
    }

    TEST.api_policy_profiles.add(policy_profile_dict)
    TEST.policy_profiles.add(neutron.Profile(policy_profile_dict))

    # network profile binding
    network_profile_binding_dict = {
        'profile_id': '00000000-5555-5555-5555-000000000000',
        'tenant_id': TEST.networks.get(name="net4")['tenant_id']
    }

    TEST.api_network_profile_binding.add(network_profile_binding_dict)
    TEST.network_profile_binding.add(
        neutron.Profile(network_profile_binding_dict))

    # policy profile binding
    policy_profile_binding_dict = {
        'profile_id': '11111111-9999-9999-9999-111111111111',
        'tenant_id': TEST.networks.get(name="net4")['tenant_id']
    }

    TEST.api_policy_profile_binding.add(policy_profile_binding_dict)
    TEST.policy_profile_binding.add(
        neutron.Profile(policy_profile_binding_dict))

    # ports on 4th network
    port_dict = {
        'admin_state_up':
        True,
        'device_id':
        '9872faaa-b2b2-eeee-9911-21332eedaa77',
        'device_owner':
        'network:dhcp',
        'fixed_ips': [{
            'ip_address': '11.10.0.3',
            'subnet_id': TEST.subnets.get(name="mysubnet4")['id']
        }],
        'id':
        'a21dcd22-6733-cccc-aa32-22adafaf16a2',
        'mac_address':
        '78:22:ff:1a:ba:23',
        'name':
        'port5',
        'network_id':
        TEST.networks.get(name="net4")['id'],
        'status':
        'ACTIVE',
        'tenant_id':
        TEST.networks.get(name="net4")['tenant_id'],
        'binding:vnic_type':
        'normal',
        'binding:host_id':
        'host'
    }
    TEST.api_ports.add(port_dict)
    TEST.ports.add(neutron.Port(port_dict))