| """Executes LUCI recipe tests.""" |
| from __future__ import absolute_import |
| import os |
| |
| from helpers import luci_recipe_utils |
| from slave import base_step |
| |
| _STEP_TIMEOUT_SECS = 5 * 60 # 5 minutes. |
| |
| |
| class LUCIRecipeBaseStep(base_step.BaseStep): |
| """Step for executing LUCI recipe commands for a single recipe package.""" |
| |
| def __init__(self, |
| script_path, |
| package_path, |
| timeout_secs=_STEP_TIMEOUT_SECS, |
| **kwargs): |
| super(LUCIRecipeBaseStep, self).__init__( |
| timeout_secs=timeout_secs, **kwargs) |
| script_abspath = os.path.join(self.directory, script_path) |
| package_abspath = os.path.join(self.directory, package_path) |
| |
| self._recipe_runner = luci_recipe_utils.LUCIRecipeRunner( |
| self, script_abspath, package_path=package_abspath) |
| |
| |
| class LUCIRecipeTestStep(LUCIRecipeBaseStep): |
| """Step for executing LUCI recipe expectation tests.""" |
| |
| def __init__(self, |
| script_path, |
| package_path, |
| test_retries, |
| **kwargs): |
| super().__init__( |
| script_path, package_path, **kwargs) |
| self._test_retries = test_retries |
| |
| def run(self): |
| retries = 0 |
| while retries <= self._test_retries: |
| returncode, _, _ = self._recipe_runner.run_tests() |
| if returncode == 0: |
| return True |
| retries += 1 |
| |
| # Max retries reached. |
| self.add_review({'message': 'Recipe tests failed! See step logs.'}) |
| return False |
| |
| |
| class LUCIRecipeBundleStep(LUCIRecipeBaseStep): |
| """Step for bundling a LUCI recipe.""" |
| |
| def __init__(self, script_path, package_path, destination, **kwargs): |
| super(LUCIRecipeBundleStep, self).__init__( |
| script_path, package_path, **kwargs) |
| self._destination_abspath = os.path.join(self.directory, destination) |
| |
| def run(self): |
| returncode, _, _ = self._recipe_runner.bundle(self._destination_abspath) |
| |
| if returncode != 0: |
| self.add_review({ |
| 'message': 'Failed to generate recipe bundle! See step logs.'}) |
| return False |
| return True |