服务客户端返回值不截断并迁移至 tempest-lib

https://blueprints.launchpad.net/tempest/+spec/method-return-value-and-move-service-clients-to-lib

使服务客户端不截断响应,并将它们迁移至 tempest-lib

问题描述

服务客户端是 Tempest 自有的 REST 客户端,用于操作每个 OpenStack 项目的 API。我们计划将服务客户端的方法迁移到 tempest-lib。

1. 当前这些方法会截断响应中的顶级键,例如

def show_host_detail(self, hostname):
    """Show detail information for the host."""

     resp, body = self.get("os-hosts/%s" % str(hostname))
     body = json.loads(body)
     self.validate_response(schema.show_host_detail, resp, body)
     return service_client.ResponseBodyList(resp, body['host'])

然而,这种截断作为库函数来说是错误的,因为调用者无法知道相应的 API 返回的完整响应。

一个例子是资源链接,它们目前被服务客户端截断。因此,如果调用者需要使用这些资源链接,则无法从当前的服务客户端获取。

2. 当前用于在服务客户端中验证响应的 JSON 模式存在于 Tempest 中。当服务客户端迁移到 Tempest-lib 时,这些模式应该可供 Tempest-lib 中的服务客户端访问。

提议的变更

  • 停止截断响应的顶级键,我们需要从服务客户端方法中删除这种截断,例如

def show_host_detail(self, hostname):
    """Show detail information for the host."""

    resp, body = self.get("os-hosts/%s" % str(hostname))
    body = json.loads(body)
    self.validate_response(schema.show_host_detail, resp, body)
-   return service_client.ResponseBodyList(resp, body['host'])
+   return service_client.ResponseBodyList(resp, body)
  • 将 JSON 响应模式迁移到 Tempest-lib。目前 Tempest 在 ‘tempest/api_schema’ 中拥有 JSON 响应模式,这些模式用于在服务客户端中验证 API 响应。在温哥华峰会上,决定了短期解决方案是将这些模式与服务客户端一起迁移到 Tempest-lib。

    从长远来看,每个项目应该提供某种方式来通过 API 或其他方式获取这些模式。

  • 将服务客户端代码复制到 tempest-lib 仓库

  • 切换 Tempest 以使用 tempest-lib 的服务客户端代码

服务客户端的迁移可以逐步进行,一次一个客户端类。

实现

负责人

主要负责人

其他贡献者

里程碑

完成目标里程碑

Liberty

工作项

  • 根据此提案修改服务客户端的方法返回值。

  • 将 JSON 模式迁移到 Tempest-lib

  • 将服务客户端迁移到 Tempest-lib

依赖项

https://blueprints.launchpad.net/tempest/+spec/consistent-service-method-names

参考资料