Add more types of status to Bay's status

Added more types of status which can be updated to Bay's status field:
'RESUME_COMPLETE'
'RESTORE_COMPLETE'
'ROLLBACK_COMPLETE'
'SNAPSHOT_COMPLETE'
'CHECK_COMPLETE'
Added these states so that the bay_update code have better resiliency
If the user operates the stack,he(she) could still update the bay.

Change-Id: Ia71ca90742a7e23bbf2c0c9254951db7e06faf28
Closes-Bug: #1538447
This commit is contained in:
space 2016-01-27 17:50:04 +08:00
parent 98cb7fb229
commit 36a6fde15a
6 changed files with 78 additions and 6 deletions

View File

@ -175,8 +175,17 @@ class Handler(object):
osc = clients.OpenStackClients(context)
stack = osc.heat().stacks.get(bay.stack_id)
if (stack.stack_status != bay_status.CREATE_COMPLETE and
stack.stack_status != bay_status.UPDATE_COMPLETE):
allow_update_status = (
bay_status.CREATE_COMPLETE,
bay_status.UPDATE_COMPLETE,
bay_status.RESUME_COMPLETE,
bay_status.RESTORE_COMPLETE,
bay_status.ROLLBACK_COMPLETE,
bay_status.SNAPSHOT_COMPLETE,
bay_status.CHECK_COMPLETE,
bay_status.ADOPT_COMPLETE
)
if stack.stack_status not in allow_update_status:
operation = _('Updating a bay when stack status is '
'"%s"') % stack.stack_status
raise exception.NotSupported(operation=operation)

View File

@ -30,7 +30,8 @@ class Bay(base.MagnumPersistentObject, base.MagnumObject,
# Version 1.1: Added 'bay_create_timeout' field
# Version 1.2: Add 'registry_trust_id' field
# Version 1.3: Added 'baymodel' field
VERSION = '1.3'
# Version 1.4: Added more types of status to bay's status field
VERSION = '1.4'
dbapi = dbapi.get_instance()

View File

@ -25,10 +25,18 @@ class BayStatus(fields.Enum):
DELETE_IN_PROGRESS = 'DELETE_IN_PROGRESS'
DELETE_FAILED = 'DELETE_FAILED'
DELETE_COMPLETE = 'DELETE_COMPLETE'
RESUME_COMPLETE = 'RESUME_COMPLETE'
RESTORE_COMPLETE = 'RESTORE_COMPLETE'
ROLLBACK_COMPLETE = 'ROLLBACK_COMPLETE'
SNAPSHOT_COMPLETE = 'SNAPSHOT_COMPLETE'
CHECK_COMPLETE = 'CHECK_COMPLETE'
ADOPT_COMPLETE = 'ADOPT_COMPLETE'
ALL = (CREATE_IN_PROGRESS, CREATE_FAILED, CREATE_COMPLETE,
UPDATE_IN_PROGRESS, UPDATE_FAILED, UPDATE_COMPLETE,
DELETE_IN_PROGRESS, DELETE_FAILED, DELETE_COMPLETE)
DELETE_IN_PROGRESS, DELETE_FAILED, DELETE_COMPLETE,
RESUME_COMPLETE, RESTORE_COMPLETE, ROLLBACK_COMPLETE,
SNAPSHOT_COMPLETE, CHECK_COMPLETE, ADOPT_COMPLETE)
def __init__(self):
super(BayStatus, self).__init__(valid_values=BayStatus.ALL)

View File

@ -97,6 +97,55 @@ class TestHandler(db_base.DbTestCase):
bay = objects.Bay.get(self.context, self.bay.uuid)
self.assertEqual(1, bay.node_count)
@patch('magnum.conductor.scale_manager.ScaleManager')
@patch('magnum.conductor.handlers.bay_conductor.Handler._poll_and_check')
@patch('magnum.conductor.handlers.bay_conductor._update_stack')
@patch('magnum.common.clients.OpenStackClients')
def _test_update_bay_status_complete(
self, expect_status, mock_openstack_client_class,
mock_update_stack, mock_poll_and_check,
mock_scale_manager):
def side_effect(*args, **kwargs):
self.bay.node_count = 2
self.bay.save()
mock_poll_and_check.side_effect = side_effect
mock_heat_stack = mock.MagicMock()
mock_heat_stack.stack_status = expect_status
mock_heat_client = mock.MagicMock()
mock_heat_client.stacks.get.return_value = mock_heat_stack
mock_openstack_client = mock_openstack_client_class.return_value
mock_openstack_client.heat.return_value = mock_heat_client
self.bay.node_count = 2
self.handler.bay_update(self.context, self.bay)
mock_update_stack.assert_called_once_with(
self.context, mock_openstack_client, self.bay,
mock_scale_manager.return_value)
bay = objects.Bay.get(self.context, self.bay.uuid)
self.assertEqual(2, bay.node_count)
def test_update_bay_status_update_compelete(self):
self._test_update_bay_status_complete(bay_status.UPDATE_COMPLETE)
def test_update_bay_status_resume_compelete(self):
self._test_update_bay_status_complete(bay_status.RESUME_COMPLETE)
def test_update_bay_status_restore_compelete(self):
self._test_update_bay_status_complete(bay_status.RESTORE_COMPLETE)
def test_update_bay_status_rollback_compelete(self):
self._test_update_bay_status_complete(bay_status.ROLLBACK_COMPLETE)
def test_update_bay_status_snapshot_compelete(self):
self._test_update_bay_status_complete(bay_status.SNAPSHOT_COMPLETE)
def test_update_bay_status_check_compelete(self):
self._test_update_bay_status_complete(bay_status.CHECK_COMPLETE)
def test_update_bay_status_adopt_compelete(self):
self._test_update_bay_status_complete(bay_status.ADOPT_COMPLETE)
@patch('magnum.common.clients.OpenStackClients')
def test_update_bay_with_invalid_params(
self, mock_openstack_client_class):

View File

@ -32,7 +32,12 @@ class TestBayStatus(test_fields.TestField):
('DELETE_IN_PROGRESS',
'DELETE_IN_PROGRESS'),
('DELETE_FAILED', 'DELETE_FAILED'),
('DELETE_COMPLETE', 'DELETE_COMPLETE'), ]
('RESUME_COMPLETE', 'RESUME_COMPLETE'),
('RESTORE_COMPLETE', 'RESTORE_COMPLETE'),
('ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'),
('SNAPSHOT_COMPLETE', 'SNAPSHOT_COMPLETE'),
('CHECK_COMPLETE', 'CHECK_COMPLETE'),
('ADOPT_COMPLETE', 'ADOPT_COMPLETE')]
self.coerce_bad_values = ['DELETE_STOPPED']
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]

View File

@ -423,7 +423,7 @@ class _TestObject(object):
# For more information on object version testing, read
# http://docs.openstack.org/developer/magnum/objects.html
object_data = {
'Bay': '1.3-5c09d266a4f21301b3243848d4c09a90',
'Bay': '1.4-ca3c05dc1b27b2e50c082bb2a1a64151',
'BayModel': '1.9-d5d32553721d0cadfcc45ddc316d9c1a',
'Certificate': '1.0-2aff667971b85c1edf8d15684fd7d5e2',
'Container': '1.3-e2d9d2e8a8844d421148cd9fde6c6bd6',