def list_tests(context, verbose, test_dirs): """ Print a list of test files or test cases. If verbose option selected, print all tests cases in each test file, otherwise print the test files only. If test_dirs supplied they will be used to search for tests otherwise the default test directories are used. """ no_color = context.obj['no_color'] test_dirs = test_dirs or TEST_PATHS try: results = collect_tests(test_dirs, verbose) except Exception as error: echo_style("An error occurred retrieving test files: {}".format(error), no_color, fg='red') sys.exit(1) if verbose: for index, test_file in enumerate(results): if index % 2 == 0: fg = 'blue' else: fg = 'green' echo_style('\n'.join(test_file), no_color, fg=fg) else: click.echo('\n'.join(results))
def test(context, accelerated_networking, access_key_id, account, cleanup, config, description, distro, early_exit, history_log, image_id, image_project, inject, instance_type, ip_address, log_level, no_default_test_dirs, cloud_config, region, results_dir, running_instance_id, secret_access_key, security_group_id, service_account_file, ssh_key_name, ssh_private_key_file, ssh_user, subnet_id, test_dirs, timeout, vnet_name, vnet_resource_group, collect_vm_info, cloud, compartment_id, availability_domain, signing_key_fingerprint, signing_key_file, tenancy, oci_user_id, enable_secure_boot, enable_uefi, tests): """Test image in the given framework using the supplied test files.""" no_color = context.obj['no_color'] try: status, results = test_image( cloud, accelerated_networking, access_key_id, account, cleanup, config, description, distro, early_exit, history_log, image_id, image_project, inject, instance_type, ip_address, log_level, no_default_test_dirs, cloud_config, region, results_dir, running_instance_id, secret_access_key, security_group_id, service_account_file, ssh_key_name, ssh_private_key_file, ssh_user, subnet_id, test_dirs, tests, timeout, vnet_name, vnet_resource_group, collect_vm_info, compartment_id, availability_domain, signing_key_fingerprint, signing_key_file, tenancy, oci_user_id, enable_secure_boot, enable_uefi) echo_results(results, no_color) sys.exit(status) except Exception as error: if log_level == logging.DEBUG: raise echo_style("{}: {}".format(type(error).__name__, error), no_color, fg='red') sys.exit(1)
def show(context, log, results_file, verbose, item): """ Print test results info from provided results json file. If no results file is supplied echo results from most recent test in history if it exists. If verbose option selected, echo all test cases. If log option selected echo test log. """ history_log = context.obj['history_log'] no_color = context.obj['no_color'] if not results_file: # Find results/log file from history # Default -1 is most recent test run try: with open(history_log, 'r') as f: lines = f.readlines() history = lines[len(lines) - item] except IndexError: echo_style('History result at index %s does not exist.' % item, no_color, fg='red') sys.exit(1) except Exception: echo_style( 'Unable to retrieve results history, ' 'provide results file or re-run test.', no_color, fg='red') sys.exit(1) log_file = get_log_file_from_item(history) if log: echo_log(log_file, no_color) else: echo_results_file( log_file.rsplit('.', 1)[0] + '.results', no_color, verbose) elif log: # Log file provided log_file = results_file.rsplit('.', 1)[0] + '.log' echo_log(log_file, no_color) else: # Results file provided echo_results_file(results_file, no_color, verbose)
def delete(context, item): """ Delete the specified history item from the history log. """ history_log = context.obj['history_log'] no_color = context.obj['no_color'] try: with open(history_log, 'r+') as f: lines = f.readlines() history = lines.pop(len(lines) - item) f.seek(0) f.write(''.join(lines)) f.flush() f.truncate() except IndexError: echo_style('History result at index %s does not exist.' % item, no_color, fg='red') sys.exit(1) except Exception as error: echo_style('Unable to delete result item {0}. {1}'.format(item, error), no_color, fg='red') sys.exit(1) log_file = get_log_file_from_item(history) try: os.remove(log_file) except Exception: echo_style('Unable to delete results file for item {0}.'.format(item), no_color, fg='red') try: os.remove(log_file.rsplit('.', 1)[0] + '.results') except Exception: echo_style('Unable to delete log file for item {0}.'.format(item), no_color, fg='red')