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 data(TEST): TEST.stacks = TestDataContainer() TEST.stack_templates = TestDataContainer() # Stacks stack1 = { "description": "No description", "links": [{ "href": "http://192.168.1.70:8004/v1/" "051c727ee67040d6a7b7812708485a97/" "stacks/stack-1211-38/" "05b4f39f-ea96-4d91-910c-e758c078a089", "rel": "self" }], "stack_status_reason": "Stack successfully created", "stack_name": "stack-test", "creation_time": "2013-04-22T00:11:39Z", "updated_time": "2013-04-22T00:11:39Z", "stack_status": "CREATE_COMPLETE", "id": "05b4f39f-ea96-4d91-910c-e758c078a089" } stack = Stack(StackManager(None), stack1) TEST.stacks.add(stack) TEST.stack_templates.add(Template(TEMPLATE, VALIDATE))
def test_index(self): stacks = TestDataContainer() stacks.add(Stack('test')) t_api.heat.stacks_list(IsA(http.HttpRequest)).AndReturn(stacks.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'thermal/stacks/index.html') stacks_table = res.context['table'].data self.assertItemsEqual(stacks_table, stacks.list())
def test_delete_stack(self): stacks = TestDataContainer() stacks.add(Stack('delete_me')) stack = stacks.first() t_api.heat.stacks_list(IsA(http.HttpRequest)).AndReturn(stacks.list()) t_api.heat.stacks_delete(IsA(http.HttpRequest), stack.id) self.mox.ReplayAll() formData = {'action': 'stacks__delete__%s' % stack.id} res = self.client.post(INDEX_URL, formData) self.assertRedirectsNoFollow(res, INDEX_URL)
def data(TEST): TEST.exceptions = TestDataContainer() unauth = keystone_exceptions.Unauthorized TEST.exceptions.keystone_unauthorized = create_stubbed_exception(unauth) keystone_exception = keystone_exceptions.ClientException TEST.exceptions.keystone = create_stubbed_exception(keystone_exception) nova_exception = nova_exceptions.ClientException TEST.exceptions.nova = create_stubbed_exception(nova_exception) nova_unauth = nova_exceptions.Unauthorized TEST.exceptions.nova_unauthorized = create_stubbed_exception(nova_unauth) glance_exception = glance_exceptions.ClientException TEST.exceptions.glance = create_stubbed_exception(glance_exception) neutron_exception = neutron_exceptions.NeutronClientException TEST.exceptions.neutron = create_stubbed_exception(neutron_exception) swift_exception = swift_exceptions.ClientException TEST.exceptions.swift = create_stubbed_exception(swift_exception) cinder_exception = cinder_exceptions.BadRequest TEST.exceptions.cinder = create_stubbed_exception(cinder_exception)
def data(TEST): TEST.containers = TestDataContainer() TEST.objects = TestDataContainer() container_1 = swift.Container(dict(name=u"container_one\u6346")) container_2 = swift.Container(dict(name=u"container_two\u6346")) TEST.containers.add(container_1, container_2) object_dict = {"name": u"test_object\u6346", "content_type": u"text/plain", "bytes": 128, "last_modified": None, "hash": u"object_hash"} obj_dicts = [object_dict] obj_data = "Fake Data" for obj_dict in obj_dicts: swift_object = swift.StorageObject(obj_dict, container_1.name, data=obj_data) TEST.objects.add(swift_object)
def data(TEST): TEST.containers = TestDataContainer() TEST.objects = TestDataContainer() container_dict_1 = { "name": u"container_one\u6346", "container_object_count": 2, "container_bytes_used": 256, "timestamp": timeutils.isotime() } container_1 = swift.Container(container_dict_1) container_dict_2 = { "name": u"container_two\u6346", "container_object_count": 4, "container_bytes_used": 1024, "timestamp": timeutils.isotime() } container_2 = swift.Container(container_dict_2) TEST.containers.add(container_1, container_2) object_dict = { "name": u"test_object\u6346", "content_type": u"text/plain", "bytes": 128, "timestamp": timeutils.isotime(), "last_modified": None, "hash": u"object_hash" } obj_dicts = [object_dict] obj_data = "Fake Data" for obj_dict in obj_dicts: swift_object = swift.StorageObject(obj_dict, container_1.name, data=obj_data) TEST.objects.add(swift_object)
def data(TEST): TEST.service_catalog = SERVICE_CATALOG TEST.tokens = TestDataContainer() TEST.domains = TestDataContainer() TEST.users = TestDataContainer() TEST.groups = TestDataContainer() TEST.tenants = TestDataContainer() TEST.roles = TestDataContainer() TEST.ec2 = TestDataContainer() admin_role_dict = {'id': '1', 'name': 'admin'} admin_role = roles.Role(roles.RoleManager, admin_role_dict) member_role_dict = { 'id': "2", 'name': settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE } member_role = roles.Role(roles.RoleManager, member_role_dict) TEST.roles.add(admin_role, member_role) TEST.roles.admin = admin_role TEST.roles.member = member_role domain_dict = { 'id': "1", 'name': 'test_domain', 'description': "a test domain.", 'enabled': True } domain_dict_2 = { 'id': "2", 'name': 'disabled_domain', 'description': "a disabled test domain.", 'enabled': False } domain = domains.Domain(domains.DomainManager, domain_dict) disabled_domain = domains.Domain(domains.DomainManager, domain_dict_2) TEST.domains.add(domain, disabled_domain) TEST.domain = domain # Your "current" domain user_dict = { 'id': "1", 'name': 'test_user', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '1', 'enabled': True, 'domain_id': "1" } user = users.User(users.UserManager(None), user_dict) user_dict = { 'id': "2", 'name': 'user_two', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '1', 'enabled': True, 'domain_id': "1" } user2 = users.User(users.UserManager(None), user_dict) user_dict = { 'id': "3", 'name': 'user_three', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '1', 'enabled': True, 'domain_id': "1" } user3 = users.User(users.UserManager(None), user_dict) user_dict = { 'id': "4", 'name': 'user_four', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '2', 'enabled': True, 'domain_id': "2" } user4 = users.User(users.UserManager(None), user_dict) TEST.users.add(user, user2, user3, user4) TEST.user = user # Your "current" user TEST.user.service_catalog = SERVICE_CATALOG group_dict = { 'id': "1", 'name': 'group_one', 'description': 'group one description', 'domain_id': '1' } group = groups.Group(groups.GroupManager(None), group_dict) group_dict = { 'id': "2", 'name': 'group_two', 'description': 'group two description', 'domain_id': '1' } group2 = groups.Group(groups.GroupManager(None), group_dict) group_dict = { 'id': "3", 'name': 'group_three', 'description': 'group three description', 'domain_id': '2' } group3 = groups.Group(groups.GroupManager(None), group_dict) TEST.groups.add(group, group2, group3) tenant_dict = { 'id': "1", 'name': 'test_tenant', 'description': "a test tenant.", 'enabled': True, 'domain_id': '1' } tenant_dict_2 = { 'id': "2", 'name': 'disabled_tenant', 'description': "a disabled test tenant.", 'enabled': False, 'domain_id': '2' } tenant_dict_3 = { 'id': "3", 'name': u'\u4e91\u89c4\u5219', 'description': "an unicode-named tenant.", 'enabled': True, 'domain_id': '2' } tenant = tenants.Tenant(tenants.TenantManager, tenant_dict) disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2) tenant_unicode = tenants.Tenant(tenants.TenantManager, tenant_dict_3) TEST.tenants.add(tenant, disabled_tenant, tenant_unicode) TEST.tenant = tenant # Your "current" tenant tomorrow = datetime_safe.datetime.now() + timedelta(days=1) expiration = datetime_safe.datetime.isoformat(tomorrow) scoped_token_dict = { 'access': { 'token': { 'id': "test_token_id", 'expires': expiration, 'tenant': tenant_dict, 'tenants': [tenant_dict] }, 'user': { 'id': "test_user_id", 'name': "test_user", 'roles': [member_role_dict] }, 'serviceCatalog': TEST.service_catalog } } scoped_access_info = AccessInfo.factory(resp=None, body=scoped_token_dict) unscoped_token_dict = { 'access': { 'token': { 'id': "test_token_id", 'expires': expiration }, 'user': { 'id': "test_user_id", 'name': "test_user", 'roles': [member_role_dict] }, 'serviceCatalog': TEST.service_catalog } } unscoped_access_info = AccessInfo.factory(resp=None, body=unscoped_token_dict) scoped_token = Token(scoped_access_info) unscoped_token = Token(unscoped_access_info) TEST.tokens.add(scoped_token, unscoped_token) TEST.token = scoped_token # your "current" token. TEST.tokens.scoped_token = scoped_token TEST.tokens.unscoped_token = unscoped_token access_secret = ec2.EC2(ec2.CredentialsManager, { "access": "access", "secret": "secret" }) TEST.ec2.add(access_secret)
def data(TEST): FlavorTemplateStruct = namedtuple('FlavorStruct', 'id name\ capacities') CapacityStruct = namedtuple('CapacityStruct', 'name value unit') TEST.tuskar_flavor_templates = TestDataContainer() flavor_template_1 = FlavorTemplate(FlavorTemplateStruct( id="1", name='nano', capacities=[ Capacity(CapacityStruct( name='cpu', unit='', value='1')), Capacity(CapacityStruct( name='memory', unit='MB', value='64')), Capacity(CapacityStruct( name='storage', unit='MB', value='128')), Capacity(CapacityStruct( name='ephemeral_disk', unit='GB', value='0')), Capacity(CapacityStruct( name='swap_disk', unit='GB', value='0'))])) flavor_template_2 = FlavorTemplate(FlavorTemplateStruct( id="2", name='large', capacities=[])) TEST.tuskar_flavor_templates.add(flavor_template_1, flavor_template_2) # Flavors TEST.tuskarclient_flavors = TestDataContainer() TEST.tuskar_flavors = TestDataContainer() flavor_1 = flavors.Flavor(flavors.FlavorManager(None), {'id': '1', 'name': 'nano', 'max_vms': 100, 'capacities': [{"name": "cpu", "value": 64, "unit": "CPU"}, {"name": "memory", "value": 1024, "unit": "MB"}, {"name": "storage", "value": 1, "unit": "GB"}, {"name": "ephemeral_disk", "value": 0, "unit": "GB"}, {"name": "swap_disk", "value": 2, "unit": "GB"}]}) flavor_2 = flavors.Flavor(flavors.FlavorManager(None), {'id': '2', 'name': 'large', 'max_vms': 10, 'capacities': []}) TEST.tuskarclient_flavors.add(flavor_1, flavor_2) TEST.tuskar_flavors.add(Flavor(flavor_1), Flavor(flavor_2)) # Resource Classes TEST.tuskarclient_resource_classes = TestDataContainer() TEST.tuskar_resource_classes = TestDataContainer() resource_class_1 = resource_classes.ResourceClass( resource_classes.ResourceClassManager(None), {'id': '1', 'service_type': 'compute', 'racks': [{'id': 1}, {'id': 2}], 'name': 'rclass1'}) resource_class_2 = resource_classes.ResourceClass( resource_classes.ResourceClassManager(None), {'id': '2', 'service_type': 'compute', 'racks': [], 'name': 'rclass2'}) TEST.tuskarclient_resource_classes.add(resource_class_1, resource_class_2) TEST.tuskar_resource_classes.add(ResourceClass(resource_class_1), ResourceClass(resource_class_2)) #Racks TEST.tuskarclient_racks = TestDataContainer() TEST.tuskar_racks = TestDataContainer() rack_1 = racks.Rack(racks.RackManager(None), {'id': '1', 'name': 'rack1', 'location': 'location', 'subnet': '192.168.1.0/24', 'state': 'active', 'nodes': [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}], 'capacities': [{"name": "total_cpu", "value": "64", "unit": "CPU"}, {"name": "total_memory", "value": "1024", "unit": "MB"}], 'resource_class': {'id': '1'}}) rack_2 = racks.Rack(racks.RackManager(None), {'id': '2', 'name': 'rack2', 'location': 'location', 'subnet': '192.168.1.0/25', 'state': 'provisioning', 'nodes': [], 'capacities': [{"name": "total_cpu", "value": "1", "unit": "CPU"}, {"name": "total_memory", "value": "4", "unit": "MB"}], 'resource_class': {'id': '1'}}) rack_3 = racks.Rack(racks.RackManager(None), {'id': '3', 'name': 'rack3', 'location': 'location', 'subnet': '192.168.1.0/26', 'state': 'inactive', 'nodes': [], 'capacities': [{"name": "total_cpu", "value": "1", "unit": "CPU"}, {"name": "total_memory", "value": "2", "unit": "MB"}], 'resource_class': None}) TEST.tuskarclient_racks.add(rack_1, rack_2, rack_3) TEST.tuskar_racks.add(Rack(rack_1), Rack(rack_2), Rack(rack_3)) # Nodes TEST.nodes = TestDataContainer() TEST.unracked_nodes = TestDataContainer() NodeStruct = namedtuple('RackStruct', 'id name prov_mac_address') node_1 = Node(NodeStruct( id="1", name="node1", prov_mac_address="00-B0-D0-86-AB-F7")) node_2 = Node(NodeStruct( id="2", name="node2", prov_mac_address="00-B0-D0-86-AB-F8")) node_3 = Node(NodeStruct( id="3", name="node3", prov_mac_address="00-B0-D0-86-AB-F9")) node_4 = Node(NodeStruct( id="4", name="node4", prov_mac_address="00-B0-D0-86-AB-F0")) node_5 = Node(NodeStruct( id="5", name="node5", prov_mac_address="00-B0-D0-86-AB-F1")) TEST.nodes.add(node_1, node_2, node_3, node_4) TEST.unracked_nodes.add(node_5)
def data(TEST): TEST.servers = TestDataContainer() TEST.flavors = TestDataContainer() TEST.keypairs = TestDataContainer() TEST.security_groups = TestDataContainer() TEST.security_groups_uuid = TestDataContainer() TEST.security_group_rules = TestDataContainer() TEST.security_group_rules_uuid = TestDataContainer() TEST.volumes = TestDataContainer() TEST.quotas = TestDataContainer() TEST.quota_usages = TestDataContainer() TEST.floating_ips = TestDataContainer() TEST.floating_ips_uuid = TestDataContainer() TEST.usages = TestDataContainer() TEST.certs = TestDataContainer() TEST.volume_snapshots = TestDataContainer() TEST.volume_types = TestDataContainer() TEST.availability_zones = TestDataContainer() TEST.hypervisors = TestDataContainer() TEST.services = TestDataContainer() TEST.aggregates = TestDataContainer() # Data return by novaclient. # It is used if API layer does data conversion. TEST.api_floating_ips = TestDataContainer() TEST.api_floating_ips_uuid = 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" }])) TEST.volumes.add(volume) TEST.volumes.add(nameless_volume) TEST.volumes.add(attached_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-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-FLV-EXT-DATA:ephemeral': 2048 }) TEST.flavors.add(flavor_1, flavor_2) # Keypairs 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 = QuotaSetWrapper(quota) TEST.quotas.add(QuotaSetWrapper(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 }, 'floating_ips': { 'used': 0, 'quota': 10 }, 'volumes': { 'used': 0, 'quota': 10 } } quota_usage = QuotaUsage() for k, v in quota_usage_data.items(): quota_usage.add_quota(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 # 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(NetFloatingIp(generate_fip(fip_1)), NetFloatingIp(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(NetFloatingIp(generate_fip(fip_3)), NetFloatingIp(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' }) TEST.volume_snapshots.add(volume_snapshot) 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 } })) # 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 }) TEST.hypervisors.add(hypervisor_1) 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 }) TEST.services.add(service_1) TEST.services.add(service_2) # Aggregates aggregate_1 = aggregates.Aggregate( aggregates.AggregateManager(None), { "name": "foo", "availability_zone": None, "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)
def data(TEST): TEST.ceilometer_users = TestDataContainer() TEST.ceilometer_tenants = TestDataContainer() TEST.resources = TestDataContainer() TEST.samples = TestDataContainer() TEST.meters = TestDataContainer() TEST.statistics = TestDataContainer() TEST.global_disk_usages = TestDataContainer() TEST.global_network_usages = TestDataContainer() TEST.global_network_traffic_usages = TestDataContainer() TEST.global_object_store_usages = TestDataContainer() # users ceilometer_user_dict1 = { 'id': "1", 'name': 'user', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '1', 'enabled': True, 'domain_id': "1" } ceilometer_user_dict2 = { 'id': "2", 'name': 'user2', 'email': '*****@*****.**', 'password': '******', 'token': 'test_token', 'project_id': '2', 'enabled': True, 'domain_id': "2" } TEST.ceilometer_users.add( users.User(users.UserManager(None), ceilometer_user_dict1)) TEST.ceilometer_users.add( users.User(users.UserManager(None), ceilometer_user_dict2)) #tenants tenant_dict = { 'id': "1", 'name': 'test_tenant', 'description': "a test tenant.", 'enabled': True, 'domain_id': '1' } tenant_dict_2 = { 'id': "2", 'name': 'disabled_tenant', 'description': "a disabled test tenant.", 'enabled': False, 'domain_id': '2' } tenant_dict_3 = { 'id': "3", 'name': u'\u4e91\u89c4\u5219', 'description': "an unicode-named tenant.", 'enabled': True, 'domain_id': '2' } ceilometer_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict) ceilometer_disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2) ceilometer_tenant_unicode = tenants.Tenant(tenants.TenantManager, tenant_dict_3) TEST.ceilometer_tenants.add(ceilometer_tenant, ceilometer_disabled_tenant, ceilometer_tenant_unicode) # resources resource_dict_1 = dict( resource_id='fake_resource_id', project_id='fake_project_id', user_id="fake_user_id", timestamp='2012-07-02T10:42:00.000000', metadata={ 'tag': 'self.counter3', 'display_name': 'test-server' }, ) resource_dict_2 = dict( resource_id='fake_resource_id2', project_id='fake_project_id', user_id="fake_user_id", timestamp='2012-07-02T10:42:00.000000', metadata={ 'tag': 'self.counter3', 'display_name': 'test-server' }, ) resource_1 = resources.Resource(resources.ResourceManager(None), resource_dict_1) resource_2 = resources.Resource(resources.ResourceManager(None), resource_dict_2) TEST.resources.add(resource_1) TEST.resources.add(resource_2) # samples sample_dict_1 = { 'resource_id': 'fake_resource_id', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id', 'counter_name': 'image', 'counter_type': 'gauge', 'counter_unit': 'image', 'counter_volume': 1, 'timestamp': '2012-12-21T11:00:55.000000', 'metadata': { 'name1': 'value1', 'name2': 'value2' }, 'message_id': 'fake_message_id' } sample_dict_2 = { 'resource_id': 'fake_resource_id2', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id', 'counter_name': 'image', 'counter_type': 'gauge', 'counter_unit': 'image', 'counter_volume': 1, 'timestamp': '2012-12-21T11:00:55.000000', 'metadata': { 'name1': 'value1', 'name2': 'value2' }, 'message_id': 'fake_message_id' } sample_1 = samples.Sample(samples.SampleManager(None), sample_dict_1) sample_2 = samples.Sample(samples.SampleManager(None), sample_dict_2) TEST.samples.add(sample_1) TEST.samples.add(sample_2) # meters meter_dict_1 = { 'name': 'instance', 'type': 'gauge', 'unit': 'instance', 'resource_id': 'fake_resource_id', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id' } meter_dict_2 = { 'name': 'instance', 'type': 'gauge', 'unit': 'instance', 'resource_id': 'fake_resource_id', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id' } meter_dict_3 = { 'name': 'disk.read.bytes', 'type': 'gauge', 'unit': 'instance', 'resource_id': 'fake_resource_id', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id' } meter_dict_4 = { 'name': 'disk.write.bytes', 'type': 'gauge', 'unit': 'instance', 'resource_id': 'fake_resource_id', 'project_id': 'fake_project_id', 'user_id': 'fake_user_id' } meter_1 = meters.Meter(meters.MeterManager(None), meter_dict_1) meter_2 = meters.Meter(meters.MeterManager(None), meter_dict_2) meter_3 = meters.Meter(meters.MeterManager(None), meter_dict_3) meter_4 = meters.Meter(meters.MeterManager(None), meter_dict_4) TEST.meters.add(meter_1) TEST.meters.add(meter_2) TEST.meters.add(meter_3) TEST.meters.add(meter_4) # statistic statistic_dict_1 = { 'min': 1, 'max': 9, 'avg': 4.55, 'sum': 45, 'count': 10, 'duration_start': '2012-12-21T11:00:55.000000', 'duration_end': '2012-12-21T11:00:55.000000', 'period': 7200, 'period_start': '2012-12-21T11:00:55.000000', 'period_end': '2012-12-21T11:00:55.000000' } statistic_1 = statistics.Statistics(statistics.StatisticsManager(None), statistic_dict_1) TEST.statistics.add(statistic_1)
def data(TEST): TEST.images = TestDataContainer() TEST.snapshots = TestDataContainer() # Snapshots snapshot_dict = { 'name': u'snapshot', 'container_format': u'ami', 'id': 3, 'status': "active", 'owner': TEST.tenant.id, 'properties': { 'image_type': u'snapshot' }, 'is_public': False, 'protected': False } snapshot_dict_no_owner = { 'name': u'snapshot 2', 'container_format': u'ami', 'id': 4, 'status': "active", 'owner': None, 'properties': { 'image_type': u'snapshot' }, 'is_public': False, 'protected': False } snapshot_dict_queued = { 'name': u'snapshot 2', 'container_format': u'ami', 'id': 5, 'status': "queued", 'owner': TEST.tenant.id, 'properties': { 'image_type': u'snapshot' }, 'is_public': False, 'protected': False } snapshot = Image(ImageManager(None), snapshot_dict) TEST.snapshots.add(snapshot) snapshot = Image(ImageManager(None), snapshot_dict_no_owner) TEST.snapshots.add(snapshot) snapshot = Image(ImageManager(None), snapshot_dict_queued) TEST.snapshots.add(snapshot) # Images image_dict = { 'id': '007e7d55-fe1e-4c5c-bf08-44b4a4964822', 'name': 'public_image', 'status': "active", 'size': 20 * 1024**3, 'owner': TEST.tenant.id, 'container_format': 'novaImage', 'properties': { 'image_type': u'image' }, 'is_public': True, 'protected': False } public_image = Image(ImageManager(None), image_dict) image_dict = { 'id': 'a001c047-22f8-47d0-80a1-8ec94a9524fe', 'name': 'private_image', 'status': "active", 'size': 10 * 1024**2, 'owner': TEST.tenant.id, 'container_format': 'aki', 'is_public': False, 'protected': False } private_image = Image(ImageManager(None), image_dict) image_dict = { 'id': 'd6936c86-7fec-474a-85c5-5e467b371c3c', 'name': 'protected_images', 'status': "active", 'owner': TEST.tenant.id, 'size': 2 * 1024**3, 'container_format': 'novaImage', 'properties': { 'image_type': u'image' }, 'is_public': True, 'protected': True } protected_image = Image(ImageManager(None), image_dict) image_dict = { 'id': '278905a6-4b52-4d1e-98f9-8c57bb25ba32', 'name': 'public_image 2', 'status': "active", 'size': 5 * 1024**3, 'owner': TEST.tenant.id, 'container_format': 'novaImage', 'properties': { 'image_type': u'image' }, 'is_public': True, 'protected': False } public_image2 = Image(ImageManager(None), image_dict) image_dict = { 'id': '710a1acf-a3e3-41dd-a32d-5d6b6c86ea10', 'name': 'private_image 2', 'status': "active", 'size': 30 * 1024**3, 'owner': TEST.tenant.id, 'container_format': 'aki', 'is_public': False, 'protected': False } private_image2 = Image(ImageManager(None), image_dict) image_dict = { 'id': '7cd892fd-5652-40f3-a450-547615680132', 'name': 'private_image 3', 'status': "active", 'size': 2 * 1024**3, 'owner': TEST.tenant.id, 'container_format': 'aki', 'is_public': False, 'protected': False } private_image3 = Image(ImageManager(None), image_dict) # A shared image. Not public and not local tenant. image_dict = { 'id': 'c8756975-7a3b-4e43-b7f7-433576112849', 'name': 'shared_image 1', 'status': "active", 'size': 8 * 1024**3, 'owner': 'someothertenant', 'container_format': 'aki', 'is_public': False, 'protected': False } shared_image1 = Image(ImageManager(None), image_dict) # "Official" image. Public and tenant matches an entry # in IMAGES_LIST_FILTER_TENANTS. image_dict = { 'id': 'f448704f-0ce5-4d34-8441-11b6581c6619', 'name': 'official_image 1', 'status': "active", 'size': 2 * 1024**3, 'owner': 'officialtenant', 'container_format': 'aki', 'is_public': True, 'protected': False } official_image1 = Image(ImageManager(None), image_dict) TEST.images.add(public_image, private_image, protected_image, public_image2, private_image2, private_image3, shared_image1, official_image1)
def data(TEST): # data returned by openstack_dashboard.api.neutron wrapper TEST.networks = TestDataContainer() TEST.subnets = TestDataContainer() TEST.ports = TestDataContainer() TEST.routers = TestDataContainer() TEST.q_floating_ips = TestDataContainer() TEST.q_secgroups = TestDataContainer() TEST.q_secgroup_rules = TestDataContainer() TEST.pools = TestDataContainer() TEST.vips = TestDataContainer() TEST.members = TestDataContainer() TEST.monitors = TestDataContainer() # data return by neutronclient TEST.api_networks = TestDataContainer() TEST.api_subnets = TestDataContainer() TEST.api_ports = TestDataContainer() TEST.api_routers = TestDataContainer() TEST.api_q_floating_ips = TestDataContainer() TEST.api_q_secgroups = TestDataContainer() TEST.api_q_secgroup_rules = TestDataContainer() TEST.api_pools = TestDataContainer() TEST.api_vips = TestDataContainer() TEST.api_members = TestDataContainer() TEST.api_monitors = 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 = Subnet(subnet_dict) network['subnets'] = [subnet] TEST.networks.add(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']} TEST.api_ports.add(port_dict) TEST.ports.add(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(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 = Subnet(subnet_dict) network['subnets'] = [subnet] TEST.networks.add(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(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 = Subnet(subnet_dict) network['subnets'] = [subnet] TEST.networks.add(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(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(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(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(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(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']} rules = [] if not default_only: rules += [rule_tcp_80, rule_icmp, rule_group] 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(SecurityGroup(copy.deepcopy(sg), sg_name_dict)) for rule in sg['security_group_rules']: TEST.q_secgroup_rules.add( 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} TEST.api_pools.add(pool_dict) TEST.pools.add(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(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(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, 'admin_state_up': True} TEST.api_members.add(member_dict) TEST.members.add(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, 'admin_state_up': True} TEST.api_members.add(member_dict) TEST.members.add(Member(member_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'], 'admin_state_up': True} TEST.api_pools.add(pool_dict) TEST.pools.add(Pool(pool_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(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(PoolMonitor(monitor_dict))