Пример #1
0
    def _handle_recipe_set(self, xmlrecipeSet, user, ignore_missing_tasks=False):
        """
        Handles the processing of recipesets into DB entries from their xml
        """
        recipeSet = RecipeSet(ttasks=0)
        recipeset_priority = xmlrecipeSet.get_xml_attr('priority',unicode,None) 
        if recipeset_priority is not None:
            try:
                my_priority = TaskPriority.from_string(recipeset_priority)
            except InvalidRequestError:
                raise BX(_('You have specified an invalid recipeSet priority:%s' % recipeset_priority))
            allowed_priorities = RecipeSet.allowed_priorities_initial(user)
            if my_priority in allowed_priorities:
                recipeSet.priority = my_priority
            else:
                recipeSet.priority = TaskPriority.default_priority() 
        else:
            recipeSet.priority = TaskPriority.default_priority() 

        for xmlrecipe in xmlrecipeSet.iter_recipes():
            recipe = self.handleRecipe(xmlrecipe, user,
                    ignore_missing_tasks=ignore_missing_tasks)
            recipe.ttasks = len(recipe.tasks)
            recipeSet.ttasks += recipe.ttasks
            recipeSet.recipes.append(recipe)
            # We want the guests to be part of the same recipeSet
            for guest in recipe.guests:
                recipeSet.recipes.append(guest)
                guest.ttasks = len(guest.tasks)
                recipeSet.ttasks += guest.ttasks
        if not recipeSet.recipes:
            raise BX(_('No Recipes! You can not have a recipeSet with no recipes!'))
        return recipeSet
Пример #2
0
def process_new_recipe(recipe_id):
    recipe = MachineRecipe.by_id(recipe_id)
    if not recipe.distro_tree:
        log.info("recipe ID %s moved from New to Aborted", recipe.id)
        recipe.recipeset.abort(u'Recipe ID %s does not have a distro tree' % recipe.id)
        return
    recipe.systems = []

    # Do the query twice.

    # First query verifies that the distro tree 
    # exists in at least one lab that has a matching system.
    systems = recipe.distro_tree.systems_filter(
                                recipe.recipeset.job.owner,
                                recipe.host_requires,
                                only_in_lab=True)
    # Second query picks up all possible systems so that as 
    # trees appear in other labs those systems will be 
    # available.
    all_systems = recipe.distro_tree.systems_filter(
                                recipe.recipeset.job.owner,
                                recipe.host_requires,
                                only_in_lab=False)
    # based on above queries, condition on systems but add
    # all_systems.
    if systems.count():
        for system in all_systems:
            # Add matched systems to recipe.
            recipe.systems.append(system)

    # If the recipe only matches one system then bump its priority.
    if len(recipe.systems) == 1:
        try:
            log.info("recipe ID %s matches one system, bumping priority" % recipe.id)
            recipe.recipeset.priority = TaskPriority.by_index(
                    TaskPriority.index(recipe.recipeset.priority) + 1)
        except IndexError:
            # We may already be at the highest priority
            pass
    recipe.virt_status = recipe.check_virtualisability()
    if not recipe.systems and not _virt_possible(recipe):
        log.info("recipe ID %s moved from New to Aborted" % recipe.id)
        recipe.recipeset.abort(u'Recipe ID %s does not match any systems' % recipe.id)
        return
    recipe.process()
    log.info("recipe ID %s moved from New to Processed" % recipe.id)
    for guestrecipe in recipe.guests:
        guestrecipe.process()
Пример #3
0
def process_new_recipe(recipe_id):
    recipe = MachineRecipe.by_id(recipe_id)
    recipe.systems = []

    # Do the query twice.

    # First query verifies that the distro tree 
    # exists in at least one lab that has a matching system.
    # But if it's a user-supplied distro, we don't have a
    # distro tree to match the lab against - so it will return
    # all possible systems
    systems = recipe.candidate_systems(only_in_lab=True)
    # Second query picks up all possible systems so that as 
    # trees appear in other labs those systems will be 
    # available.
    all_systems = recipe.candidate_systems(only_in_lab=False)
    # based on above queries, condition on systems but add
    # all_systems.
    log.debug('Counting candidate systems for recipe %s', recipe.id)
    if systems.count():
        log.debug('Computing all candidate systems for recipe %s', recipe.id)
        for system in all_systems:
            # Add matched systems to recipe.
            recipe.systems.append(system)

    # If the recipe only matches one system then bump its priority.
    if config.get('beaker.priority_bumping_enabled', True) and len(recipe.systems) == 1:
        old_prio = recipe.recipeset.priority
        try:
            new_prio = TaskPriority.by_index(TaskPriority.index(old_prio) + 1)
        except IndexError:
            # We may already be at the highest priority
            pass
        else:
            log.info("recipe ID %s matches one system, bumping priority" % recipe.id)
            recipe.recipeset.record_activity(user=None, service=u'Scheduler',
                    action=u'Changed', field=u'Priority',
                    old=unicode(old_prio), new=unicode(new_prio))
            recipe.recipeset.priority = new_prio
    recipe.virt_status = recipe.check_virtualisability()
    if not recipe.systems and not _virt_possible(recipe):
        log.info("recipe ID %s moved from New to Aborted" % recipe.id)
        recipe.recipeset.abort(u'Recipe ID %s does not match any systems' % recipe.id)
        return
    recipe.process()
    log.info("recipe ID %s moved from New to Processed" % recipe.id)
    for guestrecipe in recipe.guests:
        guestrecipe.process()
