def register_result_file(self, server, result_id, path, filename, basepath): """ register file and return path to store """ try: result = RecipeTaskResult.by_id(result_id, lockmode='update') except NoResultFound: raise BX(_('Invalid result ID: %s' % result_id)) RecipeTask.by_id(result.recipe_task_id, lockmode='update') Recipe.by_id(result.recipetask.recipe_id, lockmode='update') if result.recipetask.is_finished(): raise BX('Cannot register file for finished task %s' % result.recipetask.t_id) self._check_log_limit(result.recipetask) log_recipe = LogRecipeTaskResult.lazy_create( recipe_task_result_id=result.id, path=path, filename=filename, ) log_recipe.server = server log_recipe.basepath = basepath result.recipetask.recipe.log_server = urlparse.urlparse(server)[1] return '%s' % result.filepath
def _get_recipe_task_by_id(recipeid, taskid): try: task = RecipeTask.by_id(taskid) except NoResultFound: raise NotFound404('Recipe task not found') if recipeid != '_' and str(task.recipe.id) != recipeid: raise NotFound404('Recipe task not found') return task
def start(self, task_id, watchdog_override=None): """ Set task status to Running """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) return task.start(watchdog_override)
def watchdog(self, task_id): """ Returns number of seconds left on task_id watchdog, or False if it doesn't exist. """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) return task.status_watchdog()
def extend(self, task_id, kill_time): """ Extend tasks watchdog by kill_time seconds """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) return task.extend(kill_time)
def test_recipe_task_result_rows_are_deleted(self): with session.begin(): self.job_to_delete.to_delete = datetime.datetime.utcnow() recipe = self.job_to_delete.recipesets[0].recipes[0] recipetask = recipe.tasks[0] self.assertEqual(len(recipetask.results), 1) log_delete.log_delete() with session.begin(): recipetask = RecipeTask.by_id(recipetask.id) self.assertEqual(len(recipetask.results), 0)
def result(self, task_id, result_type, path=None, score=None, summary=None): """ Record a Result """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if result_type not in task.result_types: raise BX(_('Invalid result_type: %s, must be one of %s' % (result_type, task.result_types))) kwargs = dict(path=path, score=score, summary=summary) return getattr(task,result_type)(**kwargs)
def stop(self, task_id, stop_type, msg=None): """ Set task status to Completed """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if stop_type not in task.stop_types: raise BX(_('Invalid stop_type: %s, must be one of %s' % (stop_type, task.stop_types))) kwargs = dict(msg = msg) return getattr(task,stop_type)(**kwargs)
def stop(self, task_id, stop_type, msg=None): """ Set task status to Completed """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if stop_type not in task.stop_types: raise BX( _('Invalid stop_type: %s, must be one of %s' % (stop_type, task.stop_types))) kwargs = dict(msg=msg) return getattr(task, stop_type)(**kwargs)
def register_result_file(self, server, result_id, path, filename, basepath): """ register file and return path to store """ try: result = RecipeTaskResult.by_id(result_id, lockmode='update') except NoResultFound: raise BX(_('Invalid result ID: %s' % result_id)) RecipeTask.by_id(result.recipe_task_id, lockmode='update') Recipe.by_id(result.recipetask.recipe_id, lockmode='update') if result.recipetask.is_finished(): raise BX('Cannot register file for finished task %s' % result.recipetask.t_id) self._check_log_limit(result.recipetask) log_recipe = LogRecipeTaskResult.lazy_create(recipe_task_result_id=result.id, path=path, filename=filename, ) log_recipe.server = server log_recipe.basepath = basepath result.recipetask.recipe.log_server = urlparse.urlparse(server)[1] return '%s' % result.filepath
def update(self, task_id, data): """ XML-RPC method used by the lab controller harness API to update a recipe-task's attributes. """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if 'name' in data: task.name = data['name'] if 'version' in data: task.version = data['version'] return task.__json__()
def result(self, task_id, result_type, path=None, score=None, summary=None): """ Record a Result """ try: task = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if result_type not in task.result_types: raise BX( _('Invalid result_type: %s, must be one of %s' % (result_type, task.result_types))) kwargs = dict(path=path, score=score, summary=summary) return getattr(task, result_type)(**kwargs)
def register_file(self, server, task_id, path, filename, basepath): """ register file and return path to store """ try: recipetask = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if recipetask.is_finished(): raise BX('Cannot register file for finished task %s' % recipetask.t_id) # Add the log to the DB if it hasn't been recorded yet. log_recipe = LogRecipeTask.lazy_create(recipe_task_id=recipetask.id, path=path, filename=filename, ) log_recipe.server = server log_recipe.basepath = basepath recipetask.recipe.log_server = urlparse.urlparse(server)[1] return '%s' % recipetask.filepath
def register_file(self, server, task_id, path, filename, basepath): """ register file and return path to store """ try: recipetask = RecipeTask.by_id(task_id) except InvalidRequestError: raise BX(_('Invalid task ID: %s' % task_id)) if recipetask.is_finished(): raise BX('Cannot register file for finished task %s' % recipetask.t_id) # Add the log to the DB if it hasn't been recorded yet. log_recipe = LogRecipeTask.lazy_create( recipe_task_id=recipetask.id, path=path, filename=filename, ) log_recipe.server = server log_recipe.basepath = basepath recipetask.recipe.log_server = urlparse.urlparse(server)[1] return '%s' % recipetask.filepath
def peer_roles(self, task_id): try: task = RecipeTask.by_id(task_id) except NoResultFound: raise BX(_('Invalid task ID: %s') % task_id) # don't use set, we want to preserve ordering roles = {} for role, recipes in task.recipe.peer_roles().iteritems(): fqdns = roles.setdefault(unicode(role), []) for recipe in recipes: if not recipe.resource or not recipe.resource.fqdn: continue fqdn = unicode(recipe.resource.fqdn) if fqdn not in fqdns: fqdns.append(fqdn) for role, tasks in task.peer_roles().iteritems(): fqdns = roles.setdefault(unicode(role), []) for task in tasks: if not task.recipe.resource or not task.recipe.resource.fqdn: continue fqdn = unicode(task.recipe.resource.fqdn) if fqdn not in fqdns: fqdns.append(fqdn) return roles
def to_xml(self, id): taskxml = RecipeTask.by_id(id).to_xml().toprettyxml() return dict(xml=taskxml)