def get_filenames(bundle): prefix = file_prefix(bundle) now = datetime.now().replace(microsecond=0).isoformat() html_filename = "{}-{}-result.html".format(prefix, now) json_filename = "{}-{}-result.json".format(prefix, now) result_dir = 'results' mkdir_p(result_dir) html_filename = os.path.join(result_dir, html_filename) json_filename = os.path.join(result_dir, json_filename) return html_filename, json_filename
def run_benchmark(test_plan, bundle, output_filename, provider_name, env): """Run benchmarks and get the results.""" client = jujuclient.Actions(env) action_results = run_actions(test_plan, client, env.status()) if action_results: all_values = get_benchmark_data(file_prefix(bundle), os.path.dirname(output_filename), provider_name) value = action_results[0].values()[0]['value'] action_results[0].values()[0]['all_values'] = all_values + [value] return action_results return []
def run_benchmark(test_plan, bundle, output_filename, provider_name, env): """Run benchmarks and get the results.""" client = jujuclient.Actions(env) action_results = run_actions(test_plan, client, env.status()) if action_results: all_values = get_benchmark_data( file_prefix(bundle), os.path.dirname(output_filename), provider_name) value = action_results[0].values()[0]['value'] action_results[0].values()[0]['all_values'] = all_values + [value] return action_results return []
def get_past_test_results(self, filename): dir = os.path.dirname(filename) files = [os.path.join(dir, f) for f in os.listdir(dir) if f.startswith(file_prefix(self.bundle)) and f.endswith('.json')] try: files.remove(filename) except ValueError: pass results = [] for f in files: with codecs.open(f, 'r', encoding='utf-8') as fp: results.append(json.load(fp)) results = sorted(results, key=lambda r: r["date"]) return results, files
def get_past_test_results(self, filename): dir = os.path.dirname(filename) files = [ os.path.join(dir, f) for f in os.listdir(dir) if f.startswith(file_prefix(self.bundle)) and f.endswith('.json') ] try: files.remove(filename) except ValueError: pass results = [] for f in files: with codecs.open(f, 'r', encoding='utf-8') as fp: results.append(json.load(fp)) results = sorted(results, key=lambda r: r["date"]) return results, files
def get_filenames(bundle): prefix = file_prefix(bundle) now = datetime.now().replace(microsecond=0).isoformat() html_filename = "{}-{}-result.html".format(prefix, now) json_filename = "{}-{}-result.json".format(prefix, now) result_dir = 'results' mkdir_p(result_dir) static_dir = os.path.dirname(os.path.abspath(__file__)) static_dir = os.path.join(static_dir, 'static') try: shutil.copytree(static_dir, os.path.join(result_dir, 'static')) except OSError as e: if e.errno != errno.EEXIST: raise html_filename = os.path.join(result_dir, html_filename) json_filename = os.path.join(result_dir, json_filename) return html_filename, json_filename
def main(args): log_level = logging.DEBUG if args.verbose else logging.INFO configure_logging(log_level) logging.info('Cloud Weather Report started.') test_plan = None if args.test_plan: test_plan = read_file(args.test_plan, 'yaml') results = [] status = None bundle = test_plan.get('bundle') html_filename, json_filename = get_filenames(bundle) for env_name in args.controller: env = jujuclient.Environment.connect(env_name=env_name) env_info = env.info() provider_name = get_provider_name(env_info["ProviderType"]) logging.info('Running test on {}.'.format(provider_name)) test_results, status = run_bundle_test( args=args, env=env_name, test_plan=test_plan) client = jujuclient.Actions(env) action_results = [] if test_plan.get('benchmark'): action_results = run_actions(test_plan, client, env.status()) all_values = get_benchmark_data( file_prefix(bundle), os.path.dirname(json_filename), provider_name) value = action_results[0].values()[0]['value'] action_results[0].values()[0]['all_values'] = all_values + [value] results.append({ "provider_name": provider_name, "test_results": json.loads(test_results) if test_results else None, "action_results": action_results, "info": env_info}) bundle_yaml = get_bundle_yaml(status) reporter = Reporter(bundle=bundle, results=results, options=args, bundle_yaml=bundle_yaml) reporter.generate(html_filename=html_filename, json_filename=json_filename) return html_filename