def _create_tenant_users(cls, args): """Create tenant with users and their endpoints. This is suitable for using with pool of threads. :param args: tuple arguments, for Pool.imap() :returns: tuple (dict tenant, list users) """ admin_endpoint, users_num, project_dom, user_dom, task_id, i = args users = [] client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) tenant = client.create_project( cls.PATTERN_TENANT % {"task_id": task_id, "iter": i}, project_dom) LOG.debug("Creating %d users for tenant %s" % (users_num, tenant.id)) for user_id in range(users_num): username = cls.PATTERN_USER % {"tenant_id": tenant.id, "uid": user_id} user = client.create_user(username, "password", "*****@*****.**" % username, tenant.id, user_dom) user_endpoint = endpoint.Endpoint(client.auth_url, user.name, "password", tenant.name, consts.EndpointPermission.USER, client.region_name, project_domain_name=project_dom, user_domain_name=user_dom) users.append({"id": user.id, "endpoint": user_endpoint, "tenant_id": tenant.id}) return ({"id": tenant.id, "name": tenant.name}, users)
def setUp(self): super(KeystoneV3WrapperTestCase, self).setUp() self.client = mock.MagicMock() self.client.version = "v3" self.wrapped_client = keystone.wrap(self.client) self.client.domains.get.side_effect = exceptions.NotFound self.client.domains.list.return_value = [mock.MagicMock(id="domain_id")]
def setUp(self): super(KeystoneV3WrapperTestCase, self).setUp() self.client = mock.MagicMock() self.client.version = 'v3' self.wrapped_client = keystone.wrap(self.client) self.client.domains.get.side_effect = exceptions.NotFound self.client.domains.list.return_value = [ mock.MagicMock(id='domain_id')]
def consume(cache, args): domain, task_id, i = args if "client" not in cache: clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) tenant = cache["client"].create_project( self.PATTERN_TENANT % {"task_id": task_id, "iter": i}, domain) tenant_dict = {"id": tenant.id, "name": tenant.name} tenants.append(tenant_dict)
def _delete_users(cls, args): """Delete given users. :param args: tuple arguments, for Pool.imap() """ admin_endpoint, users = args client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) for user in users: try: client.delete_user(user["id"]) except Exception as ex: LOG.warning("Failed to delete user: %(user_id)s. " "Exception: %(ex)s" % {"user_id": user["id"], "ex": ex})
def _delete_tenants(cls, args): """Delete given tenants. :param args: tuple arguments, for Pool.imap() """ admin_endpoint, tenants = args client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) for tenant in tenants: try: client.delete_project(tenant["id"]) except Exception as ex: LOG.warning("Failed to delete tenant: %(tenant_id)s. " "Exception: %(ex)s" % {"tenant_id": tenant["id"], "ex": ex})
def consume(cache, args): username, password, project_dom, user_dom, tenant = args if "client" not in cache: clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) client = cache["client"] user = client.create_user(username, password, "*****@*****.**" % username, tenant["id"], user_dom) user_endpoint = endpoint.Endpoint( client.auth_url, user.name, password, tenant["name"], consts.EndpointPermission.USER, client.region_name, project_domain_name=project_dom, user_domain_name=user_dom) users.append({"id": user.id, "endpoint": user_endpoint, "tenant_id": tenant["id"]})
def _delete_tenants(cls, args): """Delete given tenants. :param args: tuple arguments, for Pool.imap() """ admin_endpoint, tenants = args client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) for tenant in tenants: try: client.delete_project(tenant["id"]) except Exception as ex: LOG.warning("Failed to delete tenant: %(tenant_id)s. " "Exception: %(ex)s" % { "tenant_id": tenant["id"], "ex": ex })
def _delete_users(cls, args): """Delete given users. :param args: tuple arguments, for Pool.imap() """ admin_endpoint, users = args client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) for user in users: try: client.delete_user(user["id"]) except Exception as ex: LOG.warning("Failed to delete user: %(user_id)s. " "Exception: %(ex)s" % { "user_id": user["id"], "ex": ex })
def consume(cache, args): username, password, project_dom, user_dom, tenant_id = args if "client" not in cache: clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) client = cache["client"] user = client.create_user(username, password, "*****@*****.**" % username, tenant_id, user_dom) user_endpoint = objects.Endpoint( client.auth_url, user.name, password, self.context["tenants"][tenant_id]["name"], consts.EndpointPermission.USER, client.region_name, project_domain_name=project_dom, user_domain_name=user_dom, endpoint_type=self.endpoint.endpoint_type) users.append({"id": user.id, "endpoint": user_endpoint, "tenant_id": tenant_id})
def _create_tenant_users(cls, args): """Create tenant with users and their endpoints. This is suitable for using with pool of threads. :param args: tuple arguments, for Pool.imap() :returns: tuple (dict tenant, list users) """ admin_endpoint, users_num, project_dom, user_dom, task_id, i = args users = [] client = keystone.wrap(osclients.Clients(admin_endpoint).keystone()) tenant = client.create_project( cls.PATTERN_TENANT % { "task_id": task_id, "iter": i }, project_dom) LOG.debug("Creating %d users for tenant %s" % (users_num, tenant.id)) for user_id in range(users_num): username = cls.PATTERN_USER % { "tenant_id": tenant.id, "uid": user_id } user = client.create_user(username, "password", "*****@*****.**" % username, tenant.id, user_dom) user_endpoint = endpoint.Endpoint(client.auth_url, user.name, "password", tenant.name, consts.EndpointPermission.USER, client.region_name, project_domain_name=project_dom, user_domain_name=user_dom) users.append({ "id": user.id, "endpoint": user_endpoint, "tenant_id": tenant.id }) return ({"id": tenant.id, "name": tenant.name}, users)
def delete_keystone_resources(keystone): keystone = keystone_wrapper.wrap(keystone) for resource in ["user", "project", "service", "role"]: _delete_single_keystone_resource_type(keystone, resource)
def consume(cache, user_id): if "client" not in cache: clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) cache["client"].delete_user(user_id)
def consume(cache, tenant_id): if "client" not in cache: clients = osclients.Clients(self.endpoint) cache["client"] = keystone.wrap(clients.keystone()) cache["client"].delete_project(tenant_id)
def _manager(self): return keystone_wrapper.wrap(getattr(self.admin, self._service)())
def setUp(self): super(KeystoneV2WrapperTestCase, self).setUp() self.client = mock.MagicMock() self.client.version = 'v2.0' self.wrapped_client = keystone.wrap(self.client)