This work is licensed under a Creative Commons Attribution 3.0 Unported License.
http://creativecommons.org/licenses/by/3.0/legalcode
Tempest 对多个 Keystone API 版本的支持¶
https://blueprints.launchpad.net/tempest/+spec/multi-keystone-api-version-tests
将 Tempest 与 Keystone 版本细节解耦,并使用 Keystone v3 运行测试
问题描述¶
Tempest 代码与 Keystone V2 特定实现紧密耦合。 常见的类(如 REST 客户端和租户隔离)、测试基类和测试本身都假定身份服务由 Keystone v2 端点提供。 Tempest 应该能够使用 Keystone V3 身份服务运行,以及随着可用性而出现的更新版本。
提议的变更¶
引入一个新的配置标志来指定要使用的认证版本。 该标志定义如下
cfg.StrOpt('auth_version',
default='v2',
help="Identity API version to be used for authentication "
"for API tests."),
它用于选择匹配的凭证和认证提供程序版本
if CONF.identity.auth_version == 'v2':
credential_class = KeystoneV2Credentials
auth_provider_class = KeystoneV2AuthProvider
elif CONF.identity.auth_version == 'v3':
credential_class = KeystoneV3Credentials
auth_provider_class = KeystoneV3AuthProvider
else:
raise exceptions.InvalidConfiguration('Unsupported auth version')
需要进行一些重构才能实现这一点,并确保在切换到不同的 Keystone API 版本时,我们不需要再次更改测试代码。
认证被提取到认证提供程序中。 凭证通过一个专门的类处理,由凭证管理器提供给测试。 客户端管理器接收凭证,并且是实例化客户端并将其提供给测试的唯一责任方。 目前,客户端管理器在创建时会实例化所有可用的客户端。 这是不必要的,并且当并非所有 OpenStack 服务都可用于测试时,会导致问题。 因此,客户端管理器被更改为延迟实例化客户端。
重构前后的 Manager __init__ 方法签名
Before:
def __init__(self, username=None, password=None, tenant_name=None,
interface='json', service=None):
After:
def __init__(self, credentials=None, interface='json', service=None):
重构前后的 REST 客户端中的认证
Before:
def request(self, method, url,
headers=None, body=None):
if (self.token is None) or (self.base_url is None):
self._set_auth()
if headers is None:
headers = {}
headers['X-Auth-Token'] = self.token
resp, resp_body = self._request(method, url,
headers=headers, body=body)
After:
def _request(self, method, url, headers=None, body=None):
# Authenticate the request with the auth provider
req_url, req_headers, req_body = self.auth_provider.auth_request(
method, url, headers, body, self.filters)
重构前后的测试中访问凭证 ID
Before:
# Retrieve the ResellerAdmin tenant id
_, users = cls.os_admin.identity_client.get_users()
reseller_user_id = next(usr['id'] for usr in users if usr['name']
== cls.data.test_user)
# Retrieve the ResellerAdmin tenant id
_, tenants = cls.os_admin.identity_client.list_tenants()
reseller_tenant_id = next(tnt['id'] for tnt in tenants if tnt['name']
== cls.data.test_tenant)
After:
# Retrieve the ResellerAdmin user id
reseller_user_id = cls.data.test_credentials.user_id
# Retrieve the ResellerAdmin tenant id
reseller_tenant_id = cls.data.test_credentials.tenant_id
受重构影响的区域
REST 客户端 (tempest/common/rest_client.py):将认证代码移动到外部认证提供程序
客户端管理器 (tempest/manager.py, tempest/clients.py, tempest/scenario/manager.py):使用 Credentials 类。 延迟加载客户端。
测试基类 (tempest/api/**/base.py):根据需要调整以适应修改后的 REST 客户端、客户端管理器和凭证
测试:根据需要调整以适应修改后的 REST 客户端、客户端管理器和凭证
替代方案¶
我们可以原地更改所有代码 - 不进行重构 - 添加配置的认证版本检查。 这仍然需要触及大量的 Tempest 代码,而没有为未来的 Keystone 版本带来好处。
实现¶
负责人¶
- 主要负责人
Andrea Frittoli <andrea.frittoli@hp.com>
里程碑¶
- 完成目标里程碑
Juno-1
工作项¶
将认证从 rest_client 移动到认证提供程序
为新的认证和凭证类提供单元测试
在所有地方重构 Manager 和 Credentials 类
客户端管理器提供客户端延迟加载
V3 的租户隔离支持
为 API 测试提供多认证版本
为场景测试提供多认证版本
为 CLI 测试提供多认证版本
为第三方测试提供多认证版本
为压力测试框架提供多认证版本
添加带有 auth_version = v3 的实验性任务
依赖项¶
Python 绑定和 CLI 尚未全部准备好 V3。 此蓝图中的一些工作将不得不推迟,直到解决此问题为止