Browse Source

OSC Extension Show

Implement Neutron feature of Extension Show into
OpenStack Client.

Change-Id: Ifecb794838cb3bf8c2466d178345349db3cd4003
Implements: blueprint extension-show
tags/3.10.0
Sindhu Devale 2 years ago
parent
commit
832b2591cf

+ 17
- 0
doc/source/command-objects/extension.rst View File

@@ -39,3 +39,20 @@ List API extensions
39 39
 .. option:: --long
40 40
 
41 41
     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)

+ 29
- 0
openstackclient/common/extension.py View File

@@ -134,3 +134,32 @@ class ListExtension(command.Lister):
134 134
                 LOG.warning(message)
135 135
 
136 136
         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

+ 42
- 0
openstackclient/tests/functional/common/test_extension.py View File

@@ -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'))

+ 58
- 0
openstackclient/tests/unit/common/test_extension.py View File

@@ -19,6 +19,7 @@ from openstackclient.tests.unit import fakes
19 19
 from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
20 20
 from openstackclient.tests.unit.network.v2 import fakes as network_fakes
21 21
 from openstackclient.tests.unit import utils
22
+from openstackclient.tests.unit import utils as tests_utils
22 23
 from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
23 24
 
24 25
 
@@ -242,3 +243,60 @@ class TestExtensionList(TestExtension):
242 243
         ), )
243 244
         self._test_extension_list_helper(arglist, verifylist, datalist)
244 245
         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)

+ 8
- 0
releasenotes/notes/bp-extension-show-6f7e31a27dad0dc9.yaml View File

@@ -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>`_]

+ 1
- 0
setup.cfg View File

@@ -46,6 +46,7 @@ openstack.common =
46 46
     availability_zone_list = openstackclient.common.availability_zone:ListAvailabilityZone
47 47
     configuration_show = openstackclient.common.configuration:ShowConfiguration
48 48
     extension_list = openstackclient.common.extension:ListExtension
49
+    extension_show = openstackclient.common.extension:ShowExtension
49 50
     limits_show = openstackclient.common.limits:ShowLimits
50 51
     quota_set = openstackclient.common.quota:SetQuota
51 52
     quota_show = openstackclient.common.quota:ShowQuota

Loading…
Cancel
Save