示例#1
0
    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
示例#2
0
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
示例#3
0
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
示例#4
0
 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)
示例#5
0
 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()
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
 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()
示例#10
0
 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)
示例#11
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)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
    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
示例#15
0
 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__()
示例#16
0
 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__()
示例#17
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)
示例#18
0
    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
示例#19
0
    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
示例#20
0
 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
示例#21
0
 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
示例#22
0
 def to_xml(self, id):
     taskxml = RecipeTask.by_id(id).to_xml().toprettyxml()
     return dict(xml=taskxml)
示例#23
0
 def to_xml(self, id):
     taskxml = RecipeTask.by_id(id).to_xml().toprettyxml()
     return dict(xml=taskxml)