From 479ad147277c74b9bf68d9a6c6ccb9430241a816 Mon Sep 17 00:00:00 2001 From: Vipul Nayyar Date: Thu, 14 Jul 2016 13:13:20 +0530 Subject: [PATCH] Display baymodel info with bay-show command Adds --long parameter to the sub command bay-show to list associated baymodel metadata Implements: blueprint bay-metadata Change-Id: Ib1236b96d1da8c3afb6d46815a93c6160e6c180c --- magnumclient/tests/v1/test_bays_shell.py | 12 ++++++++++++ magnumclient/v1/bays_shell.py | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/magnumclient/tests/v1/test_bays_shell.py b/magnumclient/tests/v1/test_bays_shell.py index ad1c5114..7a676405 100644 --- a/magnumclient/tests/v1/test_bays_shell.py +++ b/magnumclient/tests/v1/test_bays_shell.py @@ -16,6 +16,7 @@ import mock from magnumclient import exceptions from magnumclient.tests.v1 import shell_test_base +from magnumclient.tests.v1 import test_baymodels_shell from magnumclient.v1.bays import Bay @@ -113,6 +114,17 @@ class ShellTest(shell_test_base.TestCommandLineArgument): '--timeout 15') self.assertTrue(mock_create.called) + @mock.patch('magnumclient.v1.baymodels.BayModelManager.get') + @mock.patch('magnumclient.v1.bays.BayManager.get') + def test_bay_show_baymodel_metadata(self, mock_bay, mock_baymodel): + mock_bay.return_value = FakeBay(info={'links': 0, 'baymodel_id': 0}) + mock_baymodel.return_value = test_baymodels_shell.FakeBayModel( + info={'links': 0, 'uuid': 0, 'id': 0, 'name': ''}) + + self._test_arg_success('bay-show --long x', 'baymodel_name') + self.assertTrue(mock_bay.called) + self.assertTrue(mock_baymodel.called) + @mock.patch('magnumclient.v1.baymodels.BayModelManager.get') @mock.patch('magnumclient.v1.bays.BayManager.create') def test_bay_create_success_only_baymodel_arg(self, mock_create, mock_get): diff --git a/magnumclient/v1/bays_shell.py b/magnumclient/v1/bays_shell.py index 32b3b4a2..3e18a810 100644 --- a/magnumclient/v1/bays_shell.py +++ b/magnumclient/v1/bays_shell.py @@ -124,9 +124,19 @@ def do_bay_delete(cs, args): @utils.arg('bay', metavar='', help='ID or name of the bay to show.') +@utils.arg('--long', + action='store_true', default=False, + help='Display extra associated Baymodel info.') def do_bay_show(cs, args): """Show details about the given bay.""" bay = cs.bays.get(args.bay) + if args.long: + baymodel = cs.baymodels.get(bay.baymodel_id) + del baymodel._info['links'], baymodel._info['uuid'] + + for key in baymodel._info: + if 'baymodel_' + key not in bay._info: + bay._info['baymodel_' + key] = baymodel._info[key] _show_bay(bay)