diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index ed25117317..a634378f63 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -316,7 +316,7 @@ class SetNetwork(command.Command): return -class ShowNetwork(command.ShowOne): +class ShowNetwork(common.NetworkAndComputeShowOne): """Show network details""" def get_parser(self, prog_name): @@ -328,9 +328,17 @@ class ShowNetwork(command.ShowOne): ) return parser - def take_action(self, parsed_args): - client = self.app.client_manager.network + def take_action_network(self, client, parsed_args): obj = client.find_network(parsed_args.network, ignore_missing=False) columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (columns, data) + + def take_action_compute(self, client, parsed_args): + network = utils.find_resource( + client.networks, + parsed_args.network, + ) + columns = sorted(network._info.keys()) + data = utils.get_dict_properties(network._info, columns) + return (columns, data) diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 66e488b79b..a4d99ca228 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -539,13 +539,42 @@ class FakeNetwork(object): :param Dictionary methods: A dictionary with all methods :return: - A FakeResource object, with id, label, cidr + A FakeResource object, with id, label, cidr and so on """ # Set default attributes. network_attrs = { - 'id': 'network-id-' + uuid.uuid4().hex, - 'label': 'network-label-' + uuid.uuid4().hex, + 'bridge': 'br100', + 'bridge_interface': None, + 'broadcast': '10.0.0.255', 'cidr': '10.0.0.0/24', + 'cidr_v6': None, + 'created_at': '2016-02-11T11:17:37.000000', + 'deleted': False, + 'deleted_at': None, + 'dhcp_server': '10.0.0.1', + 'dhcp_start': '10.0.0.2', + 'dns1': '8.8.4.4', + 'dns2': None, + 'enable_dhcp': True, + 'gateway': '10.0.0.1', + 'gateway_v6': None, + 'host': None, + 'id': 'network-id-' + uuid.uuid4().hex, + 'injected': False, + 'label': 'network-label-' + uuid.uuid4().hex, + 'mtu': None, + 'multi_host': False, + 'netmask': '255.255.255.0', + 'netmask_v6': None, + 'priority': None, + 'project_id': 'project-id-' + uuid.uuid4().hex, + 'rxtx_base': None, + 'share_address': False, + 'updated_at': None, + 'vlan': None, + 'vpn_private_address': None, + 'vpn_public_address': None, + 'vpn_public_port': None, } # Overwrite default attributes. diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py index c83e7e8447..26a9da40d5 100644 --- a/openstackclient/tests/network/v2/test_network.py +++ b/openstackclient/tests/network/v2/test_network.py @@ -654,3 +654,112 @@ class TestListNetworkCompute(TestNetworkCompute): self.compute.networks.list.assert_called_with() self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + + +class TestShowNetworkCompute(TestNetworkCompute): + + # The network to show. + _network = compute_fakes.FakeNetwork.create_one_network() + + columns = ( + 'bridge', + 'bridge_interface', + 'broadcast', + 'cidr', + 'cidr_v6', + 'created_at', + 'deleted', + 'deleted_at', + 'dhcp_server', + 'dhcp_start', + 'dns1', + 'dns2', + 'enable_dhcp', + 'gateway', + 'gateway_v6', + 'host', + 'id', + 'injected', + 'label', + 'mtu', + 'multi_host', + 'netmask', + 'netmask_v6', + 'priority', + 'project_id', + 'rxtx_base', + 'share_address', + 'updated_at', + 'vlan', + 'vpn_private_address', + 'vpn_public_address', + 'vpn_public_port', + ) + + data = ( + _network.bridge, + _network.bridge_interface, + _network.broadcast, + _network.cidr, + _network.cidr_v6, + _network.created_at, + _network.deleted, + _network.deleted_at, + _network.dhcp_server, + _network.dhcp_start, + _network.dns1, + _network.dns2, + _network.enable_dhcp, + _network.gateway, + _network.gateway_v6, + _network.host, + _network.id, + _network.injected, + _network.label, + _network.mtu, + _network.multi_host, + _network.netmask, + _network.netmask_v6, + _network.priority, + _network.project_id, + _network.rxtx_base, + _network.share_address, + _network.updated_at, + _network.vlan, + _network.vpn_private_address, + _network.vpn_public_address, + _network.vpn_public_port, + ) + + def setUp(self): + super(TestShowNetworkCompute, self).setUp() + + self.app.client_manager.network_endpoint_enabled = False + + # Return value of utils.find_resource() + self.compute.networks.get.return_value = self._network + + # Get the command object to test + self.cmd = network.ShowNetwork(self.app, None) + + 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._network.label, + ] + verifylist = [ + ('network', self._network.label), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.assertEqual(self.columns, tuple(columns)) + self.assertEqual(self.data, data) diff --git a/releasenotes/notes/bug-1543672-bad2fc4c6c8f3125.yaml b/releasenotes/notes/bug-1543672-bad2fc4c6c8f3125.yaml index 9cecc06039..ad4d5f5685 100644 --- a/releasenotes/notes/bug-1543672-bad2fc4c6c8f3125.yaml +++ b/releasenotes/notes/bug-1543672-bad2fc4c6c8f3125.yaml @@ -4,3 +4,5 @@ features: [Bug `1543672 `_] - Command ``network list`` is now available for nova network. [Bug `1543672 `_] + - Command ``network show`` is now available for nova network. + [Bug `1543672 `_]