Tempest CLI 改进

https://blueprints.launchpad.net/tempest/+spec/tempest-cli-improvements

通过利用 setuptools 和 cliff python 库,使 Tempest CLI 设计更加一致和直观。

问题描述

当前,在安装 tempest 时会创建一些 Tempest CLI 端点,但控制台命令名称和功能不一致。

提议的变更

为 Tempest 创建一套直观的 CLI 端点。

为 Tempest 添加 cliff 支持

Cliff 通过使用干净的类结构来构建应用程序和命令,从而实现控制台脚本的创建。

参见: https://pypi.ac.cn/project/cliff/

例如 setup.cfg 将具有

[entry_points]
console_scripts =
    tempest = tempest.cmd.main:main
tempest.cm =
    cleanup = tempest.cmd.main:CleanupCmd
    # ...

而 tempest.cmd.main 将类似于

from cliff.app import App
from cliff.commandmanager import CommandManager
from cliff.command import Command
# ...

class Main(App):

    log = logging.getLogger(__name__)

    def __init__(self):
        super(Main, self).__init__(
            description='Tempest cli application',
            version='0.1',
            command_manager=CommandManager('tempest.cm'))

    def initialize_app(self, argv):
        self.log.info('tempest initialize_app')

    def prepare_to_run_command(self, cmd):
        self.log.info('prepare_to_run_command %s', cmd.__class__.__name__)

    def clean_up(self, cmd, result, err):
        self.log.info('Tempest app clean_up %s', cmd.__class__.__name__)
        if err:
            self.log.info('Tempest error: %s', err)

# A sample command implementation would look like:

class CleanupCmd(Command):
    log = logging.getLogger(__name__)

    def get_description(self):
        description = "Utility for cleaning up ..."
        return description

    def get_parser(self, prog_name):
        parser = super(CleanupCmd, self).get_parser(prog_name)
        parser.add_argument('--init-saved-state', action="store_true",
                            dest='init_saved_state', default=False,
                            help="Init help...")
        # More args ...
        return parser

    def take_action(self, parsed_args):
        cu = cleanup.Cleanup(parsed_args)
        cu.run()
        self.log.info("Cleanup Done!")

The end result, after running 'setup.py install', this command is valid::

    tempest cleanup --init-saved-state

建议的命令结构

tempest cleanup
    arguments:
        --dry-run
        --init-saved-state
        --delete-tempest-conf-objects

tempest create-config
    arguments:
        TBD

tempest verify-config
    arguments:
        --update, -u
        --output, -o
        --replace-ext, -r

tempest javelin
        --mode, -m
        --resources, -r
        --devstack-base, -d
        --config-file, -c
        --os-username
        --os-password
        --os-tenant-name

实现

负责人

主要负责人

David Paterson

里程碑

完成目标里程碑

Liberty-1

工作项

  • 添加对 Cliff 的支持。

  • 在 setup.cfg 中定义端点和命令。

  • 创建 stubbed tempest.cmd.main 模块,提供基于 cliff 的 CLI facade。

  • 重构并迁移现有命令。对于每个命令,都需要实现一个继承自 cliff.command.Command 的新类

    • javelin2

    • run-tempest-stress

    • tempest-cleanup

    • verify-tempest-config

  • 迁移 config_tempest.py 来自下游仓库并与 cliff 集成。

依赖项

  • cliff - 添加用于创建 CLI 应用程序和命令的框架。

参考资料