From a55aaa77807dae816299d33d75d2a9b6394716ac Mon Sep 17 00:00:00 2001 From: Motohiro OTSUKA Date: Fri, 27 Mar 2015 16:44:43 +0900 Subject: [PATCH] Allow bay name when replication controller is created Replication controller needs bay id when replication controller is created. But usually, user want to use `bay name` instead of bay id. This patch supports bay name when replication controller is created. Partially implements blueprint name-based-resource-management Change-Id: I63e1f98407221ee7cea7c8432e47702fd3850fea --- magnumclient/tests/test_shell.py | 2 +- magnumclient/tests/test_shell_args.py | 10 ++++++---- magnumclient/tests/v1/test_shell.py | 10 +++++++--- magnumclient/v1/shell.py | 10 ++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/magnumclient/tests/test_shell.py b/magnumclient/tests/test_shell.py index 8790e7e5..75ef52c4 100644 --- a/magnumclient/tests/test_shell.py +++ b/magnumclient/tests/test_shell.py @@ -119,7 +119,7 @@ class ShellTest(utils.TestCase): '.*--json', '.*help', '.*bay-show', - '.*--bay-id'] + '.*--bay'] for r in required: self.assertThat((stdout + stderr), matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) diff --git a/magnumclient/tests/test_shell_args.py b/magnumclient/tests/test_shell_args.py index a1e00182..0ec0c4f3 100644 --- a/magnumclient/tests/test_shell_args.py +++ b/magnumclient/tests/test_shell_args.py @@ -399,18 +399,20 @@ class TestCommandLineArgument(utils.TestCase): self._unrecognized_arg_error) self.assertFalse(mock_list.called) + @mock.patch('magnumclient.v1.bays.BayManager.get') @mock.patch('magnumclient.v1.replicationcontrollers.' 'ReplicationControllerManager.create') - def test_rc_create_success(self, mock_create): + def test_rc_create_success(self, mock_create, mock_get): self._test_arg_success('rc-create ' - '--bay-id xxx ' + '--bay xxx ' '--manifest test ' '--manifest-url test_url') self.assertTrue(mock_create.called) + @mock.patch('magnumclient.v1.bays.BayManager.get') @mock.patch('magnumclient.v1.replicationcontrollers.' 'ReplicationControllerManager.create') - def test_rc_create_failure_few_arg(self, mock_create): + def test_rc_create_failure_few_arg(self, mock_create, mock_get): self._test_arg_failure('rc-create ' '--manifest test ' '--manifest-url test_url', @@ -418,7 +420,7 @@ class TestCommandLineArgument(utils.TestCase): self.assertFalse(mock_create.called) self._test_arg_failure('rc-create ' - 'bay-id xxx ' + 'bay xxx ' '--manifest-url test_url', self._mandatory_arg_error) self.assertFalse(mock_create.called) diff --git a/magnumclient/tests/v1/test_shell.py b/magnumclient/tests/v1/test_shell.py index d65c2baa..660e545f 100644 --- a/magnumclient/tests/v1/test_shell.py +++ b/magnumclient/tests/v1/test_shell.py @@ -195,17 +195,21 @@ class ShellTest(base.TestCase): def test_do_rc_create(self): client_mock = mock.MagicMock() + bay = mock.MagicMock() + bay.uuid = 'uuid' + client_mock.bays.get.return_value = bay + args = mock.MagicMock() manifest_url = "test_url" args.manifest_url = manifest_url - bay_id = "xxx" - args.bay_id = bay_id + 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) client_mock.rcs.create.assert_called_once_with( - manifest_url=manifest_url, bay_uuid=bay_id) + manifest_url=manifest_url, bay_uuid=bay.uuid) def test_do_rc_delete(self): client_mock = mock.MagicMock() diff --git a/magnumclient/v1/shell.py b/magnumclient/v1/shell.py index 4c110aaa..9ea6629a 100644 --- a/magnumclient/v1/shell.py +++ b/magnumclient/v1/shell.py @@ -314,15 +314,17 @@ def do_rc_list(cs, args): metavar='', help='File path of the replication controller file to use for ' 'creating replication controllers.') -@utils.arg('--bay-id', +@utils.arg('--bay', required=True, - metavar='', - help='The bay ID.') + metavar='', + help='ID or name of the bay.') def do_rc_create(cs, args): """Create a replication controller.""" + bay = cs.bays.get(args.bay) + opts = {} opts['manifest_url'] = args.manifest_url - opts['bay_uuid'] = args.bay_id + opts['bay_uuid'] = bay.uuid if args.manifest is not None and os.path.isfile(args.manifest): with open(args.manifest, 'r') as f: