Exemplo n.º 1
0
    def test_user(self):

        fake_user = users.User(self.fc.users, {'id': '1'})
        user.User.keystone().AndReturn(self.fc)
        self.fc.users.create('test_stack.CfnUser',
                             '',
                             '*****@*****.**',
                             enabled=True,
                             tenant_id='test_tenant').AndReturn(fake_user)

        fake_role = roles.Role(self.fc.roles, {
            'id': '123',
            'name': 'stack_user_role'
        })
        user.User.keystone().AndReturn(self.fc)
        self.fc.roles.list().AndReturn([fake_role])

        user.User.keystone().AndReturn(self.fc)
        self.fc.roles.add_user_role('1', '123', 'test_tenant').AndReturn(None)

        # delete script
        user.User.keystone().AndReturn(self.fc)
        self.fc.users.get(user.DummyId('1')).AndRaise(Exception('not found'))
        eventlet.sleep(1).AndReturn(None)

        user.User.keystone().AndReturn(self.fc)
        self.fc.users.get(user.DummyId('1')).AndReturn(fake_user)
        self.fc.users.delete(fake_user).AndRaise(Exception('delete failed'))

        self.fc.users.delete(fake_user).AndReturn(None)

        self.m.ReplayAll()

        t = self.load_template()
        stack = self.parse_stack(t)

        resource = self.create_user(t, stack, 'CfnUser')
        self.assertEqual('1', resource.resource_id)
        self.assertEqual('test_stack.CfnUser', resource.FnGetRefId())

        self.assertEqual('CREATE_COMPLETE', resource.state)
        self.assertEqual(user.User.UPDATE_REPLACE, resource.handle_update())

        resource.resource_id = None
        self.assertEqual(None, resource.delete())
        self.assertEqual('DELETE_COMPLETE', resource.state)

        resource.resource_id = '1'
        resource.state_set('CREATE_COMPLETE')
        self.assertEqual('CREATE_COMPLETE', resource.state)

        self.assertEqual(None, resource.delete())
        self.assertEqual('DELETE_COMPLETE', resource.state)

        resource.state_set('CREATE_COMPLETE')
        self.assertEqual('CREATE_COMPLETE', resource.state)

        self.assertEqual(None, resource.delete())
        self.assertEqual('DELETE_COMPLETE', resource.state)
        self.m.VerifyAll()
    def test_resource_lazy_getattr(self):
        self.client.get = self.mox.CreateMockAnything()
        self.client.get('/OS-KSADM/roles/1').AndRaise(AttributeError)
        self.mox.ReplayAll()

        f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
        self.assertEqual(f.name, 'Member')

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, f, 'blahblah')
    def test_eq(self):
        # Two resources of the same type with the same id: equal
        r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
        r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
        self.assertEqual(r1, r2)

        # Two resoruces of different types: never equal
        r1 = base.Resource(None, {'id': 1})
        r2 = roles.Role(None, {'id': 1})
        self.assertNotEqual(r1, r2)

        # Two resources with no ID: equal if their info is equal
        r1 = base.Resource(None, {'name': 'joe', 'age': 12})
        r2 = base.Resource(None, {'name': 'joe', 'age': 12})
        self.assertEqual(r1, r2)
Exemplo n.º 4
0
    def test_resource_lazy_getattr(self):
        # Creating a Client not using session is deprecated.
        with self.deprecations.expect_deprecations_here():
            self.client = client.Client(token=self.TEST_TOKEN,
                                        auth_url='http://127.0.0.1:5000',
                                        endpoint='http://127.0.0.1:5000')

        self.useFixture(mockpatch.PatchObject(
            self.client._adapter, 'get', side_effect=AttributeError,
            autospec=True))

        f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
        self.assertEqual(f.name, 'Member')

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, f, 'blahblah')
Exemplo n.º 5
0
    def test_resource_lazy_getattr(self):
        self.client = client.Client(username=self.TEST_USER,
                                    token=self.TEST_TOKEN,
                                    tenant_name=self.TEST_TENANT_NAME,
                                    auth_url='http://127.0.0.1:5000',
                                    endpoint='http://127.0.0.1:5000')

        self.client._adapter.get = self.mox.CreateMockAnything()
        self.client._adapter.get('/OS-KSADM/roles/1').AndRaise(AttributeError)
        self.mox.ReplayAll()

        f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
        self.assertEqual(f.name, 'Member')

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, f, 'blahblah')
Exemplo n.º 6
0
    def test_resource_lazy_getattr(self):
        self.client = client.Client(username=self.TEST_USER,
                                    token=self.TEST_TOKEN,
                                    tenant_name=self.TEST_TENANT_NAME,
                                    auth_url='http://127.0.0.1:5000',
                                    endpoint='http://127.0.0.1:5000')

        self.useFixture(mockpatch.PatchObject(
            self.client._adapter, 'get', side_effect=AttributeError,
            autospec=True))

        f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
        self.assertEqual(f.name, 'Member')

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, f, 'blahblah')
Exemplo n.º 7
0
    def test_resource_lazy_getattr(self):
        auth = v2.Token(token=self.TEST_TOKEN,
                        auth_url='http://127.0.0.1:5000')
        session_ = session.Session(auth=auth)
        self.client = client.Client(session=session_)

        self.useFixture(
            fixtures.MockPatchObject(self.client._adapter,
                                     'get',
                                     side_effect=AttributeError,
                                     autospec=True))

        f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
        self.assertEqual(f.name, 'Member')

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, f, 'blahblah')
Exemplo n.º 8
0
    def test_eq(self):
        # Two resources with same ID: never equal if their info is not equal
        r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
        r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
        self.assertNotEqual(r1, r2)
        self.assertTrue(r1 != r2)

        # Two resources with same ID: equal if their info is equal
        # The truth of r1==r2 does not imply that r1!=r2 is false in PY2.
        # Test that inequality operator is defined and that comparing equal
        # items returns False
        r1 = base.Resource(None, {'id': 1, 'name': 'hello'})
        r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
        self.assertTrue(r1 == r2)
        self.assertFalse(r1 != r2)

        # Two resources of different types: never equal
        r1 = base.Resource(None, {'id': 1})
        r2 = roles.Role(None, {'id': 1})
        self.assertNotEqual(r1, r2)
        self.assertTrue(r1 != r2)

        # Two resources with no ID: equal if their info is equal
        # The truth of r1==r2 does not imply that r1!=r2 is false in PY2.
        # Test that inequality operator is defined and that comparing equal
        # items returns False.
        r1 = base.Resource(None, {'name': 'joe', 'age': 12})
        r2 = base.Resource(None, {'name': 'joe', 'age': 12})
        self.assertTrue(r1 == r2)
        self.assertFalse(r1 != r2)

        r1 = base.Resource(None, {'id': 1})
        self.assertNotEqual(r1, object())
        self.assertTrue(r1 != object())
        self.assertNotEqual(r1, {'id': 1})
        self.assertTrue(r1 != {'id': 1})
Exemplo n.º 9
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 = 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',
                 '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)

    group_dict = {'id': "1",
                  'name': 'group_one',
                  'description': 'group one description',
                  'project_id': '1',
                  'domain_id': '1'}
    group = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {'id': "2",
                  'name': 'group_two',
                  'description': 'group two description',
                  'project_id': '1',
                  'domain_id': '1'}
    group2 = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {'id': "3",
                  'name': 'group_three',
                  'description': 'group three description',
                  'project_id': '1',
                  'domain_id': '1'}
    group3 = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {'id': "4",
                  'name': 'group_four',
                  'description': 'group four description',
                  'project_id': '2',
                  'domain_id': '2'}
    group4 = groups.Group(groups.GroupManager(None), group_dict)
    TEST.groups.add(group, group2, group3, group4)

    role_assignments_dict = {'user': {'id': '1'},
                             'role': {'id': '1'},
                             'scope': {'project': {'id': '1'}}}
    proj_role_assignment1 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'user': {'id': '2'},
                             'role': {'id': '2'},
                             'scope': {'project': {'id': '1'}}}
    proj_role_assignment2 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'group': {'id': '1'},
                             'role': {'id': '2'},
                             'scope': {'project': {'id': '1'}}}
    proj_role_assignment3 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'user': {'id': '3'},
                             'role': {'id': '2'},
                             'scope': {'project': {'id': '1'}}}
    proj_role_assignment4 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'user': {'id': '1'},
                             'role': {'id': '1'},
                             'scope': {'domain': {'id': '1'}}}
    domain_role_assignment1 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'user': {'id': '2'},
                             'role': {'id': '2'},
                             'scope': {'domain': {'id': '1'}}}
    domain_role_assignment2 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'group': {'id': '1'},
                             'role': {'id': '2'},
                             'scope': {'domain': {'id': '1'}}}
    domain_role_assignment3 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    role_assignments_dict = {'user': {'id': '3'},
                             'role': {'id': '2'},
                             'scope': {'domain': {'id': '1'}}}
    domain_role_assignment4 = role_assignments.RoleAssignment(
        role_assignments.RoleAssignmentManager, role_assignments_dict)
    TEST.role_assignments.add(proj_role_assignment1,
                              proj_role_assignment2,
                              proj_role_assignment3,
                              proj_role_assignment4,
                              domain_role_assignment1,
                              domain_role_assignment2,
                              domain_role_assignment3,
                              domain_role_assignment4)

    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

    access_secret = ec2.EC2(ec2.CredentialsManager, {"access": "access",
                                                     "secret": "secret",
                                                     "tenant_id": tenant.id})
    TEST.ec2.add(access_secret)

    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.º 10
0
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)
Exemplo n.º 11
0
def generate_test_data():
    '''Builds a set of test_data data as returned by Keystone V2.'''
    test_data = TestDataContainer()

    keystone_service = {
        'type': 'identity',
        'name': 'keystone',
        'endpoints_links': [],
        'endpoints': [
            {
                'region': 'RegionOne',
                'adminURL': 'http://admin.localhost:35357/v2.0',
                'internalURL': 'http://internal.localhost:5000/v2.0',
                'publicURL': 'http://public.localhost:5000/v2.0'
            }
        ]
    }

    # Users
    user_dict = {'id': uuid.uuid4().hex,
                 'name': 'gabriel',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': '',
                 'enabled': True}
    test_data.user = users.User(None, user_dict, loaded=True)

    # Tenants
    tenant_dict_1 = {'id': uuid.uuid4().hex,
                     'name': 'tenant_one',
                     'description': '',
                     'enabled': True}
    tenant_dict_2 = {'id': uuid.uuid4().hex,
                     'name': 'tenant_two',
                     'description': '',
                     'enabled': False}
    test_data.tenant_one = tenants.Tenant(None, tenant_dict_1, loaded=True)
    test_data.tenant_two = tenants.Tenant(None, tenant_dict_2, loaded=True)

    nova_service = {
        'type': 'compute',
        'name': 'nova',
        'endpoint_links': [],
        'endpoints': [
            {
                'region': 'RegionOne',
                'adminURL': ('http://nova-admin.localhost:8774/v2.0/%s'
                             % (tenant_dict_1['id'])),
                'internalURL': ('http://nova-internal.localhost:8774/v2.0/%s'
                                % (tenant_dict_1['id'])),
                'publicURL': ('http://nova-public.localhost:8774/v2.0/%s'
                              % (tenant_dict_1['id']))
            },
            {
                'region': 'RegionTwo',
                'adminURL': ('http://nova2-admin.localhost:8774/v2.0/%s'
                             % (tenant_dict_1['id'])),
                'internalURL': ('http://nova2-internal.localhost:8774/v2.0/%s'
                                % (tenant_dict_1['id'])),
                'publicURL': ('http://nova2-public.localhost:8774/v2.0/%s'
                              % (tenant_dict_1['id']))
            }
        ]
    }

    # Roles
    role_dict = {'id': uuid.uuid4().hex,
                 'name': 'Member'}
    test_data.role = roles.Role(roles.RoleManager, role_dict)

    # Tokens
    tomorrow = datetime_safe.datetime.now() + datetime.timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration,
                'tenant': tenant_dict_1,
                'tenants': [tenant_dict_1, tenant_dict_2]},
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'roles': [role_dict]},
            'serviceCatalog': [keystone_service, nova_service]
        }
    }

    test_data.scoped_access_info = access.AccessInfo.factory(
        resp=None,
        body=scoped_token_dict)

    unscoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration},
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'roles': [role_dict]},
            'serviceCatalog': [keystone_service]
        }
    }
    test_data.unscoped_access_info = access.AccessInfo.factory(
        resp=None,
        body=unscoped_token_dict)

    # Service Catalog
    test_data.service_catalog = service_catalog.ServiceCatalog.factory({
        'serviceCatalog': [keystone_service, nova_service],
        'token': {
            'id': scoped_token_dict['access']['token']['id'],
            'expires': scoped_token_dict['access']['token']['expires'],
            'user_id': user_dict['id'],
            'tenant_id': tenant_dict_1['id']
        }
    })

    return test_data
