browbeat/browbeat.py
Joe Talerico 8a542ef8ec Migrate browbeat.sh to Python
Learning the Ansible API for this migration. Very simple script
that will use the browbeat checks

+ Added Pbench start/stop 01/11/16
+ Moved ansible to config 01/11/16
+ Adding ansible hosts option 01/11/16
+ Connmon added (start/stop) still nothing with results 01/12/16
+ New Rally YAML format... (nova example) 01/12/16
+ Create results directory 01/12/16
+ Created lib with classes 01/13/16
+ Updated Scenarios 01/14/16
+ Updated other workloads to new format 01/15/16
+ Switched to dict get method 01/15/16
+ Removed pyc files and updated 01/15/16
+ updated genhost file 01/15/16
+ Update Ansible for connmon finished pbench work 01/15/16
+ Catch if user tries to run without Ansible or Ansible2 01/26/16
+ Minor changes 01/26/16
+ Bug fix... 01/27/16
+ (akrzos) added keystone yamls and browbeat-complete.yaml
+ Moved BrowbeatRally to Rally and broke connmon out of Tools
+ (akrzos) Implemented per Rally test scenario task args.
+ Updated Docs, removed old browbeat.sh
+ (akrzos) Cleaned up lib/Rally.py and added cinder scenarios to browbeat configs.
+ Fix Connmon install issue
+ (akrzos) Added parameters to neutron task yamls
+ (akrzos) Changed connmon to stop logging immediately after rally task completes.
Change-Id: I338c3463e25f38c2ec7667c7dfc8b5424acba8c2
2016-01-29 21:24:34 +01:00

132 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python
import argparse
import yaml
import logging
import sys
sys.path.append('lib/')
from Pbench import *
from Tools import *
from Rally import *
import ConfigParser, os
# Setting up our logger
_logger = logging.getLogger('browbeat')
_logger.setLevel(logging.INFO)
_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)5s - %(message)s')
_ch = logging.StreamHandler()
_ch.setFormatter(_formatter)
_logger.addHandler(_ch)
# import ansible
try :
from ansible.playbook import PlayBook
from ansible import callbacks
from ansible import utils
except ImportError :
_logger.error("Unable to import Ansible API. This code is not Ansible 2.0 ready")
exit(1)
# Browbeat specific options
_install_opts=['pbench','connmon','browbeat']
_config_file = 'browbeat-config.yaml'
_config = None
# Load Config file
def _load_config(path):
stream = open(path, 'r')
config=yaml.load(stream)
stream.close()
return config
# Run Ansible Playbook
def _run_playbook(path, hosts, only_tag=None, skip_tag=None):
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=1)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=1)
play = PlayBook(playbook=path,
host_list=hosts,
stats=stats,
only_tags=only_tag,
skip_tags=skip_tag,
callbacks=playbook_cb,
runner_callbacks=runner_cb)
return play.run()
#
# Browbeat Main
#
if __name__ == '__main__':
_cli=argparse.ArgumentParser(description="Browbeat automated scrips")
_cli.add_argument('-n','--hosts',nargs=1,
help='Provide Ansible hosts file to use. Default is ansible/hosts')
_cli.add_argument('-s','--setup',nargs=1,
help='Provide Setup YAML for browbeat. Default is ./browbeat-config.yaml')
_cli.add_argument('-c','--check',action='store_true',
help='Run the Browbeat Overcloud Checks')
_cli.add_argument('-w','--workloads',action='store_true',
help='Run the Browbeat workloads')
_cli.add_argument('-i','--install',nargs=1,choices=_install_opts,dest='install',
help='Install Browbeat Tools')
_cli.add_argument('--debug',action='store_true',
help='Enable Debug messages')
_cli_args = _cli.parse_args()
if _cli_args.debug :
_logger.setLevel(logging.DEBUG)
#
# Install Tool(s)
#
if _cli_args.install :
if _cli_args.setup :
_config=_load_config(_cli_args.setup[0])
else:
_config=_load_config(_config_file)
hosts_path=_config['ansible']['hosts']
if _cli_args.hosts :
_logger.info("Loading new hosts file : %s"% _cli_args.hosts[0])
hosts_path=_cli_args.hosts
if _cli_args.install[0] == 'all' :
for tool in _install_opts:
_run_playbook(_config['ansible']['install'][tool],hosts_path)
elif _cli_args.install[0] in _install_opts :
_run_playbook(_config['ansible']['install'][_cli_args.install[0]],hosts_path)
#
# Overcloud check
#
if _cli_args.check :
if _cli_args.setup :
_config=_load_config(_cli_args.setup[0])
else:
_config=_load_config(_config_file)
hosts_path=_config['ansible']['hosts']
if _cli_args.hosts :
_logger.info("Loading new hosts file : %s"% _cli_args.hosts[0])
hosts_path=_cli_args.hosts
_run_playbook(_config['ansible']['check'],hosts_path)
#
# Run Workloads
#
if _cli_args.workloads :
hosts = None
if _cli_args.setup :
_config=_load_config(_cli_args.setup[0])
else:
_config=_load_config(_config_file)
hosts_path=_config['ansible']['hosts']
if _config['browbeat']['pbench']['enabled'] :
pbench_hosts_path=_config['browbeat']['pbench']['hosts']
if _cli_args.hosts :
_logger.info("Loading new hosts file : %s"% _cli_args.hosts[0])
hosts_path=_cli_args.hosts
if _config['browbeat']['pbench']['enabled'] :
hosts = ConfigParser.ConfigParser(allow_no_value=True)
hosts.read(pbench_hosts_path)
tools = Tools(_config)
rally = Rally(_config,hosts)
rally.start_workloads()