def run_tests(self): testsfailed = 0 for test_name, cfg in self.tests.items(): for run in cfg["runs"]: with teamcity_messages.block("TEST: {}".format(run["test_name"])): env_cfg = cfg["test_env_cfg"] test_info = self.test_info.format(run["test_name"], run["description"], env_cfg["clients"]["count"], env_cfg["servers"]["count_per_group"]) self.logger.info(test_info) extra_vars = copy.deepcopy(run["params"]) # Expand extra ansible variables with special fields extra_vars.update({"test_name": run["test_name"]}) self.setup(test_name, cfg["test_env_cfg"], run, extra_vars) if not self.run(test_name, run, cfg["test_env_cfg"], extra_vars): testsfailed += 1 self.teardown(test_name, run, cfg["test_env_cfg"], extra_vars) if testsfailed: return False else: return True
def run_playbook(playbook, inventory, extra_vars={}): tc_block = "ANSIBLE: {}({})".format(os.path.basename(playbook), os.path.basename(inventory)) with teamcity_messages.block(tc_block): extra_vars_qjson = json.dumps(extra_vars) cmd = "ansible-playbook -v --extra-vars='{}' --inventory-file {} {}.yml" cmd = cmd.format(extra_vars_qjson, inventory, playbook) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) for line in iter(process.stdout.readline, ''): sys.stdout.write(line) process.wait() if process.returncode: error_msg = "Playbook {} failed (exit code: {})".format(playbook, process.returncode) raise AnsiblePlaybookError(error_msg)
def __init__(self, args): repo_dir = os.path.dirname(os.path.abspath(__file__)) self.project_dir = os.path.abspath(os.path.join(repo_dir, "..")) self.ansible_dir = os.path.join(self.project_dir, "ansible") self.configs_dir = os.path.abspath(os.path.expanduser(args.configs_dir)) self.user = args.user if args.testsuite_params: with open(args.testsuite_params, 'r') as f: self.testsuite_params = json.load(f) else: self.testsuite_params = {} self.logger = logging.getLogger('runner_logger') self.teamcity = args.teamcity self.tests = self._get_ordered_tests(args.tags) self.inventory = self.get_inventory(args.inventory, args.instance_name) self.tests = self.expand_tests_configs() with teamcity_messages.block("PREPARE TEST ENVIRONMENT"): self.prepare_ansible_test_files() self.install_elliptics_packages()
def main(args): exitcode = EXIT_OK try: setup_loggers(args.teamcity, args.verbose) testrunner = TestRunner(args) if not testrunner.run_tests(): exitcode = EXIT_TESTSFAILED except TestError: traceback.print_exc(file=sys.stderr) exitcode = EXIT_TESTSFAILED except: traceback.print_exc(file=sys.stderr) exitcode = EXIT_INTERNALERROR finally: if args.teamcity: # Upload artifacts to file storage with teamcity_messages.block("LOGS: Links"): for artifacts in os.listdir(ARTIFACTS_PATH): print(qa_storage_upload(os.path.join(ARTIFACTS_PATH, artifacts))) return exitcode