From 32da111c1757a884466814ac000fb7e662e6da42 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Sat, 7 May 2016 16:21:06 +0800 Subject: [PATCH] Implement "address scope show" command This patch add a command that supports showing address scope details Change-Id: Ic0b41c1cab8c618904c7a6046d7493db5b74b430 Partial-Bug: #1566269 --- doc/source/command-objects/address-scope.rst | 16 ++++++ openstackclient/network/v2/address_scope.py | 24 +++++++++ .../tests/network/v2/test_address_scope.py | 53 +++++++++++++++++++ setup.cfg | 1 + 4 files changed, 94 insertions(+) diff --git a/doc/source/command-objects/address-scope.rst b/doc/source/command-objects/address-scope.rst index 2c701a4941..f37bc321a0 100644 --- a/doc/source/command-objects/address-scope.rst +++ b/doc/source/command-objects/address-scope.rst @@ -72,3 +72,19 @@ List address scopes .. code:: bash os address scope list + +address scope show +------------------ + +Display address scope details + +.. program:: address scope show +.. code:: bash + + os address scope show + + +.. _address_scope_show-address-scope: +.. describe:: + + Address scope to display (name or ID) diff --git a/openstackclient/network/v2/address_scope.py b/openstackclient/network/v2/address_scope.py index dd43ef5b21..86f39c3477 100644 --- a/openstackclient/network/v2/address_scope.py +++ b/openstackclient/network/v2/address_scope.py @@ -140,3 +140,27 @@ class ListAddressScope(command.Lister): (utils.get_item_properties( s, columns, formatters={}, ) for s in data)) + + +class ShowAddressScope(command.ShowOne): + """Display address scope details""" + + def get_parser(self, prog_name): + parser = super(ShowAddressScope, self).get_parser(prog_name) + parser.add_argument( + 'address_scope', + metavar="", + help=_("Address scope to display (name or ID)") + ) + + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + obj = client.find_address_scope( + parsed_args.address_scope, + ignore_missing=False) + columns = _get_columns(obj) + data = utils.get_item_properties(obj, columns, formatters={}) + + return columns, data diff --git a/openstackclient/tests/network/v2/test_address_scope.py b/openstackclient/tests/network/v2/test_address_scope.py index d33013ce9a..da658fefb1 100644 --- a/openstackclient/tests/network/v2/test_address_scope.py +++ b/openstackclient/tests/network/v2/test_address_scope.py @@ -235,3 +235,56 @@ class TestListAddressScope(TestAddressScope): self.network.address_scopes.assert_called_once_with(**{}) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + + +class TestShowAddressScope(TestAddressScope): + + # The address scope to show. + _address_scope = ( + network_fakes.FakeAddressScope.create_one_address_scope()) + columns = ( + 'id', + 'ip_version', + 'name', + 'project_id', + 'shared', + ) + data = ( + _address_scope.id, + _address_scope.ip_version, + _address_scope.name, + _address_scope.project_id, + _address_scope.shared, + ) + + def setUp(self): + super(TestShowAddressScope, self).setUp() + self.network.find_address_scope = mock.Mock( + return_value=self._address_scope) + + # Get the command object to test + self.cmd = address_scope.ShowAddressScope(self.app, self.namespace) + + def test_show_no_options(self): + arglist = [] + verifylist = [] + + # Missing required args should bail here + self.assertRaises(tests_utils.ParserException, self.check_parser, + self.cmd, arglist, verifylist) + + def test_show_all_options(self): + arglist = [ + self._address_scope.name, + ] + verifylist = [ + ('address_scope', self._address_scope.name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.find_address_scope.assert_called_once_with( + self._address_scope.name, ignore_missing=False) + self.assertEqual(self.columns, columns) + self.assertEqual(list(self.data), list(data)) diff --git a/setup.cfg b/setup.cfg index 18f177dc48..3c8c829040 100644 --- a/setup.cfg +++ b/setup.cfg @@ -322,6 +322,7 @@ openstack.network.v2 = address_scope_create = openstackclient.network.v2.address_scope:CreateAddressScope address_scope_delete = openstackclient.network.v2.address_scope:DeleteAddressScope address_scope_list = openstackclient.network.v2.address_scope:ListAddressScope + address_scope_show = openstackclient.network.v2.address_scope:ShowAddressScope ip_floating_create = openstackclient.network.v2.floating_ip:CreateFloatingIP ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP