From c73328c444a29803ca7e268ec72ab0447cd9307e Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Sat, 18 Jan 2014 16:09:54 +1100 Subject: [PATCH] Continue prepping generic shell execution Change-Id: Ie4c8b849f9ed2d80c09104a8b2e0a30f143b2cbb --- turbo_hipster/lib/models.py | 43 ++++++++++++++++--- .../task_plugins/gate_real_db_upgrade/task.py | 2 +- .../task_plugins/shell_script/__init__.py | 0 .../task_plugins/shell_script/task.py | 27 ++++++++++++ 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 turbo_hipster/task_plugins/shell_script/__init__.py create mode 100644 turbo_hipster/task_plugins/shell_script/task.py diff --git a/turbo_hipster/lib/models.py b/turbo_hipster/lib/models.py index 66f26c8..d4a2738 100644 --- a/turbo_hipster/lib/models.py +++ b/turbo_hipster/lib/models.py @@ -124,24 +124,29 @@ class ShellTask(Task): def __init__(self, global_config, plugin_config, job_name): super(ShellTask, self).__init__(global_config, plugin_config, job_name) # Define the number of steps we will do to determine our progress. - self.total_steps = 4 + self.total_steps = 5 def _reset(self): super(ShellTask, self)._reset() self.git_path = None + self.job_working_dir = None + self.shell_output_log = None def do_job_steps(self, job): # Step 1: Checkout updates from git self._grab_patchset(self.job_arguments, self.job_datasets[0]['job_log_file_path']) - # Step 2: Run shell script + # Step 2: Prep job working dir + self._prep_working_dir() + + # Step 3: Run shell script self._execute_script() - # Step 3: Analyse logs for errors + # Step 4: Analyse logs for errors self._parse_and_check_results() - # Step 4: handle the results (and upload etc) + # Step 5: handle the results (and upload etc) self._handle_results() @common.task_step @@ -166,10 +171,38 @@ class ShellTask(Task): self.git_path = local_path return local_path + @common.task_step + def _prep_working_dir(self): + self.job_working_dir = os.path.join( + self.global_config['jobs_working_dir'], + utils.determine_job_identifier(self.job_arguments, + self.plugin_config['function'], + self.job.unique) + ) + self.shell_output_log = os.path.join( + self.job_working_dir, + 'shell_output.log' + ) + + if not os.path.isdir(os.path.dirname(self.shell_output_log)): + os.makedirs(os.path.dirname(self.shell_output_log)) + @common.task_step def _execute_script(self): # Run script - self.script_return_code = 0 + cmd = self.plugin_config['shell_script'] + cmd += ( + (' %(git_path)s %(job_working_dir)s %(unique_id)s') + % { + 'git_path': self.git_path, + 'job_working_dir': self.job_working_dir, + 'unique_id': self.job.unique + } + ) + self.script_return_code = utils.execute_to_log( + cmd, + self.shell_output_log + ) @common.task_step def _parse_and_check_results(self): diff --git a/turbo_hipster/task_plugins/gate_real_db_upgrade/task.py b/turbo_hipster/task_plugins/gate_real_db_upgrade/task.py index 24313c0..d02bed0 100644 --- a/turbo_hipster/task_plugins/gate_real_db_upgrade/task.py +++ b/turbo_hipster/task_plugins/gate_real_db_upgrade/task.py @@ -48,7 +48,7 @@ class Runner(models.ShellTask): self.job_datasets = [] # Define the number of steps we will do to determine our progress. - self.total_steps = 5 + self.total_steps = 6 def do_job_steps(self): # Step 1: Figure out which datasets to run diff --git a/turbo_hipster/task_plugins/shell_script/__init__.py b/turbo_hipster/task_plugins/shell_script/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/turbo_hipster/task_plugins/shell_script/task.py b/turbo_hipster/task_plugins/shell_script/task.py new file mode 100644 index 0000000..6deef4e --- /dev/null +++ b/turbo_hipster/task_plugins/shell_script/task.py @@ -0,0 +1,27 @@ +# Copyright 2013 Rackspace Australia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import logging + +from turbo_hipster.lib import models + + +class Runner(models.ShellTask): + + """ This thread handles the actual sql-migration tests. + It pulls in a gearman job from the build:gate-real-db-upgrade + queue and runs it through _handle_patchset""" + + log = logging.getLogger("task_plugins.gate_real_db_upgrade.task.Runner")