Ejemplo n.º 1
0
    def remove_previous_task(self):
        locked_tasks = objects.TaskCollection.filter_by(
            None, cluster_id=self.cluster.id)
        locked_tasks = objects.TaskCollection.filter_by_list(
            locked_tasks,
            'name', (consts.TASK_NAMES.check_networks,
                     consts.TASK_NAMES.verify_networks),
            order_by='id')
        locked_tasks = objects.TaskCollection.lock_for_update(
            locked_tasks).all()

        check_networks = objects.TaskCollection.filter_by(
            locked_tasks, name=consts.TASK_NAMES.check_networks)
        check_networks = list(check_networks)

        if check_networks:
            db().delete(check_networks[0])
            db().flush()

        verification_tasks = objects.TaskCollection.filter_by(
            locked_tasks, name=consts.TASK_NAMES.verify_networks)
        verification_tasks = list(verification_tasks)

        # TODO(pkaminski): this code shouldn't be required at all
        if verification_tasks:
            ver_task = verification_tasks[0]
            if ver_task.status == consts.TASK_STATUSES.running:
                raise errors.CantRemoveOldVerificationTask()
            for subtask in ver_task.subtasks:
                db().delete(subtask)
            db().delete(ver_task)
            db().flush()
Ejemplo n.º 2
0
 def remove_previous_task(self):
     verification_tasks = filter(
         lambda task: task.cluster_id == self.cluster.id and task.name ==
         "verify_networks", self.cluster.tasks)
     if verification_tasks:
         ver_task = verification_tasks[0]
         if ver_task.status == "running":
             raise errors.CantRemoveOldVerificationTask()
         for subtask in ver_task.subtasks:
             db().delete(subtask)
         db().delete(ver_task)
         db().commit()
Ejemplo n.º 3
0
    def remove_previous_task(self):
        check_networks = db().query(Task).filter_by(
            cluster=self.cluster, name="check_networks").first()
        if check_networks:
            db().delete(check_networks)
            db().commit()

        verification_tasks = db().query(Task).filter_by(
            cluster=self.cluster, name="verify_networks").all()
        if verification_tasks:
            ver_task = verification_tasks[0]
            if ver_task.status == "running":
                raise errors.CantRemoveOldVerificationTask()
            for subtask in ver_task.subtasks:
                db().delete(subtask)
            db().delete(ver_task)
            db().commit()