Merge "Add bay status check when rc create."

This commit is contained in:
Jenkins 2015-04-20 14:29:35 +00:00 committed by Gerrit Code Review
commit 622480a31a
3 changed files with 29 additions and 0 deletions

View File

@ -423,6 +423,10 @@ class TestCommandLineArgument(utils.TestCase):
@mock.patch('magnumclient.v1.replicationcontrollers.'
'ReplicationControllerManager.create')
def test_rc_create_success(self, mock_create, mock_get):
mockbay = mock.MagicMock()
mockbay.status = "CREATE_COMPLETE"
mock_get.return_value = mockbay
self._test_arg_success('rc-create '
'--bay xxx '
'--manifest test '

View File

@ -263,6 +263,7 @@ class ShellTest(base.TestCase):
client_mock = mock.MagicMock()
bay = mock.MagicMock()
bay.uuid = 'uuid'
bay.status = 'CREATE_COMPLETE'
client_mock.bays.get.return_value = bay
args = mock.MagicMock()
@ -277,6 +278,24 @@ class ShellTest(base.TestCase):
client_mock.rcs.create.assert_called_once_with(
manifest_url=manifest_url, bay_uuid=bay.uuid)
def test_do_rc_create_with_bay_status_wrong(self):
client_mock = mock.MagicMock()
bay = mock.MagicMock()
bay.uuid = 'uuid'
bay.status = 'XXX'
client_mock.bays.get.return_value = bay
args = mock.MagicMock()
manifest_url = "test_url"
args.manifest_url = manifest_url
bay_id_or_name = "xxx"
args.bay_id = bay_id_or_name
manifest = "test_manifest"
args.manifest = manifest
shell.do_rc_create(client_mock, args)
self.assertFalse(client_mock.rcs.create.called)
def test_do_rc_update(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()

View File

@ -359,6 +359,12 @@ def do_rc_list(cs, args):
def do_rc_create(cs, args):
"""Create a replication controller."""
bay = cs.bays.get(args.bay)
if bay.status not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']:
print('Bay status for %s is: %s. We can not create a '
'replication controller in bay until the status '
'is CREATE_COMPLETE or UPDATE_COMPLETE.' %
(args.bay, bay.status))
return
opts = {}
opts['manifest_url'] = args.manifest_url