Migrate tempest-account-generator to new cliff cli framework

Leave existing endpoint for now as to not disrupt existing
workflows and deprecate next cycle.

Add deprication warning for old usage.

Change-Id: I9db27a853184126a7f751800bc8cacd7dd4e40fd
Implements: blueprint tempest-cli-improvements
This commit is contained in:
David Paterson 2015-12-01 15:44:14 -08:00
parent e45aa842bc
commit 68b8b9d26f
2 changed files with 47 additions and 18 deletions

View File

@ -33,6 +33,7 @@ console_scripts =
tempest-account-generator = tempest.cmd.account_generator:main
tempest = tempest.cmd.main:main
tempest.cm =
account-generator = tempest.cmd.account_generator:TempestAccountGenerator
init = tempest.cmd.init:TempestInit
cleanup = tempest.cmd.cleanup:TempestCleanup
run-stress = tempest.cmd.run_stress:TempestRunStress

View File

@ -85,7 +85,9 @@ To see help on specific argument, please do: ``tempest-account-generator
import argparse
import netaddr
import os
import traceback
from cliff import command
from oslo_log import log as logging
import yaml
@ -104,6 +106,11 @@ import tempest_lib.exceptions
LOG = None
CONF = config.CONF
DESCRIPTION = ('Create accounts.yaml file for concurrent test runs.%s'
'One primary user, one alt user, '
'one swift admin, one stack owner '
'and one admin (optionally) will be created '
'for each concurrent thread.' % os.linesep)
def setup_logging():
@ -388,20 +395,7 @@ def dump_accounts(opts, resources):
LOG.info('%s generated successfully!' % opts.accounts)
def get_options():
usage_string = ('tempest-account-generator [-h] <ARG> ...\n\n'
'To see help on specific argument, do:\n'
'tempest-account-generator <ARG> -h')
parser = argparse.ArgumentParser(
description='Create accounts.yaml file for concurrent test runs. '
'One primary user, one alt user, '
'one swift admin, one stack owner '
'and one admin (optionally) will be created '
'for each concurrent thread.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
usage=usage_string
)
def _parser_add_args(parser):
parser.add_argument('-c', '--config-file',
metavar='/etc/tempest.conf',
help='path to tempest config file')
@ -438,16 +432,50 @@ def get_options():
metavar='accounts_file.yaml',
help='Output accounts yaml file')
def get_options():
usage_string = ('tempest-account-generator [-h] <ARG> ...\n\n'
'To see help on specific argument, do:\n'
'tempest-account-generator <ARG> -h')
parser = argparse.ArgumentParser(
description=DESCRIPTION,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
usage=usage_string
)
_parser_add_args(parser)
opts = parser.parse_args()
if opts.config_file:
config.CONF.set_config_path(opts.config_file)
return opts
class TempestAccountGenerator(command.Command):
def get_parser(self, prog_name):
parser = super(TempestAccountGenerator, self).get_parser(prog_name)
_parser_add_args(parser)
return parser
def take_action(self, parsed_args):
try:
return main(parsed_args)
except Exception:
LOG.exception("Failure generating test accounts.")
traceback.print_exc()
raise
return 0
def get_description(self):
return DESCRIPTION
def main(opts=None):
if not opts:
opts = get_options()
setup_logging()
if not opts:
LOG.warn("Use of: 'tempest-account-generator' is deprecated, "
"please use: 'tempest account-generator'")
opts = get_options()
if opts.config_file:
config.CONF.set_config_path(opts.config_file)
resources = generate_resources(opts)
create_resources(opts, resources)
dump_accounts(opts, resources)