Merge "Addition of verbose / quiet options to tobiko cmd"

This commit is contained in:
Zuul 2019-03-27 15:29:16 +00:00 committed by Gerrit Code Review
commit 6746d08357
5 changed files with 32 additions and 25 deletions

View File

@ -15,21 +15,27 @@
from __future__ import absolute_import
import os
import logging
import argparse
from oslo_log import log
from tobiko.common import clients
from tobiko.common.managers import stack
from tobiko.common.managers import ansible
from tobiko import config
LOG = log.getLogger(__name__)
class TobikoCMD(object):
"""Manages different command line utilities."""
def __init__(self):
config.CONF.tobiko.use_stderr = True
log.setup(config.CONF.tobiko, 'tobiko')
self.parser = self.get_parser()
self.args = (self.parser).parse_args()
self.clientManager = clients.ClientManager()
curr_dir = os.path.dirname(__file__)
@ -41,3 +47,20 @@ class TobikoCMD(object):
self.templates_dir)
self.ansibleManager = ansible.AnsibleManager(self.clientManager,
self.playbooks_dir)
def get_parser(self):
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument('--verbose', '-v', action='count',
help='Make the output more verbose, incremental.')
parser.add_argument('--quiet', '-q', action='count',
help='Make the output less verbose, incremental.')
return parser
def set_stream_handler_logging_level(self):
num_quiet = self.args.quiet or 0
num_verb = self.args.verbose or 0
level = logging.WARNING - (num_verb * 10) + (num_quiet * 10)
root_logger = logging.getLogger()
for handler in root_logger.handlers:
if isinstance(handler, logging.StreamHandler):
handler.setLevel(level)

View File

@ -13,12 +13,10 @@
# under the License.
from __future__ import absolute_import
import argparse
import os
import sys
from oslo_log import log
from tobiko.cmd import base
from tobiko.common import constants
from tobiko.common import exceptions
@ -28,13 +26,8 @@ LOG = log.getLogger(__name__)
class CreateUtil(base.TobikoCMD):
def __init__(self):
super(CreateUtil, self).__init__()
self.parser = self.get_parser()
self.args = (self.parser).parse_args()
def get_parser(self):
parser = argparse.ArgumentParser(add_help=True)
parser = super(CreateUtil, self).get_parser()
parser.add_argument(
'--stack', '-s',
help="The name of the stack to create.\n"
@ -78,6 +71,7 @@ class NoSuchTemplateError(exceptions.TobikoException):
def main():
"""Create CLI main entry."""
create_cmd = CreateUtil()
create_cmd.set_stream_handler_logging_level()
if create_cmd.args.playbook:
create_cmd.run_playbook(create_cmd.args.playbook)
else:

View File

@ -13,7 +13,6 @@
# under the License.
from __future__ import absolute_import
import argparse
import logging
import sys
@ -24,13 +23,8 @@ LOG = logging.getLogger(__name__)
class DeleteUtil(base.TobikoCMD):
def __init__(self):
super(DeleteUtil, self).__init__()
self.parser = self.get_parser()
self.args = (self.parser).parse_args()
def get_parser(self):
parser = argparse.ArgumentParser(add_help=True)
parser = super(DeleteUtil, self).get_parser()
parser.add_argument(
'--stack', '-s',
help="The name of the stack to remove.")
@ -64,7 +58,7 @@ class DeleteUtil(base.TobikoCMD):
def main():
"""Delete CLI main entry."""
delete_cmd = DeleteUtil()
delete_cmd.set_stream_handler_logging_level()
if delete_cmd.args.playbook:
delete_cmd.run_playbook(delete_cmd.args.playbook)
else:

View File

@ -13,7 +13,6 @@
# under the License.
from __future__ import absolute_import
import argparse
import sys
from oslo_log import log
@ -27,13 +26,9 @@ LOG = log.getLogger(__name__)
class FixtureUtil(base.TobikoCMD):
def __init__(self):
super(FixtureUtil, self).__init__()
self.parser = self.get_parser()
self.args = self.parser.parse_args()
def get_parser(self):
parser = argparse.ArgumentParser(add_help=True)
parser = super(FixtureUtil, self).get_parser()
subparsers_params = {}
subparsers = parser.add_subparsers(**subparsers_params)
@ -188,6 +183,7 @@ class FixtureUtil(base.TobikoCMD):
def main():
"""Create CLI main entry."""
fixture_util = FixtureUtil()
fixture_util.set_stream_handler_logging_level()
fixture_util.execute()

View File

@ -22,7 +22,7 @@ from tobiko.tests.openstack import base as test_base
class TobikoCMDTest(test_base.OpenstackTest):
command_name = None
command_name = 'tobiko-base'
command_class = base.TobikoCMD
def test_init(self, argv=None):