def test_quotaset_add_doesnt_override_existing_quota(self): quota_dict = {'foo': 1, 'bar': 10} quota_set = api_base.QuotaSet(quota_dict) other_quota_set = api_base.QuotaSet({'foo': 12}) quota_set += other_quota_set self.assertEqual(2, len(quota_set)) for q in quota_set: self.assertEqual(quota_dict[q.name], q.limit)
def test_quotaset_add_with_plus(self): quota_dict = {'foo': 1, 'bar': 10} other_quota_dict = {'my_test': 12} quota_set = api_base.QuotaSet(quota_dict) other_quota_set = api_base.QuotaSet(other_quota_dict) quota_set += other_quota_set self.assertEqual(len(quota_set), 3) quota_dict.update(other_quota_dict) for q in quota_set: self.assertEqual(q.limit, quota_dict[q.name])
def test_quotaset_add_method(self): quota_dict = {'foo': 1, 'bar': 10} other_quota_dict = {'my_test': 12} quota_set = api_base.QuotaSet(quota_dict) other_quota_set = api_base.QuotaSet(other_quota_dict) quota_set.add(other_quota_set) self.assertEqual(3, len(quota_set)) quota_dict.update(other_quota_dict) for q in quota_set: self.assertEqual(quota_dict[q.name], q.limit)
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)
def _get_quota_data(request, method_name, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id #quotasets.append(getattr(nova, method_name)(request, tenant_id)) if is_m1_user_admin(request): quotasets.append(tenant_quota_get_nova(request, tenant_id)) else: quotasets.append(getattr(nova, method_name)(request, tenant_id)) qs = base.QuotaSet() if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) if 'volumes' not in disabled_quotas: try: #quotasets.append(getattr(cinder, method_name)(request, tenant_id)) if is_m1_user_admin(request): quotasets.append(tenant_quota_get_cinder(request, tenant_id)) else: quotasets.append( getattr(cinder, method_name)(request, tenant_id)) except cinder.ClientException: disabled_quotas.extend(CINDER_QUOTA_FIELDS) msg = _("Unable to retrieve volume limit information.") exceptions.handle(request, msg) for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas: qs[quota.name] = quota.limit return qs
def get_default_quota_data(request, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) if NOVA_QUOTA_FIELDS - disabled_quotas: quotasets.append(nova.default_quota_get(request, tenant_id)) if CINDER_QUOTA_FIELDS - disabled_quotas: try: quotasets.append(cinder.default_quota_get(request, tenant_id)) except cinder.cinder_exception.ClientException: disabled_quotas.update(CINDER_QUOTA_FIELDS) msg = _("Unable to retrieve volume quota information.") exceptions.handle(request, msg) if NEUTRON_QUOTA_FIELDS - disabled_quotas: # TODO(jpichon): There is no API to access the Neutron default quotas # (LP#1204956). For now, use the values from the current project. try: quotasets.append( neutron.tenant_quota_get(request, tenant_id=tenant_id)) except Exception: disabled_quotas.update(NEUTRON_QUOTA_FIELDS) msg = _('Unable to retrieve Neutron quota information.') exceptions.handle(request, msg) qs = base.QuotaSet() for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS: qs[quota.name] = quota.limit return qs
def _get_quota_data(request, tenant_mode=True, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) qs = base.QuotaSet() if NOVA_QUOTA_FIELDS - disabled_quotas: if tenant_mode: quotasets.append(nova.tenant_quota_get(request, tenant_id)) else: quotasets.append(nova.default_quota_get(request, tenant_id)) if CINDER_QUOTA_FIELDS - disabled_quotas: try: if tenant_mode: quotasets.append(cinder.tenant_quota_get(request, tenant_id)) else: quotasets.append(cinder.default_quota_get(request, tenant_id)) except cinder.cinder_exception.ClientException: disabled_quotas.update(CINDER_QUOTA_FIELDS) msg = _("Unable to retrieve volume limit information.") exceptions.handle(request, msg) for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas: qs[quota.name] = quota.limit return qs
def _get_tenant_network_usages_legacy(request, usages, disabled_quotas, tenant_id): qs = base.QuotaSet() _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id) for quota in qs: usages.add_quota(quota) # TODO(amotoki): Add security_group_rule? resource_lister = { 'network': (neutron.network_list, { 'tenant_id': tenant_id }), 'subnet': (neutron.subnet_list, { 'tenant_id': tenant_id }), 'port': (neutron.port_list, { 'tenant_id': tenant_id }), 'router': (neutron.router_list, { 'tenant_id': tenant_id }), 'floatingip': (neutron.tenant_floating_ip_list, {}), 'security_group': (neutron.security_group_list, {}), } for quota_name, lister_info in resource_lister.items(): if quota_name not in disabled_quotas: lister = lister_info[0] kwargs = lister_info[1] try: resources = lister(request, **kwargs) except Exception: resources = [] usages.tally(quota_name, len(resources))
def _get_tenant_network_usages_legacy(request, usages, disabled_quotas, tenant_id): warnings.warn( "The legacy way to retrieve neutron resource usage is deprecated " "in Ussuri release. Horizon will depend on 'quota_details' " "neutron extension added in Pike release in future.", DeprecationWarning) qs = base.QuotaSet() _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id) for quota in qs: usages.add_quota(quota) resource_lister = { 'network': (neutron.network_list, { 'tenant_id': tenant_id }), 'subnet': (neutron.subnet_list, { 'tenant_id': tenant_id }), 'port': (neutron.port_list, { 'tenant_id': tenant_id }), 'router': (neutron.router_list, { 'tenant_id': tenant_id }), 'floatingip': (neutron.tenant_floating_ip_list, {}), } for quota_name, lister_info in resource_lister.items(): if quota_name not in disabled_quotas: lister = lister_info[0] kwargs = lister_info[1] try: resources = lister(request, **kwargs) except Exception: resources = [] usages.tally(quota_name, len(resources)) # Security groups have to be processed separately so that rules may be # processed in the same api call and in a single pass add_sg = 'security_group' not in disabled_quotas add_sgr = 'security_group_rule' not in disabled_quotas if add_sg or add_sgr: try: security_groups = neutron.security_group_list(request) num_rules = sum( len(group['security_group_rules']) for group in security_groups) except Exception: security_groups = [] num_rules = 0 if add_sg: usages.tally('security_group', len(security_groups)) if add_sgr: usages.tally('security_group_rule', num_rules)
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None): qs = _get_quota_data(request, tenant_mode=True, disabled_quotas=disabled_quotas, tenant_id=tenant_id) if not disabled_quotas: return qs # Check if neutron is enabled by looking for network if 'network' not in disabled_quotas: # mj - another quota hack. This is fixed properly in Queens. #tenant_id = tenant_id or request.user.tenant_id neutron_quotas = neutron.tenant_quota_get(request, tenant_id) if 'floating_ips' in disabled_quotas: # Neutron with quota extension disabled if 'floatingip' in disabled_quotas: qs.add(base.QuotaSet({'floating_ips': -1})) # Neutron with quota extension enabled else: # Rename floatingip to floating_ips since that's how it's # expected in some places (e.g. Security & Access' Floating IPs) fips_quota = neutron_quotas.get('floatingip').limit qs.add(base.QuotaSet({'floating_ips': fips_quota})) if 'security_groups' in disabled_quotas: if 'security_group' in disabled_quotas: qs.add(base.QuotaSet({'security_groups': -1})) # Neutron with quota extension enabled else: # Rename security_group to security_groups since that's how it's # expected in some places (e.g. Security & Access' Security Groups) sec_quota = neutron_quotas.get('security_group').limit qs.add(base.QuotaSet({'security_groups': sec_quota})) if 'network' in disabled_quotas: for item in qs.items: if item.name == 'networks': qs.items.remove(item) break else: net_quota = neutron_quotas.get('network').limit qs.add(base.QuotaSet({'networks': net_quota})) if 'subnet' in disabled_quotas: for item in qs.items: if item.name == 'subnets': qs.items.remove(item) break else: net_quota = neutron_quotas.get('subnet').limit qs.add(base.QuotaSet({'subnets': net_quota})) if 'router' in disabled_quotas: for item in qs.items: if item.name == 'routers': qs.items.remove(item) break else: router_quota = neutron_quotas.get('router').limit qs.add(base.QuotaSet({'routers': router_quota})) return qs
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
def _get_mock_share_quota_data(self): quota_data = { 'shares': 24, 'gigabytes': 333, 'snapshots': 14, 'snapshot_gigabytes': 444, 'share_networks': 14 } return base.QuotaSet(quota_data)
def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id): tenant_id = tenant_id or request.user.tenant_id neutron_quotas = neutron.tenant_quota_get(request, tenant_id) for quota_name in NEUTRON_QUOTA_FIELDS: if quota_name not in disabled_quotas: quota_data = neutron_quotas.get(quota_name).limit qs.add(base.QuotaSet({quota_name: quota_data})) return qs
def _get_tenant_network_usages_legacy(request, usages, disabled_quotas, tenant_id): qs = base.QuotaSet() _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id) for quota in qs: usages.add_quota(quota) resource_lister = { 'network': (neutron.network_list, { 'tenant_id': tenant_id }), 'subnet': (neutron.subnet_list, { 'tenant_id': tenant_id }), 'port': (neutron.port_list, { 'tenant_id': tenant_id }), 'router': (neutron.router_list, { 'tenant_id': tenant_id }), 'floatingip': (neutron.tenant_floating_ip_list, {}), } for quota_name, lister_info in resource_lister.items(): if quota_name not in disabled_quotas: lister = lister_info[0] kwargs = lister_info[1] try: resources = lister(request, **kwargs) except Exception: resources = [] usages.tally(quota_name, len(resources)) # Security groups have to be processed separately so that rules may be # processed in the same api call and in a single pass add_sg = 'security_group' not in disabled_quotas add_sgr = 'security_group_rule' not in disabled_quotas if add_sg or add_sgr: try: security_groups = neutron.security_group_list(request) num_rules = sum( len(group['security_group_rules']) for group in security_groups) except Exception: security_groups = [] num_rules = 0 if add_sg: usages.tally('security_group', len(security_groups)) if add_sgr: usages.tally('security_group_rule', num_rules)
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None): qs = _get_quota_data(request, "tenant_quota_get", disabled_quotas=disabled_quotas, tenant_id=tenant_id) # TODO(jpichon): There is no API to get the default system quotas # in Neutron (cf. LP#1204956), so for now handle tenant quotas here. # This should be handled in _get_quota_data() eventually. if disabled_quotas and 'floating_ips' in disabled_quotas: # Neutron with quota extension disabled if 'floatingip' in disabled_quotas: qs.add(base.QuotaSet({'floating_ips': -1})) # Neutron with quota extension enabled else: tenant_id = tenant_id or request.user.tenant_id neutron_quotas = neutron.tenant_quota_get(request, tenant_id) # Rename floatingip to floating_ips since that's how it's # expected in some places (e.g. Security & Access' Floating IPs) fips_quota = neutron_quotas.get('floatingip').limit qs.add(base.QuotaSet({'floating_ips': fips_quota})) return qs
def _get_quota_data(request, method_name, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id quotasets.append(getattr(nova, method_name)(request, tenant_id)) qs = base.QuotaSet() if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) if 'volumes' not in disabled_quotas: quotasets.append(getattr(cinder, method_name)(request, tenant_id)) for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas: qs[quota.name] = quota.limit return qs
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None): qs = _get_quota_data(request, tenant_mode=True, disabled_quotas=disabled_quotas, tenant_id=tenant_id) # TODO(jpichon): There is no API to get the default system quotas # in Neutron (cf. LP#1204956), so for now handle tenant quotas here. # This should be handled in _get_quota_data() eventually. # TODO(amotoki): Purge this tricky usage. # openstack_dashboard/dashboards/identity/projects/views.py # calls get_tenant_quota_data directly and it expects # neutron data is not returned. if not disabled_quotas: return qs # Check if neutron is enabled by looking for network if not (NEUTRON_QUOTA_FIELDS - disabled_quotas): return qs tenant_id = tenant_id or request.user.tenant_id neutron_quotas = neutron.tenant_quota_get(request, tenant_id) if 'floating_ips' in disabled_quotas: if 'floatingip' not in disabled_quotas: # Rename floatingip to floating_ips since that's how it's # expected in some places (e.g. Security & Access' Floating IPs) fips_quota = neutron_quotas.get('floatingip').limit qs.add(base.QuotaSet({'floating_ips': fips_quota})) if 'security_groups' in disabled_quotas: if 'security_group' not in disabled_quotas: # Rename security_group to security_groups since that's how it's # expected in some places (e.g. Security & Access' Security Groups) sec_quota = neutron_quotas.get('security_group').limit qs.add(base.QuotaSet({'security_groups': sec_quota})) if 'network' not in disabled_quotas: net_quota = neutron_quotas.get('network').limit qs.add(base.QuotaSet({'networks': net_quota})) if 'subnet' not in disabled_quotas: net_quota = neutron_quotas.get('subnet').limit qs.add(base.QuotaSet({'subnets': net_quota})) if 'port' not in disabled_quotas: net_quota = neutron_quotas.get('port').limit qs.add(base.QuotaSet({'ports': net_quota})) if 'router' not in disabled_quotas: router_quota = neutron_quotas.get('router').limit qs.add(base.QuotaSet({'routers': router_quota})) return qs
def _get_quota_data(request, tenant_mode=True, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) qs = base.QuotaSet() if 'instances' not in disabled_quotas: if tenant_mode: quotasets.append(nova.tenant_quota_get(request, tenant_id)) else: quotasets.append(nova.default_quota_get(request, tenant_id)) if 'volumes' not in disabled_quotas: try: if tenant_mode: quotasets.append(cinder.tenant_quota_get(request, tenant_id)) else: quotasets.append(cinder.default_quota_get(request, tenant_id)) except cinder.cinder_exception.ClientException: disabled_quotas.update(CINDER_QUOTA_FIELDS) msg = _("Unable to retrieve volume limit information.") exceptions.handle(request, msg) #mj - add the tenant_quota info from neutron - this is replaced in Queens if 'network' not in disabled_quotas: try: if tenant_mode: quotasets.append( neutron.tenant_quota_get(request, tenant_id=tenant_id)) else: quotasets.append(neutron.default_quota_get(request, tenant_id)) except Exception: disabled_quotas.update(NEUTRON_QUOTA_FIELDS) msg = _('Unable to retrieve Neutron quota information.') for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas: qs[quota.name] = quota.limit return qs
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None): qs = _get_quota_data(request, "tenant_quota_get", disabled_quotas=disabled_quotas, tenant_id=tenant_id) # TODO(jpichon): There is no API to get the default system quotas # in Neutron (cf. LP#1204956), so for now handle tenant quotas here. # This should be handled in _get_quota_data() eventually. if not disabled_quotas: return qs # Check if neutron is enabled by looking for network and router if 'network' and 'router' not in disabled_quotas: tenant_id = tenant_id or request.user.tenant_id neutron_quotas = neutron.tenant_quota_get(request, tenant_id) if 'floating_ips' in disabled_quotas: # Neutron with quota extension disabled if 'floatingip' in disabled_quotas: qs.add(base.QuotaSet({'floating_ips': -1})) # Neutron with quota extension enabled else: # Rename floatingip to floating_ips since that's how it's # expected in some places (e.g. Security & Access' Floating IPs) fips_quota = neutron_quotas.get('floatingip').limit qs.add(base.QuotaSet({'floating_ips': fips_quota})) if 'security_groups' in disabled_quotas: if 'security_group' in disabled_quotas: qs.add(base.QuotaSet({'security_groups': -1})) # Neutron with quota extension enabled else: # Rename security_group to security_groups since that's how it's # expected in some places (e.g. Security & Access' Security Groups) sec_quota = neutron_quotas.get('security_group').limit qs.add(base.QuotaSet({'security_groups': sec_quota})) if 'network' in disabled_quotas: for item in qs.items: if item.name == 'networks': qs.items.remove(item) break else: net_quota = neutron_quotas.get('network').limit qs.add(base.QuotaSet({'networks': net_quota})) if 'router' in disabled_quotas: for item in qs.items: if item.name == 'routers': qs.items.remove(item) break else: router_quota = neutron_quotas.get('router').limit qs.add(base.QuotaSet({'routers': router_quota})) return qs
def get_default_quota_data(request, disabled_quotas=None, tenant_id=None): quotasets = [] if not tenant_id: tenant_id = request.user.tenant_id if disabled_quotas is None: disabled_quotas = get_disabled_quotas(request) if NOVA_QUOTA_FIELDS - disabled_quotas: try: quotasets.append(nova.default_quota_get(request, tenant_id)) except Exception: disabled_quotas.update(NOVA_QUOTA_FIELDS) msg = _('Unable to retrieve Nova quota information.') exceptions.handle(request, msg) if CINDER_QUOTA_FIELDS - disabled_quotas: try: quotasets.append(cinder.default_quota_get(request, tenant_id)) except cinder.cinder_exception.ClientException: disabled_quotas.update(CINDER_QUOTA_FIELDS) msg = _("Unable to retrieve volume quota information.") exceptions.handle(request, msg) if NEUTRON_QUOTA_FIELDS - disabled_quotas: try: quotasets.append(neutron.default_quota_get(request, tenant_id=tenant_id)) except Exception: disabled_quotas.update(NEUTRON_QUOTA_FIELDS) msg = _('Unable to retrieve Neutron quota information.') exceptions.handle(request, msg) qs = base.QuotaSet() for quota in itertools.chain(*quotasets): if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS: qs[quota.name] = quota.limit return qs
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)
def tenant_quota_get(request, tenant_id): return base.QuotaSet(neutronclient(request).show_quota(tenant_id)['quota'])
def default_quota_get(request, tenant_id): return base.QuotaSet(novaclient(request).quotas.defaults(tenant_id))
def tenant_quota_get(request, tenant_id): return base.QuotaSet(novaclient(request).quotas.get(tenant_id))
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' })
def tenant_quota_get(request, tenant_id): c_client = cinderclient(request) if c_client is None: return base.QuotaSet() return base.QuotaSet(c_client.quotas.get(tenant_id))
def tenant_quota_get(request, tenant_id, region=None): return base.QuotaSet(novaclient(request, region=region).quotas.get(tenant_id))
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)
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.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': network_dict['tenant_id'] } 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'] } 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'] } TEST.api_ports.add(port_dict) TEST.ports.add(neutron.Port(port_dict)) assoc_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'] } 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) #------------------------------------------------------------ # 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': network_dict['id'], 'status': 'ACTIVE', 'tenant_id': '1' } TEST.api_ports.add(port_dict) TEST.ports.add(neutron.Port(port_dict)) router_dict = { 'id': '279989f7-54bb-41d9-ba42-0d61f12fda61', 'name': 'router1', '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', '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': '71fb25e9-cd9f-4a44-a780-85ec3bd8bdd7', 'name': 'rulerouter', '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': ['d4a0500f-db2b-4cc4-afcf-ec026febff96'], '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': ['d4a0500f-db2b-4cc4-afcf-ec026febff97'], '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', 'floatip_address': '', 'other_address': '10.0.0.100', 'description': 'vip description', 'subnet_id': TEST.subnets.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', 'floatip_address': '', 'other_address': '10.0.0.110', 'description': 'vip description', 'subnet_id': TEST.subnets.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)) # 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': 'ping', 'delay': 10, 'timeout': 10, 'max_retries': 10, 'http_method': 'GET', 'url_path': '/', 'expected_codes': '200', 'admin_state_up': True } 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, 'http_method': 'GET', 'url_path': '/', 'expected_codes': '200', 'admin_state_up': True } 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)) #------------------------------------------------------------ # 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" } TEST.api_extensions.add(extension_1) TEST.api_extensions.add(extension_2) #------------------------------------------------------------ # 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': 'icmp', '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', 'description': 'firewall description', 'status': 'PENDING_CREATE', 'shared': True, 'admin_state_up': True } TEST.api_firewalls.add(fw1_dict) fw1 = fwaas.Firewall(copy.deepcopy(fw1_dict)) fw1._apidict['policy'] = policy1 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', 'shared': True, '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' } 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))
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)