Skip to content

Commit 832b259

Browse files
Sindhu-Devalestevemar
authored andcommitted
OSC Extension Show
Implement Neutron feature of Extension Show into OpenStack Client. Change-Id: Ifecb794838cb3bf8c2466d178345349db3cd4003 Implements: blueprint extension-show
1 parent 62bf9e2 commit 832b259

6 files changed

Lines changed: 155 additions & 0 deletions

File tree

doc/source/command-objects/extension.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,20 @@ List API extensions
3939
.. option:: --long
4040

4141
List additional fields in output
42+
43+
extension show
44+
--------------
45+
46+
Show API extension
47+
48+
.. program:: extension show
49+
.. code:: bash
50+
51+
openstack extension show
52+
<extension>
53+
54+
.. _extension_show:
55+
.. describe:: <extension>
56+
57+
Extension to display. Currently, only network extensions are supported.
58+
(Name or Alias)

openstackclient/common/extension.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,32 @@ def take_action(self, parsed_args):
134134
LOG.warning(message)
135135

136136
return (columns, extension_tuples)
137+
138+
139+
class ShowExtension(command.ShowOne):
140+
_description = _("Show API extension")
141+
142+
def get_parser(self, prog_name):
143+
parser = super(ShowExtension, self).get_parser(prog_name)
144+
parser.add_argument(
145+
'extension',
146+
metavar='<extension>',
147+
help=_('Extension to display. '
148+
'Currently, only network extensions are supported. '
149+
'(Name or Alias)'),
150+
)
151+
return parser
152+
153+
def take_action(self, parsed_args):
154+
client = self.app.client_manager.network
155+
columns = ('Alias', 'Description', 'Links', 'Name',
156+
'Namespace', 'Updated')
157+
ext = str(parsed_args.extension)
158+
obj = client.find_extension(ext)
159+
dict_tuples = (utils.get_item_properties(
160+
obj,
161+
columns,
162+
formatters={},)
163+
)
164+
165+
return columns, dict_tuples
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2017, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import json
17+
18+
from openstackclient.tests.functional import base
19+
20+
21+
class TestExtension(base.TestCase):
22+
"""Functional tests for extension."""
23+
24+
def test_extension_list(self):
25+
"""Test extension list."""
26+
json_output = json.loads(self.openstack(
27+
'extension list -f json ' + '--network')
28+
)
29+
self.assertEqual(
30+
'Default Subnetpools',
31+
json_output[0]['Name'],
32+
)
33+
34+
def test_extension_show(self):
35+
"""Test extension show."""
36+
name = 'agent'
37+
json_output = json.loads(self.openstack(
38+
'extension show -f json ' + name)
39+
)
40+
self.assertEqual(
41+
name,
42+
json_output.get('Alias'))

openstackclient/tests/unit/common/test_extension.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
2020
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
2121
from openstackclient.tests.unit import utils
22+
from openstackclient.tests.unit import utils as tests_utils
2223
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
2324

2425

@@ -242,3 +243,60 @@ def test_extension_list_volume(self):
242243
), )
243244
self._test_extension_list_helper(arglist, verifylist, datalist)
244245
self.volume_extensions_mock.show_all.assert_called_with()
246+
247+
248+
class TestExtensionShow(TestExtension):
249+
extension_details = (
250+
network_fakes.FakeExtension.create_one_extension()
251+
)
252+
253+
columns = (
254+
'Alias',
255+
'Description',
256+
'Links',
257+
'Name',
258+
'Namespace',
259+
'Updated'
260+
)
261+
262+
data = (
263+
extension_details.alias,
264+
extension_details.description,
265+
extension_details.links,
266+
extension_details.name,
267+
extension_details.namespace,
268+
extension_details.updated
269+
)
270+
271+
def setUp(self):
272+
super(TestExtensionShow, self).setUp()
273+
274+
self.cmd = extension.ShowExtension(self.app, None)
275+
276+
self.app.client_manager.network.find_extension = mock.Mock(
277+
return_value=self.extension_details)
278+
279+
def test_show_no_options(self):
280+
arglist = []
281+
verifylist = []
282+
283+
self.assertRaises(tests_utils.ParserException, self.check_parser,
284+
self.cmd, arglist, verifylist)
285+
286+
def test_show_all_options(self):
287+
arglist = [
288+
self.extension_details.alias,
289+
]
290+
verifylist = [
291+
('extension', self.extension_details.alias),
292+
]
293+
294+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
295+
296+
columns, data = self.cmd.take_action(parsed_args)
297+
298+
self.app.client_manager.network.find_extension.assert_called_with(
299+
self.extension_details.alias)
300+
301+
self.assertEqual(self.columns, columns)
302+
self.assertEqual(self.data, data)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Added `openstack extension show` command to allow users
5+
to view the details of the extension. Currently works only for
6+
network extensions.
7+
8+
[Blueprint `extension-show <https://blueprints.launchpad.net/python-openstackclient/+spec/extension-show>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ openstack.common =
4646
availability_zone_list = openstackclient.common.availability_zone:ListAvailabilityZone
4747
configuration_show = openstackclient.common.configuration:ShowConfiguration
4848
extension_list = openstackclient.common.extension:ListExtension
49+
extension_show = openstackclient.common.extension:ShowExtension
4950
limits_show = openstackclient.common.limits:ShowLimits
5051
quota_set = openstackclient.common.quota:SetQuota
5152
quota_show = openstackclient.common.quota:ShowQuota

0 commit comments

Comments
 (0)