From 7369321d47fb15c4a06a552b86005f2c3aa139b6 Mon Sep 17 00:00:00 2001 From: Fang Fenghua <449171342@qq.com> Date: Fri, 17 Apr 2015 12:42:55 +0000 Subject: [PATCH] Add bay status check when rc create. Now when we create rc,we didn't check the bay status it require.It may cause some strange error. Change-Id: I9bd043782be8c7370a118d3e059bbe9c078150cf Closes-bug:#1445410 --- magnumclient/tests/test_shell_args.py | 4 ++++ magnumclient/tests/v1/test_shell.py | 19 +++++++++++++++++++ magnumclient/v1/shell.py | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/magnumclient/tests/test_shell_args.py b/magnumclient/tests/test_shell_args.py index 82b80307..803b0a62 100644 --- a/magnumclient/tests/test_shell_args.py +++ b/magnumclient/tests/test_shell_args.py @@ -420,6 +420,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 ' diff --git a/magnumclient/tests/v1/test_shell.py b/magnumclient/tests/v1/test_shell.py index 287a1cf3..1836a136 100644 --- a/magnumclient/tests/v1/test_shell.py +++ b/magnumclient/tests/v1/test_shell.py @@ -244,6 +244,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() @@ -258,6 +259,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() diff --git a/magnumclient/v1/shell.py b/magnumclient/v1/shell.py index 2bb20aea..58da42f5 100644 --- a/magnumclient/v1/shell.py +++ b/magnumclient/v1/shell.py @@ -355,6 +355,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