Styling Fix

Fixing Styling

Change-Id: I38ff33ed0da5bf6a67bd1d072f715ee2b6f3ef71
This commit is contained in:
Joe 2016-04-15 13:43:27 -04:00
parent 5169d338ed
commit 7584575895
7 changed files with 240 additions and 169 deletions

View File

@ -1,6 +1,8 @@
from Tools import *
class Connmon:
def __init__(self, config):
self.logger = logging.getLogger('browbeat.Connmon')
self.config = config
@ -22,10 +24,11 @@ class Connmon :
self.tools.run_cmd(cmd)
self.logger.info("Starting connmond")
cmd = ""
cmd +="{} --config /etc/connmon.cfg > /tmp/connmond 2>&1 &".format(connmond)
cmd += "{} --config /etc/connmon.cfg > /tmp/connmond 2>&1 &".format(
connmond)
self.tools.run_cmd(cmd)
if self.check_connmon_results == False:
if retry == None :
if self.check_connmon_results is False:
if retry is None:
self.start_connmon(retry=True)
else:
return False

View File

@ -3,6 +3,7 @@ import subprocess
class Grafana:
def __init__(self, config):
self.logger = logging.getLogger('browbeat.Grafana')
self.config = config
@ -13,8 +14,10 @@ class Grafana:
self.playbook = self.config['ansible']['grafana_snapshot']
def get_extra_vars(self, from_ts, to_ts, result_dir, test_name):
extra_vars = 'grafana_ip={} '.format(self.config['grafana']['grafana_ip'])
extra_vars += 'grafana_port={} '.format(self.config['grafana']['grafana_port'])
extra_vars = 'grafana_ip={} '.format(
self.config['grafana']['grafana_ip'])
extra_vars += 'grafana_port={} '.format(
self.config['grafana']['grafana_port'])
extra_vars += 'from={} '.format(from_ts)
extra_vars += 'to={} '.format(to_ts)
extra_vars += 'results_dir={}/{} '.format(result_dir, test_name)
@ -25,15 +28,18 @@ class Grafana:
def print_dashboard_url(self, from_ts, to_ts, test_name):
if 'grafana' in self.config and self.config['grafana']['enabled']:
url = 'http://{}:{}/dashboard/db/'.format(self.grafana_ip, self.grafana_port)
url = 'http://{}:{}/dashboard/db/'.format(
self.grafana_ip, self.grafana_port)
for dashboard in self.config['grafana']['dashboards']:
full_url = '{}{}?from={}&to={}&var-Cloud={}'.format(
url, dashboard, from_ts, to_ts, self.cloud_name)
self.logger.info('{} - Grafana URL: {}'.format(test_name, full_url))
self.logger.info(
'{} - Grafana URL: {}'.format(test_name, full_url))
def log_snapshot_playbook_cmd(self, from_ts, to_ts, result_dir, test_name):
if 'grafana' in self.config and self.config['grafana']['enabled']:
extra_vars = self.get_extra_vars(from_ts, to_ts, result_dir, test_name)
extra_vars = self.get_extra_vars(
from_ts, to_ts, result_dir, test_name)
snapshot_cmd = 'ansible-playbook -i {} {} -e "{}"'.format(
self.hosts_file, self.playbook, extra_vars)
self.logger.info('Snapshot command: {}'.format(snapshot_cmd))
@ -41,9 +47,12 @@ class Grafana:
def run_playbook(self, from_ts, to_ts, result_dir, test_name):
if 'grafana' in self.config and self.config['grafana']['enabled']:
if self.config['grafana']['snapshot']['enabled']:
extra_vars = self.get_extra_vars(from_ts, to_ts, result_dir, test_name)
extra_vars = self.get_extra_vars(
from_ts, to_ts, result_dir, test_name)
subprocess_cmd = ['ansible-playbook', '-i', self.hosts_file, self.playbook, '-e',
'{}'.format(extra_vars)]
snapshot_log = open('{}/snapshot.log'.format(result_dir), 'a+')
self.logger.info('Running ansible to create snapshots for: {}'.format(test_name))
subprocess.Popen(subprocess_cmd, stdout=snapshot_log, stderr=subprocess.STDOUT)
self.logger.info(
'Running ansible to create snapshots for: {}'.format(test_name))
subprocess.Popen(
subprocess_cmd, stdout=snapshot_log, stderr=subprocess.STDOUT)

