Exemplo n.º 1
0
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.networks = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = 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))
Exemplo n.º 2
0
def data(TEST):
    # Make a deep copy of the catalog to avoid persisting side-effects
    # when tests modify the catalog.
    TEST.service_catalog = copy.deepcopy(SERVICE_CATALOG)
    TEST.tokens = utils.TestDataContainer()
    TEST.domains = utils.TestDataContainer()
    TEST.users = utils.TestDataContainer()
    # TEST.groups = utils.TestDataContainer()
    TEST.tenants = utils.TestDataContainer()
    # TEST.role_assignments = utils.TestDataContainer()
    # TEST.roles = utils.TestDataContainer()
    # TEST.ec2 = utils.TestDataContainer()

    TEST.identity_providers = utils.TestDataContainer()
    TEST.idp_mappings = utils.TestDataContainer()
    TEST.idp_protocols = utils.TestDataContainer()

    # admin_role_dict = {'id': '1',
    #                    'name': 'admin'}
    # admin_role = roles.Role(roles.RoleManager, admin_role_dict, loaded=True)
    member_role_dict = {'id': "2",
                        'name': settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE}
    # member_role = roles.Role(roles.RoleManager,
    #                          member_role_dict, loaded=True)
    # 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_dict_3 = {'id': "3",
                     'name': 'another_test_domain',
                     'description': "another test domain.",
                     'enabled': True}
    domain = domains.Domain(domains.DomainManager, domain_dict)
    disabled_domain = domains.Domain(domains.DomainManager, domain_dict_2)
    another_domain = domains.Domain(domains.DomainManager, domain_dict_3)
    TEST.domains.add(domain, disabled_domain, another_domain)
    TEST.domain = domain  # Your "current" domain

    user_dict = {'id': "1",
                 'name': 'test_user',
                 'description': 'test_description',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': 'test_token',
                 'project_id': '1',
                 'enabled': True,
                 'domain_id': "1"}
    user = users.User(None, user_dict)
    user_dict = {'id': "2",
                 'name': 'user_two',
                 'description': 'test_description',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': 'test_token',
                 'project_id': '1',
                 'enabled': True,
                 'domain_id': "1"}
    user2 = users.User(None, user_dict)
    user_dict = {'id': "3",
                 'name': 'user_three',
                 'description': 'test_description',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': 'test_token',
                 'project_id': '1',
                 'enabled': True,
                 'domain_id': "1"}
    user3 = users.User(None, user_dict)
    user_dict = {'id': "4",
                 'name': 'user_four',
                 'description': 'test_description',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': 'test_token',
                 'project_id': '2',
                 'enabled': True,
                 'domain_id': "2"}
    user4 = users.User(None, user_dict)
    user_dict = {'id': "5",
                 'name': 'user_five',
                 'description': 'test_description',
                 'email': None,
                 'password': '******',
                 'token': 'test_token',
                 'project_id': '2',
                 'enabled': True,
                 'domain_id': "1"}
    user5 = users.User(None, user_dict)
    TEST.users.add(user, user2, user3, user4, user5)
    TEST.user = user  # Your "current" user
    TEST.user.service_catalog = copy.deepcopy(SERVICE_CATALOG)

    tenant_dict = {'id': "1",
                   'name': 'test_tenant',
                   'description': "a test tenant.",
                   'enabled': True,
                   'domain_id': '1',
                   'domain_name': 'test_domain'}
    tenant_dict_2 = {'id': "2",
                     'name': 'disabled_tenant',
                     'description': "a disabled test tenant.",
                     'enabled': False,
                     'domain_id': '2',
                     'domain_name': 'disabled_domain'}
    tenant_dict_3 = {'id': "3",
                     'name': u'\u4e91\u89c4\u5219',
                     'description': "an unicode-named tenant.",
                     'enabled': True,
                     'domain_id': '2',
                     'domain_name': 'disabled_domain'}
    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 = tomorrow.isoformat()

    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 = access.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 = access.AccessInfo.factory(resp=None,
                                                     body=unscoped_token_dict)

    scoped_token = auth_user.Token(scoped_access_info)
    unscoped_token = auth_user.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

    idp_dict_1 = {'id': 'idp_1',
                  'description': 'identity provider 1',
                  'enabled': True,
                  'remote_ids': ['rid_1', 'rid_2']}
    idp_1 = identity_providers.IdentityProvider(
        identity_providers.IdentityProviderManager,
        idp_dict_1, loaded=True)
    idp_dict_2 = {'id': 'idp_2',
                  'description': 'identity provider 2',
                  'enabled': True,
                  'remote_ids': ['rid_3', 'rid_4']}
    idp_2 = identity_providers.IdentityProvider(
        identity_providers.IdentityProviderManager,
        idp_dict_2, loaded=True)
    TEST.identity_providers.add(idp_1, idp_2)

    idp_mapping_dict = {
        "id": "mapping_1",
        "rules": [
            {
                "local": [
                    {
                        "user": {
                            "name": "{0}"
                        }
                    },
                    {
                        "group": {
                            "id": "0cd5e9"
                        }
                    }
                ],
                "remote": [
                    {
                        "type": "UserName"
                    },
                    {
                        "type": "orgPersonType",
                        "not_any_of": [
                            "Contractor",
                            "Guest"
                        ]
                    }
                ]
            }
        ]
    }
    idp_mapping = mappings.Mapping(
        mappings.MappingManager(None),
        idp_mapping_dict)
    TEST.idp_mappings.add(idp_mapping)

    idp_protocol_dict_1 = {'id': 'protocol_1',
                           'mapping_id': 'mapping_1'}
    idp_protocol = protocols.Protocol(
        protocols.ProtocolManager,
        idp_protocol_dict_1,
        loaded=True)
    TEST.idp_protocols.add(idp_protocol)
Exemplo n.º 3
0
def data(TEST):
    TEST.stacks = utils.TestDataContainer()
    TEST.stack_templates = utils.TestDataContainer()
    TEST.stack_environments = utils.TestDataContainer()
    TEST.stack_snapshot_create = utils.TestDataContainer()
    TEST.stack_snapshot = utils.TestDataContainer()
    TEST.resource_types = utils.TestDataContainer()
    TEST.heat_resources = utils.TestDataContainer()
    TEST.heat_services = utils.TestDataContainer()
    TEST.template_versions = utils.TestDataContainer()
    TEST.template_functions = utils.TestDataContainer()

    # Services
    service_1 = services.Service(services.ServiceManager(None), {
        "status": "up",
        "binary": "heat-engine",
        "report_interval": 60,
        "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d1",
        "created_at": "2015-02-06T03:23:32.000000",
        "hostname": "mrkanag",
        "updated_at": "2015-02-20T09:49:52.000000",
        "topic": "engine",
        "host": "engine-1",
        "deleted_at": None,
        "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
    })

    service_2 = services.Service(services.ServiceManager(None), {
        "status": "up",
        "binary": "heat-engine",
        "report_interval": 60,
        "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d2",
        "created_at": "2015-02-06T03:23:32.000000",
        "hostname": "mrkanag",
        "updated_at": "2015-02-20T09:49:52.000000",
        "topic": "engine",
        "host": "engine-2",
        "deleted_at": None,
        "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
    })

    TEST.heat_services.add(service_1)
    TEST.heat_services.add(service_2)

    # Data return by heatclient.
    TEST.api_resource_types = utils.TestDataContainer()

    for i in range(10):
        stack_data = {
            "description": "No description",
            "links": [{
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/stack-test{0}/"
                        "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i),
                "rel": "self"
            }],
            "parameters": {
                'DBUsername': '******',
                'InstanceType': 'm1.small',
                'AWS::StackId': (
                    'arn:openstack:heat::2ce287:stacks/teststack/88553ec'),
                'DBRootPassword': '******',
                'AWS::StackName': "teststack{0}".format(i),
                'DBPassword': '******',
                'AWS::Region': 'ap-southeast-1',
                'DBName': u'wordpress'
            },
            "stack_status_reason": "Stack successfully created",
            "stack_name": "stack-test{0}".format(i),
            "creation_time": "2013-04-22T00:11:39Z",
            "updated_time": "2013-04-22T00:11:39Z",
            "stack_status": "CREATE_COMPLETE",
            "id": "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i)
        }
        stack = stacks.Stack(stacks.StackManager(None), stack_data)
        TEST.stacks.add(stack)

    for i in range(10):
        snapshot_data = {
            "status": "COMPLETE",
            "name": 'null',
            "data": {
                "files": {},
                "status": "COMPLETE",
                "name": "zhao3",
                "tags": ["a", " 123", " b", " 456"],
                "stack_user_project_id": "3cba4460875444049a2a7cc5420ccddb",
                "environment": {
                    "encrypted_param_names": [],
                    "parameter_defaults": {},
                    "event_sinks": [],
                    "parameters": {},
                    "resource_registry": {
                        "resources": {}
                    }
                },
                "template": {
                    "heat_template_version": "2013-05-23",
                    "description":
                        "HOT template for Test.",
                    "resources": {
                        "private_subnet": {
                            "type": "OS::Neutron::Subnet",
                            "properties": {
                                "network_id": {"get_resource": "private_net"},
                                "cidr": "172.16.2.0/24",
                                "gateway_ip": "172.16.2.1"
                            }
                        },
                        "private_net": {
                            "type": "OS::Neutron::Net",
                            "properties": {"name": "private-net"}
                        }
                    }
                },
                "action": "SNAPSHOT",
                "project_id": "1acd0026829f4d28bb2eff912d7aad0d",
                "id": "70650725-bdbd-419f-b53f-5707767bfe0e",
                "resources": {
                    "private_subnet": {
                        "status": "COMPLETE",
                        "name": "private_subnet",
                        "resource_data": {},
                        "resource_id": "9c7211b3-31c7-41f6-b92a-442ad3f71ef0",
                        "action": "SNAPSHOT",
                        "type": "OS::Neutron::Subnet",
                        "metadata": {}
                    },
                    "private_net": {
                        "status": "COMPLETE",
                        "name": "private_net",
                        "resource_data": {},
                        "resource_id": "ff4fd287-31b2-4d00-bc96-c409bc1db027",
                        "action": "SNAPSHOT",
                        "type": "OS::Neutron::Net",
                        "metadata": {}
                    }
                }
            },

            "creation_time": "2016-02-21T04:02:54",
            "status_reason": "Stack SNAPSHOT completed successfully",
            "id": "01558a3b-ba05-4427-bbb4-1e4ab71cfca{0}".format(i)
        }
        TEST.stack_snapshot.add(snapshot_data)

    TEST.stack_templates.add(Template(TEMPLATE, VALIDATE))
    TEST.stack_environments.add(Environment(ENVIRONMENT))
    TEST.stack_snapshot_create.add(Snapshot(SNAPSHOT_CREATE))

    # Resource types list
    r_type_1 = {
        "resource_type": "AWS::CloudFormation::Stack",
        "attributes": {},
        "properties": {
            "Parameters": {
                "description":
                    "The set of parameters passed to this nested stack.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": True},
            "TemplateURL": {
                "description": "The URL of a template that specifies"
                               " the stack to be created as a resource.",
                "immutable": False,
                "required": True,
                "type": "string",
                "update_allowed": True},
            "TimeoutInMinutes": {
                "description": "The length of time, in minutes,"
                               " to wait for the nested stack creation.",
                "immutable": False,
                "required": False,
                "type": "number",
                "update_allowed": True}
        }
    }

    r_type_2 = {
        "resource_type": "OS::Heat::CloudConfig",
        "attributes": {
            "config": {
                "description": "The config value of the software config."}
        },
        "properties": {
            "cloud_config": {
                "description": "Map representing the cloud-config data"
                               " structure which will be formatted as YAML.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": False}
        }
    }

    r_types_list = [r_type_1, r_type_2]

    for rt in r_types_list:
        r_type = resource_types.ResourceType(
            resource_types.ResourceTypeManager(None), rt['resource_type'])
        TEST.resource_types.add(r_type)
        TEST.api_resource_types.add(rt)

    # Resources
    resource_1 = resources.Resource(resources.ResourceManager(None), {
        "logical_resource_id": "my_resource",
        "physical_resource_id": "7b5e29b1-c94d-402d-b69c-df9ac6dfc0ce",
        "resource_name": "my_resource",
        "links": [
            {
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/%s/%s/resources/my_resource" %
                        (TEST.stacks.first().stack_name,
                         TEST.stacks.first().id),
                "rel": "self"
            },
            {
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/%s/%s" %
                        (TEST.stacks.first().stack_name,
                         TEST.stacks.first().id),
                "rel": "stack"
            }
        ],
        "attributes": {
            "metadata": {}
        }
    })

    TEST.heat_resources.add(resource_1)

    # Template versions
    template_version_1 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "version": "HeatTemplateFormatVersion.2012-12-12",
            "type": "cfn"
        })

    template_version_2 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "version": "heat_template_version.2013-05-23",
            "type": "hot"
        })

    TEST.template_versions.add(template_version_1)
    TEST.template_versions.add(template_version_2)

    # Template functions
    template_function_1 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "functions": "Fn::GetAZs",
            "description": "A function for retrieving the availability zones."
        })

    template_function_2 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "functions": "Fn::Join",
            "description": "A function for joining strings."
        })

    TEST.template_functions.add(template_function_1)
    TEST.template_functions.add(template_function_2)
Exemplo n.º 4
0
def data(TEST):
    # Data returned by openstack_dashboard.api.neutron wrapper.
    TEST.networks = utils.TestDataContainer()
    TEST.subnets = utils.TestDataContainer()
    TEST.ports = utils.TestDataContainer()
    TEST.routers = utils.TestDataContainer()
    TEST.floating_ips = utils.TestDataContainer()
    TEST.security_groups = utils.TestDataContainer()
    TEST.qos_policies = utils.TestDataContainer()

    # Data return by neutronclient.
    TEST.api_networks = utils.TestDataContainer()
    TEST.api_subnets = 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.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
    network = copy.deepcopy(network_dict)
    subnet = neutron.Subnet(subnet_dict)
    network['subnets'] = [subnet]
    TEST.networks.add(neutron.Network(network))
    TEST.subnets.add(subnet)

    assoc_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',
                   'availability_zone_hints': ['nova']}
    TEST.routers.add(neutron.Router(router_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']}
    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'}
    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:
        sg['security_group_rules'] = []
        # OpenStack Dashboard internaly API.
        TEST.security_groups.add(
            neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))

    # qos policies
    policy_dict = {'id': 'a21dcd22-7189-cccc-aa32-22adafaf16a7',
                   'name': 'policy 1',
                   'tenant_id': '1'}
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict))
    policy_dict1 = {'id': 'a21dcd22-7189-ssss-aa32-22adafaf16a7',
                    'name': 'policy 2',
                    'tenant_id': '1'}
    TEST.qos_policies.add(neutron.QoSPolicy(policy_dict1))
