Sync bay status reason in periodic task

In periodic task, when bay status is found to be different with
corresponding stack, or the corresponding stack cannot be found in
heat, status reason should be synced as well as status. Otherwise,
status reason will be meaningless in some situation.

Change-Id: I27d6a7ecb0c74bd4d4a2bb2bfcd81d7632cd2147
Closes-Bug: #1488709
This commit is contained in:
mathspanda 2015-08-27 21:57:31 +08:00
parent 31974f2023
commit 235877bebc
2 changed files with 16 additions and 2 deletions

View File

@ -23,6 +23,7 @@ from oslo_service import threadgroup
from magnum.common import clients from magnum.common import clients
from magnum.common import context from magnum.common import context
from magnum.common import exception from magnum.common import exception
from magnum.i18n import _
from magnum.i18n import _LI from magnum.i18n import _LI
from magnum.i18n import _LW from magnum.i18n import _LW
from magnum import objects from magnum import objects
@ -74,6 +75,7 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
if bay.status != stack.stack_status: if bay.status != stack.stack_status:
old_status = bay.status old_status = bay.status
bay.status = stack.stack_status bay.status = stack.stack_status
bay.status_reason = stack.stack_status_reason
bay.save() bay.save()
LOG.info(_LI("Sync up bay with id %(id)s from " LOG.info(_LI("Sync up bay with id %(id)s from "
"%(old_status)s to %(status)s."), "%(old_status)s to %(status)s."),
@ -95,6 +97,8 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
{'id': bay.id, 'sid': sid}) {'id': bay.id, 'sid': sid})
elif bay.status == bay_status.CREATE_IN_PROGRESS: elif bay.status == bay_status.CREATE_IN_PROGRESS:
bay.status = bay_status.CREATE_FAILED bay.status = bay_status.CREATE_FAILED
bay.status_reason = _("Stack with id %s not found in "
"Heat.") % sid
bay.save() bay.save()
LOG.info(_LI("Bay with id %(id)s has been set to " LOG.info(_LI("Bay with id %(id)s has been set to "
"%(status)s due to stack with id %(sid)s " "%(status)s due to stack with id %(sid)s "
@ -103,6 +107,8 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
'sid': sid}) 'sid': sid})
elif bay.status == bay_status.UPDATE_IN_PROGRESS: elif bay.status == bay_status.UPDATE_IN_PROGRESS:
bay.status = bay_status.UPDATE_FAILED bay.status = bay_status.UPDATE_FAILED
bay.status_reason = _("Stack with id %s not found in "
"Heat.") % sid
bay.save() bay.save()
LOG.info(_LI("Bay with id %(id)s has been set to " LOG.info(_LI("Bay with id %(id)s has been set to "
"%(status)s due to stack with id %(sid)s " "%(status)s due to stack with id %(sid)s "

View File

@ -67,8 +67,10 @@ class PeriodicTestCase(base.TestCase):
def test_sync_bay_status_changes(self, mock_db_update, mock_db_destroy, def test_sync_bay_status_changes(self, mock_db_update, mock_db_destroy,
mock_oscc, mock_bay_list): mock_oscc, mock_bay_list):
mock_heat_client = mock.MagicMock() mock_heat_client = mock.MagicMock()
stack1 = fake_stack(id='11', stack_status=bay_status.CREATE_COMPLETE) stack1 = fake_stack(id='11', stack_status=bay_status.CREATE_COMPLETE,
stack3 = fake_stack(id='33', stack_status=bay_status.UPDATE_COMPLETE) stack_status_reason='fake_reason_11')
stack3 = fake_stack(id='33', stack_status=bay_status.UPDATE_COMPLETE,
stack_status_reason='fake_reason_33')
mock_heat_client.stacks.list.return_value = [stack1, stack3] mock_heat_client.stacks.list.return_value = [stack1, stack3]
mock_osc = mock_oscc.return_value mock_osc = mock_oscc.return_value
mock_osc.heat.return_value = mock_heat_client mock_osc.heat.return_value = mock_heat_client
@ -81,8 +83,10 @@ class PeriodicTestCase(base.TestCase):
periodic.MagnumPeriodicTasks(CONF).sync_bay_status(None) periodic.MagnumPeriodicTasks(CONF).sync_bay_status(None)
self.assertEqual(self.bay1.status, bay_status.CREATE_COMPLETE) self.assertEqual(self.bay1.status, bay_status.CREATE_COMPLETE)
self.assertEqual(self.bay1.status_reason, 'fake_reason_11')
mock_db_destroy.assert_called_once_with(self.bay2.uuid) mock_db_destroy.assert_called_once_with(self.bay2.uuid)
self.assertEqual(self.bay3.status, bay_status.UPDATE_COMPLETE) self.assertEqual(self.bay3.status, bay_status.UPDATE_COMPLETE)
self.assertEqual(self.bay3.status_reason, 'fake_reason_33')
@mock.patch.object(objects.Bay, 'list_all') @mock.patch.object(objects.Bay, 'list_all')
@mock.patch('magnum.common.clients.OpenStackClients') @mock.patch('magnum.common.clients.OpenStackClients')
@ -124,5 +128,9 @@ class PeriodicTestCase(base.TestCase):
periodic.MagnumPeriodicTasks(CONF).sync_bay_status(None) periodic.MagnumPeriodicTasks(CONF).sync_bay_status(None)
self.assertEqual(self.bay1.status, bay_status.CREATE_FAILED) self.assertEqual(self.bay1.status, bay_status.CREATE_FAILED)
self.assertEqual(self.bay1.status_reason, 'Stack with id 11 not '
'found in Heat.')
mock_db_destroy.assert_called_once_with(self.bay2.uuid) mock_db_destroy.assert_called_once_with(self.bay2.uuid)
self.assertEqual(self.bay3.status, bay_status.UPDATE_FAILED) self.assertEqual(self.bay3.status, bay_status.UPDATE_FAILED)
self.assertEqual(self.bay3.status_reason, 'Stack with id 33 not '
'found in Heat.')