View File

@ -11,6 +11,7 @@ import time
class PerfKit:
def __init__(self, config):
self.logger = logging.getLogger('browbeat.PerfKit')
self.config = config
@ -22,9 +23,12 @@ class PerfKit:
self.scenario_count = 0
def _log_details(self):
self.logger.info("Current number of scenarios executed: {}".format(self.scenario_count))
self.logger.info("Current number of test(s) executed: {}".format(self.test_count))
self.logger.info("Current number of test failures: {}".format(self.error_count))
self.logger.info(
"Current number of scenarios executed: {}".format(self.scenario_count))
self.logger.info(
"Current number of test(s) executed: {}".format(self.test_count))
self.logger.info(
"Current number of test failures: {}".format(self.error_count))
def run_benchmark(self, benchmark_config, result_dir, test_name, cloud_type="OpenStack"):
self.logger.debug("--------------------------------")
@ -45,7 +49,8 @@ class PerfKit:
benchmark_config[default_item] = value
for parameter, value in benchmark_config.iteritems():
if not parameter == 'name':
self.logger.debug("Parameter: {}, Value: {}".format(parameter, value))
self.logger.debug(
"Parameter: {}, Value: {}".format(parameter, value))
cmd += " --{}={}".format(parameter, value)
# Remove any old results
@ -62,7 +67,8 @@ class PerfKit:
self.logger.info("Running Perfkit Command: {}".format(cmd))
stdout_file = open("{}/pkb.stdout.log".format(result_dir), 'w')
stderr_file = open("{}/pkb.stderr.log".format(result_dir), 'w')
process = subprocess.Popen(cmd, shell=True, stdout=stdout_file, stderr=stderr_file)
process = subprocess.Popen(
cmd, shell=True, stdout=stdout_file, stderr=stderr_file)
process.communicate()
if 'sleep_after' in self.config['perfkit']:
time.sleep(self.config['perfkit']['sleep_after'])
@ -75,7 +81,8 @@ class PerfKit:
self.connmon.move_connmon_results(result_dir, test_name)
self.connmon.connmon_graphs(result_dir, test_name)
except:
self.logger.error("Connmon Result data missing, Connmon never started")
self.logger.error(
"Connmon Result data missing, Connmon never started")
# Determine success
try:
@ -86,7 +93,8 @@ class PerfKit:
self.logger.error("Benchmark failed.")
self.error_count += 1
except IOError:
self.logger.error("File missing: {}/pkb.stderr.log".format(result_dir))
self.logger.error(
"File missing: {}/pkb.stderr.log".format(result_dir))
# Copy all results
for perfkit_file in glob.glob("/tmp/perfkitbenchmarker/run_browbeat/*"):
@ -96,7 +104,8 @@ class PerfKit:
# Grafana integration
self.grafana.print_dashboard_url(from_ts, to_ts, test_name)
self.grafana.log_snapshot_playbook_cmd(from_ts, to_ts, result_dir, test_name)
self.grafana.log_snapshot_playbook_cmd(
from_ts, to_ts, result_dir, test_name)
self.grafana.run_playbook(from_ts, to_ts, result_dir, test_name)
def start_workloads(self):
@ -113,10 +122,12 @@ class PerfKit:
self.test_count += 1
result_dir = self.tools.create_results_dir(
self.config['browbeat']['results'], time_stamp, benchmark['name'], run)
test_name = "{}-{}-{}".format(time_stamp, benchmark['name'], run)
test_name = "{}-{}-{}".format(time_stamp,
benchmark['name'], run)
self.run_benchmark(benchmark, result_dir, test_name)
self._log_details()
else:
self.logger.info("Skipping {} benchmark, enabled: false".format(benchmark['name']))
self.logger.info(
"Skipping {} benchmark, enabled: false".format(benchmark['name']))
else:
self.logger.error("Config file contains no perfkit benchmarks.")

View File