Пример #4
0
def create_job_for_recipes(recipes, owner=None, whiteboard=None, cc=None,product=None,
        retention_tag=None, group=None, submitter=None, priority=None, **kwargs):
    if retention_tag is None:
        retention_tag = RetentionTag.by_tag(u'scratch') # Don't use default, unpredictable
    else:
        retention_tag = RetentionTag.by_tag(retention_tag)

    if owner is None:
        owner = create_user()
    if whiteboard is None:
        whiteboard = unique_name(u'job %s')
    job = Job(whiteboard=whiteboard, ttasks=sum(r.ttasks for r in recipes),
        owner=owner, retention_tag=retention_tag, group=group, product=product,
        submitter=submitter)
    if cc is not None:
        job.cc = cc
    if priority is None:
        priority = TaskPriority.default_priority()
    recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes),
            priority=priority)
    recipe_set.recipes.extend(recipes)
    job.recipesets.append(recipe_set)
    session.add(job)
    session.flush()
    log.debug('Created %s', job.t_id)
    return job
Пример #5
0
def create_recipeset_for_recipes(recipes, priority=None, queue_time=None, **kwargs):
    if priority is None:
        priority = TaskPriority.default_priority()
    recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes),
            priority=priority)
    if queue_time is not None:
        recipe_set.queue_time = queue_time
    recipe_set.recipes.extend(recipes)
    return recipe_set
Пример #6
0
def create_recipeset_for_recipes(recipes,
                                 priority=None,
                                 queue_time=None,
                                 **kwargs):
    if priority is None:
        priority = TaskPriority.default_priority()
    recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes),
                           priority=priority)
    if queue_time is not None:
        recipe_set.queue_time = queue_time
    recipe_set.recipes.extend(recipes)
    return recipe_set
Пример #7
0
    def _handle_recipe_set(self,
                           xmlrecipeSet,
                           user,
                           ignore_missing_tasks=False):
        """
        Handles the processing of recipesets into DB entries from their xml
        """
        recipeSet = RecipeSet(ttasks=0)
        recipeset_priority = xmlrecipeSet.get_xml_attr('priority', unicode,
                                                       None)
        if recipeset_priority is not None:
            try:
                my_priority = TaskPriority.from_string(recipeset_priority)
            except InvalidRequestError:
                raise BX(
                    _('You have specified an invalid recipeSet priority:%s' %
                      recipeset_priority))
            allowed_priorities = RecipeSet.allowed_priorities_initial(user)
            if my_priority in allowed_priorities:
                recipeSet.priority = my_priority
            else:
                recipeSet.priority = TaskPriority.default_priority()
        else:
            recipeSet.priority = TaskPriority.default_priority()

        for xmlrecipe in xmlrecipeSet.iter_recipes():
            recipe = self.handleRecipe(
                xmlrecipe, user, ignore_missing_tasks=ignore_missing_tasks)
            recipe.ttasks = len(recipe.tasks)
            recipeSet.ttasks += recipe.ttasks
            recipeSet.recipes.append(recipe)
            # We want the guests to be part of the same recipeSet
            for guest in recipe.guests:
                recipeSet.recipes.append(guest)
                guest.ttasks = len(guest.tasks)
                recipeSet.ttasks += guest.ttasks
        if not recipeSet.recipes:
            raise BX(
                _('No Recipes! You can not have a recipeSet with no recipes!'))
        return recipeSet
Пример #8
0
def _update_recipeset(recipeset, data=None):
    if not data:
        data = {}

    def record_activity(field, old=None, new=None, action=u'Changed'):
        recipeset.record_activity(user=identity.current.user,
                                  service=u'HTTP',
                                  action=action,
                                  field=field,
                                  old=old,
                                  new=new)

    with convert_internal_errors():
        if 'priority' in data:
            priority = TaskPriority.from_string(data['priority'])
            if priority != recipeset.priority:
                if not recipeset.can_change_priority(identity.current.user):
                    raise Forbidden403('Cannot change recipe set %s priority' %
                                       recipeset.id)
                allowed = recipeset.allowed_priorities(identity.current.user)
                if priority not in allowed:
                    raise Forbidden403(
                        'Cannot set recipe set %s priority to %s, '
                        'permitted priorities are: %s' %
                        (recipeset.id, priority, ' '.join(
                            unicode(pri) for pri in allowed)))
                record_activity(u'Priority',
                                old=recipeset.priority.value,
                                new=priority.value)
                recipeset.priority = priority
        if 'waived' in data:
            if not isinstance(data['waived'], bool):
                raise ValueError('waived key must be true or false')
            waived = data['waived']
            if waived != recipeset.waived:
                if not recipeset.can_waive(identity.current.user):
                    raise Forbidden403('Cannot waive recipe set %s' %
                                       recipeset.id)
                record_activity(u'Waived',
                                old=unicode(recipeset.waived),
                                new=unicode(waived))
                recipeset.waived = waived
Пример #9
0
def create_job_for_recipes(recipes,
                           owner=None,
                           whiteboard=None,
                           cc=None,
                           product=None,
                           retention_tag=None,
                           group=None,
                           submitter=None,
                           priority=None,
                           **kwargs):
    if retention_tag is None:
        retention_tag = RetentionTag.by_tag(
            u'scratch')  # Don't use default, unpredictable
    else:
        retention_tag = RetentionTag.by_tag(retention_tag)

    if owner is None:
        owner = create_user()
    if whiteboard is None:
        whiteboard = unique_name(u'job %s')
    job = Job(whiteboard=whiteboard,
              ttasks=sum(r.ttasks for r in recipes),
              owner=owner,
              retention_tag=retention_tag,
              group=group,
              product=product,
              submitter=submitter)
    if cc is not None:
        job.cc = cc
    if priority is None:
        priority = TaskPriority.default_priority()
    recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes),
                           priority=priority)
    recipe_set.recipes.extend(recipes)
    job.recipesets.append(recipe_set)
    session.add(job)
    session.flush()
    log.debug('Created %s', job.t_id)
    return job