Exemplo n.º 12
0
def data(TEST):
    TEST.service_catalog = SERVICE_CATALOG
    TEST.tokens = TestDataContainer()
    TEST.domains = TestDataContainer()
    TEST.users = 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}
    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}
    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}
    user3 = users.User(users.UserManager(None), user_dict)
    TEST.users.add(user, user2, user3)
    TEST.user = user  # Your "current" user
    TEST.user.service_catalog = SERVICE_CATALOG

    tenant_dict = {'id': "1",
                   'name': 'test_tenant',
                   'description': "a test tenant.",
                   'enabled': True}
    tenant_dict_2 = {'id': "2",
                     'name': 'disabled_tenant',
                     'description': "a disabled test tenant.",
                     'enabled': False}
    tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
    disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2)
    TEST.tenants.add(tenant, disabled_tenant)
    TEST.tenant = tenant  # Your "current" tenant

    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token = tokens.Token(tokens.TokenManager,
                                dict(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))
    unscoped_token = tokens.Token(tokens.TokenManager,
                                  dict(token={"id": "test_token_id",
                                              "expires": expiration},
                                       user={"id": "test_user_id",
                                             "name": "test_user",
                                             "roles": [member_role_dict]},
                                       serviceCatalog=TEST.service_catalog))
    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):
    TEST.service_catalog = SERVICE_CATALOG
    TEST.tokens = TestDataContainer()
    TEST.users = 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(member_role, admin_role)
    TEST.roles.admin = admin_role
    TEST.roles.member = member_role

    user_dict = {'id': "1",
                 'name': 'test_user',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': 'test_token'}
    user = users.User(users.UserManager, user_dict)
    user_dict.update({'id': "2",
                      'name': 'user_two',
                      'email': '*****@*****.**'})
    user2 = users.User(users.UserManager, user_dict)
    TEST.users.add(user, user2)
    TEST.user = user  # Your "current" user
    TEST.user.service_catalog = SERVICE_CATALOG

    tenant_dict = {'id': "1",
                   'name': 'test_tenant',
                   'description': "a test tenant.",
                   'enabled': True}
    tenant_dict_2 = {'id': "2",
                     'name': 'disabled_tenant',
                     'description': "a disabled test tenant.",
                     'enabled': False}
    tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
    disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2)
    TEST.tenants.add(tenant, disabled_tenant)
    TEST.tenant = tenant  # Your "current" tenant

    scoped_token = tokens.Token(tokens.TokenManager,
                                dict(token={"id": "test_token_id",
                                            "expires": "#FIXME",
                                            "tenant": tenant_dict,
                                            "tenants": [tenant_dict]},
                                     user={"id": "test_user_id",
                                           "name": "test_user",
                                           "roles": [member_role_dict]},
                                     serviceCatalog=TEST.service_catalog))
    unscoped_token = tokens.Token(tokens.TokenManager,
                                  dict(token={"id": "test_token_id",
                                              "expires": "#FIXME"},
                                       user={"id": "test_user_id",
                                             "name": "test_user",
                                             "roles": [member_role_dict]},
                                       serviceCatalog=TEST.service_catalog))
    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)