@ -12,6 +12,7 @@ import time
class Rally:
def __init__(self, config):
self.logger = logging.getLogger('browbeat.Rally')
self.config = config
@ -52,15 +53,18 @@ class Rally:
to_ts = int(time.time() * 1000)
self.grafana.print_dashboard_url(from_ts, to_ts, test_name)
self.grafana.log_snapshot_playbook_cmd(from_ts, to_ts, result_dir, test_name)
self.grafana.log_snapshot_playbook_cmd(
from_ts, to_ts, result_dir, test_name)
self.grafana.run_playbook(from_ts, to_ts, result_dir, test_name)
def workload_logger(self, result_dir):
base = result_dir.split('/')
if not os.path.isfile("{}/{}/browbeat-rally-run.log".format(base[0], base[1])):
file = logging.FileHandler("{}/{}/browbeat-rally-run.log".format(base[0], base[1]))
file = logging.FileHandler(
"{}/{}/browbeat-rally-run.log".format(base[0], base[1]))
file.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)5s - %(message)s')
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)5s - %(message)s')
file.setFormatter(formatter)
self.logger.addHandler(file)
return None
@ -75,18 +79,23 @@ class Rally:
return self.scenario_count
def get_task_id(self, test_name):
cmd = "grep \"rally task results\" {}.log | awk '{{print $4}}'".format(test_name)
cmd = "grep \"rally task results\" {}.log | awk '{{print $4}}'".format(
test_name)
return self.tools.run_cmd(cmd)
def _get_details(self):
self.logger.info("Current number of scenarios executed:{}".format(self.get_scenario_count()))
self.logger.info("Current number of test(s) executed:{}".format(self.get_test_count()))
self.logger.info("Current number of test failures:{}".format(self.get_error_count()))
self.logger.info("Current number of scenarios executed:{}".format(
self.get_scenario_count()))
self.logger.info(
"Current number of test(s) executed:{}".format(self.get_test_count()))
self.logger.info("Current number of test failures:{}".format(
self.get_error_count()))
def gen_scenario_html(self, task_ids, test_name):
all_task_ids = ' '.join(task_ids)
cmd = "source {}; ".format(self.config['rally']['venv'])
cmd += "rally task report --task {} --out {}.html".format(all_task_ids, test_name)
cmd += "rally task report --task {} --out {}.html".format(
all_task_ids, test_name)
return self.tools.run_cmd(cmd)
def gen_scenario_json(self, task_id, test_name):
@ -109,26 +118,32 @@ class Rally:
scenarios = benchmark['scenarios']
def_concurrencies = benchmark['concurrency']
def_times = benchmark['times']
self.logger.debug("Default Concurrencies: {}".format(def_concurrencies))
self.logger.debug(
"Default Concurrencies: {}".format(def_concurrencies))
self.logger.debug("Default Times: {}".format(def_times))
for scenario in scenarios:
if scenario['enabled']:
self.scenario_count += 1
scenario_name = scenario['name']
scenario_file = scenario['file']
self.logger.info("Running Scenario: {}".format(scenario_name))
self.logger.debug("Scenario File: {}".format(scenario_file))
self.logger.info(
"Running Scenario: {}".format(scenario_name))
self.logger.debug(
"Scenario File: {}".format(scenario_file))
del scenario['enabled']
del scenario['file']
del scenario['name']
if len(scenario) > 0:
self.logger.debug("Overriding Scenario Args: {}".format(scenario))
self.logger.debug(
"Overriding Scenario Args: {}".format(scenario))
result_dir = self.tools.create_results_dir(
self.config['browbeat']['results'], time_stamp, benchmark['name'],
self.config['browbeat'][
'results'], time_stamp, benchmark['name'],
scenario_name)
self.logger.debug("Created result directory: {}".format(result_dir))
self.logger.debug(
"Created result directory: {}".format(result_dir))
self.workload_logger(result_dir)
# Override concurrency/times
@ -150,34 +165,44 @@ class Rally:
scenario_name, concurrency, run)
if not result_dir:
self.logger.error("Failed to create result directory")
self.logger.error(
"Failed to create result directory")
exit(1)
# Start connmon before rally
if self.config['connmon']['enabled']:
self.connmon.start_connmon()
self.run_scenario(scenario_file, scenario, result_dir, test_name)
self.run_scenario(
scenario_file, scenario, result_dir, test_name)
# Stop connmon at end of rally task
if self.config['connmon']['enabled']:
self.connmon.stop_connmon()
try:
self.connmon.move_connmon_results(result_dir, test_name)
self.connmon.move_connmon_results(
result_dir, test_name)
except:
self.logger.error("Connmon Result data missing, Connmon never started")
self.logger.error(
"Connmon Result data missing, Connmon never started")
return False
self.connmon.connmon_graphs(result_dir, test_name)
self.connmon.connmon_graphs(
result_dir, test_name)
# Find task id (if task succeeded in running)
# Find task id (if task succeeded in
# running)
task_id = self.get_task_id(test_name)
if task_id:
self.logger.info("Generating Rally HTML for task_id : {}".format(task_id))
self.gen_scenario_html([task_id], test_name)
self.gen_scenario_json(task_id, test_name)
self.logger.info(
"Generating Rally HTML for task_id : {}".format(task_id))
self.gen_scenario_html(
[task_id], test_name)
self.gen_scenario_json(
task_id, test_name)
results[run].append(task_id)
else:
self.logger.error("Cannot find task_id")
self.logger.error(
"Cannot find task_id")
self.error_count += 1
for data in glob.glob("./{}*".format(test_name)):
@ -186,9 +211,11 @@ class Rally:
self._get_details()
else:
self.logger.info("Skipping {} scenario enabled: false".format(scenario['name']))
self.logger.info(
"Skipping {} scenario enabled: false".format(scenario['name']))
else:
self.logger.info("Skipping {} benchmarks enabled: false".format(benchmark['name']))
self.logger.info(
"Skipping {} benchmarks enabled: false".format(benchmark['name']))
self.logger.debug("Creating Combined Rally Reports")
for run in results:
combined_html_name = 'all-rally-run-{}'.format(run)

