Пример #1
0
 def run_playbook_test(self, test_name, run, extra_vars):
     playbook = self.abspath(run["playbook"])
     inventory = self.get_inventory_path(test_name)
     try:
         ansible_manager.run_playbook(playbook, inventory, extra_vars=extra_vars)
     except ansible_manager.AnsiblePlaybookError as exc:
         self.logger.error(exc.message)
         return False
     return True
Пример #2
0
 def teardown(self, test_name, run, env_cfg, extra_vars):
     """Does clean-up steps after a test."""
     playbook = self.abspath(env_cfg["teardown_playbook"])
     inventory = self.get_inventory_path(test_name)
     try:
         ansible_manager.run_playbook(playbook, inventory, extra_vars=extra_vars)
     except ansible_manager.AnsiblePlaybookError as exc:
         exc_info = traceback.format_exc()
         teamcity_messages.report_test("test_" + test_name + "_teardown", failed=True,
                                       message=exc.message, details=exc_info)
         raise TestError("Teardown for test {} raised exception: {}".format(test_name, exc_info))
Пример #3
0
    def setup(self, test_name, env_cfg, run, extra_vars):
        playbook = self.abspath(env_cfg["setup_playbook"])
        inventory = self.get_inventory_path(test_name)
        try:
            # Do prerequisite steps for a test
            ansible_manager.run_playbook(playbook, inventory, extra_vars=extra_vars)
        except ansible_manager.AnsiblePlaybookError as exc:
            exc_info = traceback.format_exc()
            teamcity_messages.report_test("test_" + test_name + "_setup", failed=True,
                                          message=exc.message, details=exc_info)
            raise TestError("Setup for test {} raised exception: {}".format(test_name, exc_info))

        # Check if it's a pytest test
        if run["type"] == "pytest":
            self.generate_pytest_cfg(run["addopts"])
Пример #4
0
    def install_elliptics_packages(self):
        """Installs elliptics packages on all servers and clients."""
        base_setup_playbook = "test-env-prepare"
        inventory_path = self.get_inventory_path(base_setup_playbook)
        groups = ansible_manager._get_groups_names("setup")

        ansible_manager.generate_inventory(inventory_path=inventory_path,
                                           clients_count=len(self.inventory['clients']),
                                           servers_per_group=[len(self.inventory['servers'])],
                                           groups=groups,
                                           instances_names=self.inventory,
                                           ssh_user=self.user)

        playbook = self.abspath(base_setup_playbook)
        ansible_manager.run_playbook(playbook, inventory_path)
Пример #5
0
def deploy_ci_task(self, host_list, vars):
    playbook_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'ansible'))
    playbook = os.path.join(playbook_dir, "deploy-ci.yml")
    deploy_ci_stages = ['ci', 'docker', 'jenkins', 'mysql', 'sonarqube', 'apache']
    deploy_ci_messages = ['Initializing CI VM', 'Setting up docker', 'Setting up jenkins',
                          'Setting up mysql', 'Setting up sonarqube',
                          'Setting up apache reverse proxy']
    result = 0
    ci_pubkey = None
    for i, (stage, message) in enumerate(zip(deploy_ci_stages, deploy_ci_messages)):
        vars['deploy_ci_stage'] = stage
        self.update_state(state='STARTED',
                          meta={'current': i, 'total': len(deploy_ci_stages),
                                'message': message, 'ci_pubkey': ci_pubkey})
        result, tmp_pubkey = run_playbook(playbook, host_list, vars)
        if result != 0:
            if result == 2:
                error = 'Task failed'
            elif result == 4:
                error = 'Unreachable host'
            else:
                error = 'Unknown'
            raise Exception('Failed at: ' + message + '. Reason: ' + error +
                            '. For more info, consult Celery log.')
        if tmp_pubkey is not None:
            ci_pubkey = tmp_pubkey
    return result