def created_task(pcmodel, execution_model): tsk = task.PlaybookPluginTask( pcmodel.playbook_id, pcmodel._id, execution_model.model_id ) tsk.create() yield tsk
def new_task(public_playbook_name, configured_new_pcmodel, new_execution): tsk = task.PlaybookPluginTask(public_playbook_name, configured_new_pcmodel._id, new_execution.model_id) tsk.create() return tsk
def test_plugin_finish(action, state, new_pcmodel, new_execution): new_task = task.PlaybookPluginTask( new_pcmodel.playbook_id, new_pcmodel._id, new_execution.model_id) new_task.create() new_task.start() assert all(srv.lock is not None for srv in new_pcmodel.servers) new_execution = execution.ExecutionModel.find_by_model_id( new_execution.model_id) assert new_execution.state == execution.ExecutionState.started getattr(new_task, action)() new_execution = execution.ExecutionModel.find_by_model_id( new_execution.model_id) assert new_execution.state == state assert all(srv.lock is None for srv in new_pcmodel.servers)
def post(self): pc_id = self.request_json["playbook_configuration"]["id"] pc_version = self.request_json["playbook_configuration"]["version"] config = playbook_configuration.PlaybookConfigurationModel config = config.find_version(pc_id, pc_version) if not config: LOG.warning( "Cannot find playbook configuration %s of version %s", pc_id, pc_version ) raise http_exceptions.UnknownPlaybookConfiguration( pc_id, pc_version ) auth.check_auth_permission(flask.g.token.user, "playbook", config.playbook_id) model = execution.ExecutionModel.create(config, self.initiator_id) LOG.info( "Created execution %s for playbook configuration %s of " "version %s", model.model_id, config.model_id, config.version ) try: tsk = task.PlaybookPluginTask( config.playbook_id, config._id, model.model_id ) tsk.create() except Exception as exc: LOG.error("Cannot create task for execution %s: %s", model.model_id, exc) model.state = execution.ExecutionState.failed model.save() raise else: LOG.info("Created task for execution %s: %s", model.model_id, tsk._id) return model
def test_plugin_finish(action, state, new_pcmodel, new_execution, pymongo_connection): new_task = task.PlaybookPluginTask( new_pcmodel.playbook_id, new_pcmodel._id, new_execution.model_id) new_task.create() new_task.start() assert all(srv.lock is not None for srv in new_pcmodel.servers) new_execution = execution.ExecutionModel.find_by_model_id( new_execution.model_id) assert new_execution.state == execution.ExecutionState.started getattr(new_task, action)() new_execution = execution.ExecutionModel.find_by_model_id( new_execution.model_id) assert new_execution.state == state assert all(srv.lock is None for srv in new_pcmodel.servers) db_task = pymongo_connection.db.task.find_one({"_id": new_task._id}) assert db_task assert task.TTL_FIELDNAME in db_task
def compose_commandline(path, playbook_config): destpath = path.joinpath("execute.sh") faketask = task.PlaybookPluginTask(playbook_config.playbook_id, playbook_config._id, None) plugin = plugins.get_public_playbook_plugins()[playbook_config.playbook_id] plugin = plugin() plugin.compose_command(faketask) proc = plugin.proc proc.env = {} proc.options["--inventory-file"] = "inventory.yaml" extras = json.loads(proc.options["--extra-vars"]) extras["decapod_common_playbooks"] = "../common_playbooks" extras["fetch_directory"] = "fetch_directory" extras = patch_plugin_paths(extras, plugin) proc.options["--extra-vars"] = process.jsonify(extras) proc.command = "ansible-playbook" proc.args = [ path.joinpath("plugin", plugin.playbook_filename).relative_to(path).as_posix() ] shell_script = """\ #!/bin/bash set +e cd "$(dirname "$0")" {0} cd - >/dev/null 2>&1 """.format(proc.printable_commandline) shell_script = textwrap.dedent(shell_script) destpath.write_text(shell_script) destpath.chmod(0o755)