Exemplo n.º 5
0
def data(TEST):
    TEST.exceptions = utils.TestDataContainer()

    heat_exception = heat_exceptions.HTTPException
    TEST.exceptions.heat = create_stubbed_exception(heat_exception)
Exemplo n.º 6
0
def data(TEST):
    TEST.servers = utils.TestDataContainer()
    TEST.flavors = utils.TestDataContainer()
    TEST.keypairs = utils.TestDataContainer()
    TEST.availability_zones = utils.TestDataContainer()

    # 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)

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

    # Servers
    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": "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_4)

    # 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,
                        },
                    },
                },
            },
        ))
Exemplo n.º 7
0
def data(TEST):
    TEST.images = utils.TestDataContainer()
    TEST.images_api = utils.TestDataContainer()
    TEST.snapshots = utils.TestDataContainer()
    TEST.metadata_defs = utils.TestDataContainer()
    TEST.imagesV2 = utils.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 = images.Image(images.ImageManager(None), snapshot_dict)
    TEST.snapshots.add(api.glance.Image(snapshot))
    snapshot = images.Image(images.ImageManager(None), snapshot_dict_no_owner)
    TEST.snapshots.add(api.glance.Image(snapshot))
    snapshot = images.Image(images.ImageManager(None), snapshot_dict_queued)
    TEST.snapshots.add(api.glance.Image(snapshot))

    # Images
    image_dict = {
        'id': '007e7d55-fe1e-4c5c-bf08-44b4a4964822',
        'name': 'public_image',
        'disk_format': u'qcow2',
        'status': "active",
        'size': 20 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'novaImage',
        'properties': {
            'image_type': u'image'
        },
        'is_public': True,
        'protected': False,
        'min_ram': 0,
        'created_at': '2014-02-14T20:56:53'
    }
    public_image = images.Image(images.ImageManager(None), image_dict)

    image_dict = {
        'id': 'a001c047-22f8-47d0-80a1-8ec94a9524fe',
        'name': 'private_image',
        'status': "active",
        'size': 10 * 1024**2,
        'virtual_size': 20 * 1024**2,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'aki',
        'is_public': False,
        'protected': False,
        'min_ram': 0,
        'created_at': '2014-03-14T12:56:53'
    }
    private_image = images.Image(images.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,
        'virtual_size': None,
        'min_disk': 30,
        'container_format': 'novaImage',
        'properties': {
            'image_type': u'image'
        },
        'is_public': True,
        'protected': True,
        'min_ram': 0,
        'created_at': '2014-03-16T06:22:14'
    }
    protected_image = images.Image(images.ImageManager(None), image_dict)

    image_dict = {
        'id': '278905a6-4b52-4d1e-98f9-8c57bb25ba32',
        'name': None,
        'status': "active",
        'size': 5 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'novaImage',
        'properties': {
            'image_type': u'image'
        },
        'is_public': True,
        'protected': False,
        'min_ram': 0
    }
    public_image2 = images.Image(images.ImageManager(None), image_dict)

    image_dict = {
        'id': '710a1acf-a3e3-41dd-a32d-5d6b6c86ea10',
        'name': 'private_image 2',
        'status': "active",
        'size': 30 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'aki',
        'is_public': False,
        'protected': False,
        'min_ram': 0
    }
    private_image2 = images.Image(images.ImageManager(None), image_dict)

    image_dict = {
        'id': '7cd892fd-5652-40f3-a450-547615680132',
        'name': 'private_image 3',
        'status': "active",
        'size': 2 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'aki',
        'is_public': False,
        'protected': False,
        'min_ram': 0
    }
    private_image3 = images.Image(images.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,
        'virtual_size': None,
        'min_disk': 0,
        'owner': 'someothertenant',
        'container_format': 'aki',
        'is_public': False,
        'protected': False,
        'min_ram': 0
    }
    shared_image1 = images.Image(images.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,
        'virtual_size': None,
        'min_disk': 0,
        'owner': 'officialtenant',
        'container_format': 'aki',
        'is_public': True,
        'protected': False,
        'min_ram': 0
    }
    official_image1 = images.Image(images.ImageManager(None), image_dict)

    image_dict = {
        'id': 'a67e7d45-fe1e-4c5c-bf08-44b4a4964822',
        'name': 'multi_prop_image',
        'status': "active",
        'size': 20 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': TEST.tenant.id,
        'container_format': 'novaImage',
        'properties': {
            'description': u'a multi prop image',
            'foo': u'foo val',
            'bar': u'bar val'
        },
        'is_public': True,
        'protected': False
    }
    multi_prop_image = images.Image(images.ImageManager(None), image_dict)

    # An image without name being returned based on current api
    image_dict = {
        'id': 'c8756975-7a3b-4e43-b7f7-433576112849',
        'status': "active",
        'size': 8 * 1024**3,
        'virtual_size': None,
        'min_disk': 0,
        'owner': 'someothertenant',
        'container_format': 'aki',
        'is_public': False,
        'protected': False
    }
    no_name_image = images.Image(images.ImageManager(None), image_dict)

    TEST.images_api.add(public_image, private_image, protected_image,
                        public_image2, private_image2, private_image3,
                        shared_image1, official_image1, multi_prop_image)

    TEST.images.add(api.glance.Image(public_image),
                    api.glance.Image(private_image),
                    api.glance.Image(protected_image),
                    api.glance.Image(public_image2),
                    api.glance.Image(private_image2),
                    api.glance.Image(private_image3),
                    api.glance.Image(shared_image1),
                    api.glance.Image(official_image1),
                    api.glance.Image(multi_prop_image))

    TEST.empty_name_image = api.glance.Image(no_name_image)

    image_v2_dicts = [{
        'checksum':
        'eb9139e4942121f22bbc2afc0400b2a4',
        'container_format':
        'novaImage',
        'created_at':
        '2014-02-14T20:56:53',
        'direct_url':
        'swift+config://ref1/glance/'
        'da8500d5-8b80-4b9c-8410-cc57fb8fb9d5',
        'disk_format':
        u'qcow2',
        'file':
        '/v2/images/'
        'da8500d5-8b80-4b9c-8410-cc57fb8fb9d5/file',
        'id':
        '007e7d55-fe1e-4c5c-bf08-44b4a4964822',
        'kernel_id':
        'f6ebd5f0-b110-4406-8c1e-67b28d4e85e7',
        'locations': [{
            'metadata': {},
            'url':
            'swift+config://ref1/glance/'
            'da8500d5-8b80-4b9c-8410-cc57fb8fb9d5'
        }],
        'min_ram':
        0,
        'name':
        'public_image',
        'image_type':
        u'image',
        'min_disk':
        0,
        'owner':
        TEST.tenant.id,
        'protected':
        False,
        'ramdisk_id':
        '868efefc-4f2d-4ed8-82b1-7e35576a7a47',
        'size':
        20 * 1024**3,
        'status':
        'active',
        'tags': ['active_image'],
        'updated_at':
        '2015-08-31T19:37:45Z',
        'virtual_size':
        None,
        'visibility':
        'public'
    }, {
        'checksum': None,
        'container_format': 'novaImage',
        'created_at': '2014-03-16T06:22:14',
        'disk_format': None,
        'image_type': u'image',
        'file': '/v2/images/885d1cb0-9f5c-4677-9d03-175be7f9f984/file',
        'id': 'd6936c86-7fec-474a-85c5-5e467b371c3c',
        'locations': [],
        'min_disk': 30,
        'min_ram': 0,
        'name': 'protected_images',
        'owner': TEST.tenant.id,
        'protected': True,
        'size': 2 * 1024**3,
        'status': "active",
        'tags': ['empty_image'],
        'updated_at': '2015-09-01T22:37:32Z',
        'virtual_size': None,
        'visibility': 'public'
    }, {
        'checksum': 'e533283e6aac072533d1d091a7d2e413',
        'container_format': 'novaImage',
        'created_at': '2015-09-02T00:31:16Z',
        'disk_format': 'qcow2',
        'file': '/v2/images/10ca6b6b-48f4-43ac-8159-aa9e9353f5e4/file',
        'id': 'a67e7d45-fe1e-4c5c-bf08-44b4a4964822',
        'image_type': 'an image type',
        'min_disk': 0,
        'min_ram': 0,
        'name': 'multi_prop_image',
        'owner': TEST.tenant.id,
        'protected': False,
        'size': 20 * 1024**3,
        'status': 'active',
        'tags': ['custom_property_image'],
        'updated_at': '2015-09-02T00:31:17Z',
        'virtual_size': None,
        'visibility': 'public',
        'description': u'a multi prop image',
        'foo': u'foo val',
        'bar': u'bar val'
    }]
    for fixture in image_v2_dicts:
        apiresource = APIResourceV2(fixture)
        TEST.imagesV2.add(api.glance.Image(apiresource))

    metadef_dict = {
        'namespace':
        'namespace_1',
        'display_name':
        'Namespace 1',
        'description':
        'Mock desc 1',
        'resource_type_associations': [{
            'created_at': '2014-08-21T08:39:43Z',
            'prefix': 'mock',
            'name': 'mock name'
        }],
        'visibility':
        'public',
        'protected':
        True,
        'created_at':
        '2014-08-21T08:39:43Z',
        'properties': {
            'cpu_mock:mock': {
                'default': '1',
                'type': 'integer',
                'description': 'Number of mocks.',
                'title': 'mocks'
            }
        }
    }
    metadef = Namespace(metadef_dict)
    TEST.metadata_defs.add(metadef)

    metadef_dict = {
        'namespace':
        'namespace_2',
        'display_name':
        'Namespace 2',
        'description':
        'Mock desc 2',
        'resource_type_associations': [{
            'created_at': '2014-08-21T08:39:43Z',
            'prefix': 'mock',
            'name': 'mock name'
        }],
        'visibility':
        'private',
        'protected':
        False,
        'created_at':
        '2014-08-21T08:39:43Z',
        'properties': {
            'hdd_mock:mock': {
                'default': '2',
                'type': 'integer',
                'description': 'Number of mocks.',
                'title': 'mocks'
            }
        }
    }
    metadef = Namespace(metadef_dict)
    TEST.metadata_defs.add(metadef)

    metadef_dict = {
        'namespace':
        'namespace_3',
        'display_name':
        'Namespace 3',
        'description':
        'Mock desc 3',
        'resource_type_associations': [{
            'created_at': '2014-08-21T08:39:43Z',
            'prefix': 'mock',
            'name': 'mock name'
        }],
        'visibility':
        'public',
        'protected':
        False,
        'created_at':
        '2014-08-21T08:39:43Z',
        'properties': {
            'gpu_mock:mock': {
                'default': '2',
                'type': 'integer',
                'description': 'Number of mocks.',
                'title': 'mocks'
            }
        }
    }
    metadef = Namespace(metadef_dict)
    TEST.metadata_defs.add(metadef)

    metadef_dict = {
        'namespace':
        'namespace_4',
        'display_name':
        'Namespace 4',
        'description':
        'Mock desc 4',
        'resource_type_associations': [{
            'created_at': '2014-08-21T08:39:43Z',
            'prefix': 'mock',
            'name': 'OS::Cinder::Volume',
            'properties_target': 'user'
        }],
        'visibility':
        'public',
        'protected':
        True,
        'created_at':
        '2014-08-21T08:39:43Z',
        'properties': {
            'ram_mock:mock': {
                'default': '2',
                'type': 'integer',
                'description': 'Number of mocks.',
                'title': 'mocks'
            }
        }
    }
    metadef = Namespace(metadef_dict)
    TEST.metadata_defs.add(metadef)