View File

@ -7,7 +7,9 @@ import os
import json
import time
class Shaker:
def __init__(self, config):
self.logger = logging.getLogger('browbeat.Shaker')
self.config = config
@ -26,16 +28,21 @@ class Shaker:
self.logger.info("Shaker image is built, continuing")
def get_stats(self):
self.logger.info("Current number of scenarios executed: {}".format(self.scenarios_count))
self.logger.info("Current number of scenarios passed: {}".format(self.pass_scenarios))
self.logger.info("Current number of scenarios failed: {}".format(self.fail_scenarios))
self.logger.info(
"Current number of scenarios executed: {}".format(self.scenarios_count))
self.logger.info(
"Current number of scenarios passed: {}".format(self.pass_scenarios))
self.logger.info(
"Current number of scenarios failed: {}".format(self.fail_scenarios))
def final_stats(self, total):
self.logger.info("Total scenarios enabled by user: {}".format(total))
self.logger.info("Total number of scenarios executed: {}".format(self.scenarios_count))
self.logger.info("Total number of scenarios passed: {}".format(self.pass_scenarios))
self.logger.info("Total number of scenarios failed: {}".format(self.fail_scenarios))
self.logger.info(
"Total number of scenarios executed: {}".format(self.scenarios_count))
self.logger.info(
"Total number of scenarios passed: {}".format(self.pass_scenarios))
self.logger.info(
"Total number of scenarios failed: {}".format(self.fail_scenarios))
def set_scenario(self, scenario):
fname = scenario['file']
@ -52,18 +59,22 @@ class Shaker:
else:
data['deployment']['accommodation'][1] = default_placement
if "density" in scenario:
data['deployment']['accommodation'][2]['density'] = scenario['density']
data['deployment']['accommodation'][
2]['density'] = scenario['density']
else:
data['deployment']['accommodation'][2]['density'] = default_density
if "compute" in scenario:
data['deployment']['accommodation'][3]['compute_nodes'] = scenario['compute']
data['deployment']['accommodation'][3][
'compute_nodes'] = scenario['compute']
else:
data['deployment']['accommodation'][3]['compute_nodes'] = default_compute
data['deployment']['accommodation'][3][
'compute_nodes'] = default_compute
if "progression" in scenario:
data['execution']['progression'] = scenario['progression']
else:
data['execution']['progression'] = default_progression
data['execution']['tests']=[d for d in data['execution']['tests'] if d.get('class') == "iperf_graph"]
data['execution']['tests'] = [d for d in data['execution']
['tests'] if d.get('class') == "iperf_graph"]
if "time" in scenario:
data['execution']['tests'][0]['time'] = scenario['time']
else:
@ -88,15 +99,17 @@ class Shaker:
error = True
if error:
self.logger.error("Failed scenario: {}".format(scenario['name']))
self.logger.error("saved log to: {}.log".format(os.path.join(result_dir, test_name)))
self.logger.error("saved log to: {}.log".format(
os.path.join(result_dir, test_name)))
self.fail_scenarios += 1
else:
self.logger.info("Completed Scenario: {}".format(scenario['name']))
self.logger.info("Saved report to: {}".format(os.path.join(result_dir, test_name + "." + "html")))
self.logger.info("saved log to: {}.log".format(os.path.join(result_dir, test_name)))
self.logger.info("Saved report to: {}".format(
os.path.join(result_dir, test_name + "." + "html")))
self.logger.info("saved log to: {}.log".format(
os.path.join(result_dir, test_name)))
self.pass_scenarios += 1
def run_scenario(self, scenario, result_dir, test_name):
filename = scenario['file']
server_endpoint = self.config['shaker']['server']
@ -105,7 +118,8 @@ class Shaker:
venv = self.config['shaker']['venv']
shaker_region = self.config['shaker']['shaker_region']
timeout = self.config['shaker']['join_timeout']
cmd_1 = ("source {}/bin/activate; source /home/stack/overcloudrc").format(venv)
cmd_1 = (
"source {}/bin/activate; source /home/stack/overcloudrc").format(venv)
cmd_2 = ("shaker --server-endpoint {0}:{1} --flavor-name {2} --scenario {3}"
" --os-region-name {7} --agent-join-timeout {6}"
" --report {4}/{5}.html --output {4}/{5}.json"
@ -123,7 +137,8 @@ class Shaker:
to_ts = int(time.time() * 1000)
# Snapshotting
self.grafana.print_dashboard_url(from_ts, to_ts, test_name)
self.grafana.log_snapshot_playbook_cmd(from_ts, to_ts, result_dir, test_name)
self.grafana.log_snapshot_playbook_cmd(
from_ts, to_ts, result_dir, test_name)
self.grafana.run_playbook(from_ts, to_ts, result_dir, test_name)
def run_shaker(self):
@ -143,7 +158,8 @@ class Shaker:
self.logger.debug("Set Scenario File: {}".format(
scenario['file']))
result_dir = self.tools.create_results_dir(
self.config['browbeat']['results'], time_stamp, "shaker",
self.config['browbeat'][
'results'], time_stamp, "shaker",
scenario['name'])
time_stamp1 = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
test_name = "{}-browbeat-{}-{}".format(time_stamp1,
@ -151,8 +167,9 @@ class Shaker:
self.run_scenario(scenario, result_dir, test_name)
self.get_stats()
else:
self.logger.info("Skipping {} as scenario enabled: false".format(scenario['name']))
self.logger.info(
"Skipping {} as scenario enabled: false".format(scenario['name']))
self.final_stats(scen_enabled)
else:
self.logger.error("Configuration file contains no shaker scenarios")
self.logger.error(
"Configuration file contains no shaker scenarios")

View File

@ -3,6 +3,7 @@ import os
import shutil
from subprocess import Popen, PIPE
class Tools:
def __init__(self, config=None):
@ -39,11 +40,11 @@ class Tools:
except OSError as e:
return False
# Create directory for results
def create_results_dir(self, results_dir, timestamp, service, scenario):
try:
os.makedirs("{}/{}/{}/{}".format(results_dir, timestamp, service, scenario))
os.makedirs("{}/{}/{}/{}".format(results_dir,
timestamp, service, scenario))
self.logger.debug("{}/{}/{}/{}".format(os.path.dirname(results_dir), timestamp, service,
scenario))
return "{}/{}/{}/{}".format(os.path.dirname(results_dir), timestamp, service, scenario)

3
setup.cfg Normal file
View File

@ -0,0 +1,3 @@
[pep8]
ignore = E226,E302,E41,E111,E231,E203
max-line-length = 100