Fixed update cluster status on task deletion
Also fixed deletion subtasks with when parent is deleted
Change-Id: I53c1fdd95380602d0ee3888f3c3d2ddc0212e695
Closes-Bug: 1570853
Closes-Bug: 1570762
(cherry picked from commit c29a1ca8f9
)
This commit is contained in:
parent
a744d69c50
commit
a322c0bdef
|
@ -297,14 +297,16 @@ class Task(NailgunObject):
|
|||
super(Task, cls).update(instance, clean_data)
|
||||
db().flush()
|
||||
|
||||
if instance.cluster_id:
|
||||
# update cluster only if task status was updated
|
||||
if instance.cluster_id and 'status' in clean_data:
|
||||
logger.debug("Updating cluster status: %s "
|
||||
"cluster_id: %s status: %s",
|
||||
instance.uuid, instance.cluster_id,
|
||||
data.get('status'))
|
||||
cls._update_cluster_data(instance)
|
||||
|
||||
if instance.parent:
|
||||
if instance.parent and \
|
||||
{'status', 'message', 'progress'}.intersection(clean_data):
|
||||
logger.debug("Updating parent task: %s.", instance.parent.uuid)
|
||||
cls._update_parent_instance(instance.parent)
|
||||
|
||||
|
@ -312,6 +314,8 @@ class Task(NailgunObject):
|
|||
def delete(cls, instance):
|
||||
logger.debug("Mark task as deleted: %s", instance.uuid)
|
||||
cls.update(instance, {'deleted_at': datetime.utcnow()})
|
||||
for t in instance.subtasks:
|
||||
cls.delete(t)
|
||||
|
||||
@classmethod
|
||||
def bulk_delete(cls, instance_ids):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
from nailgun import consts
|
||||
from nailgun.db.sqlalchemy.models import Task
|
||||
from nailgun.test.base import BaseTestCase
|
||||
from nailgun.test.base import fake_tasks
|
||||
from nailgun.utils import reverse
|
||||
|
||||
|
||||
|
@ -131,3 +132,35 @@ class TestTaskHandlers(BaseTestCase):
|
|||
)
|
||||
self.assertEqual(resp.status_code, 404)
|
||||
self.assertTrue(self.db().query(Task).get(task.id))
|
||||
|
||||
@fake_tasks()
|
||||
def test_delete_task_does_not_affect_cluster_status(self):
|
||||
self.env.create(
|
||||
nodes_kwargs=[
|
||||
{'roles': ['controller'],
|
||||
'status': consts.NODE_STATUSES.discover,
|
||||
'pending_addition': True}],
|
||||
release_kwargs={
|
||||
'operating_system': consts.RELEASE_OS.ubuntu,
|
||||
'version': 'mitaka-9.0'
|
||||
}
|
||||
)
|
||||
cluster = self.env.clusters[-1]
|
||||
supertask = self.env.launch_deployment(cluster_id=cluster.id)
|
||||
self.db.refresh(cluster)
|
||||
self.assertEqual(consts.CLUSTER_STATUSES.operational, cluster.status)
|
||||
resp = self.app.delete(
|
||||
reverse(
|
||||
'TaskHandler',
|
||||
kwargs={'obj_id': supertask.id}
|
||||
),
|
||||
headers=self.default_headers,
|
||||
expect_errors=True
|
||||
)
|
||||
self.assertEqual(204, resp.status_code)
|
||||
self.db.refresh(supertask)
|
||||
self.assertIsNotNone(supertask.deleted_at)
|
||||
for t in supertask.subtasks:
|
||||
self.assertIsNotNone(t.deleted_at)
|
||||
self.db.refresh(cluster)
|
||||
self.assertEqual(consts.CLUSTER_STATUSES.operational, cluster.status)
|
||||
|
|
Loading…
Reference in New Issue