summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGinnis <sean.mcginnis@gmail.com>2018-10-09 15:24:51 -0500
committerSean McGinnis <sean.mcginnis@gmail.com>2018-10-09 15:31:35 -0500
commit4039d0d94f4eaf277f2b42c33ef873555f84f159 (patch)
tree8986d3b60c907266b555830a761b38e4135c81cf
parent4e6f47e28ee09be7dac8848660bf38bdcd02570c (diff)
Add volume backend capability show command
Adds and equivalend for "cinder get-capabilities" command to show the capabilities supported by a Cinder backend. Story: 1655624 Task: 26947 Change-Id: I38686a26cd503e45ce0102705a6632994ef10274 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
Notes
Notes (review): Code-Review+2: Steve Martinelli <s.martinelli@gmail.com> Code-Review+2: Dean Troyer <dtroyer@gmail.com> Workflow+1: Dean Troyer <dtroyer@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 12 Oct 2018 22:41:41 +0000 Reviewed-on: https://review.openstack.org/609122 Project: openstack/python-openstackclient Branch: refs/heads/master
-rw-r--r--doc/source/cli/command-objects/volume-backend.rst8
-rw-r--r--doc/source/cli/commands.rst1
-rw-r--r--doc/source/cli/data/cinder.csv2
-rw-r--r--openstackclient/tests/unit/volume/v2/fakes.py61
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_backend.py73
-rw-r--r--openstackclient/volume/v2/volume_backend.py61
-rw-r--r--releasenotes/notes/volume-backend-c5faae0b31556a24.yaml7
-rw-r--r--setup.cfg2
8 files changed, 214 insertions, 1 deletions
diff --git a/doc/source/cli/command-objects/volume-backend.rst b/doc/source/cli/command-objects/volume-backend.rst
new file mode 100644
index 0000000..0285d61
--- /dev/null
+++ b/doc/source/cli/command-objects/volume-backend.rst
@@ -0,0 +1,8 @@
1==============
2volume backend
3==============
4
5Volume v2
6
7.. autoprogram-cliff:: openstack.volume.v2
8 :command: volume backend *
diff --git a/doc/source/cli/commands.rst b/doc/source/cli/commands.rst
index 76126a7..1ca674d 100644
--- a/doc/source/cli/commands.rst
+++ b/doc/source/cli/commands.rst
@@ -156,6 +156,7 @@ referring to both Compute and Volume quotas.
156* ``user role``: (**Identity**) roles assigned to a user 156* ``user role``: (**Identity**) roles assigned to a user
157* ``volume``: (**Volume**) block volumes 157* ``volume``: (**Volume**) block volumes
158* ``volume backup``: (**Volume**) backup for volumes 158* ``volume backup``: (**Volume**) backup for volumes
159* ``volume backend``: (**volume**) volume backend storage
159* ``volume host``: (**Volume**) the physical computer for volumes 160* ``volume host``: (**Volume**) the physical computer for volumes
160* ``volume qos``: (**Volume**) quality-of-service (QoS) specification for volumes 161* ``volume qos``: (**Volume**) quality-of-service (QoS) specification for volumes
161* ``volume snapshot``: (**Volume**) a point-in-time copy of a volume 162* ``volume snapshot``: (**Volume**) a point-in-time copy of a volume
diff --git a/doc/source/cli/data/cinder.csv b/doc/source/cli/data/cinder.csv
index 5c89e08..068ffb7 100644
--- a/doc/source/cli/data/cinder.csv
+++ b/doc/source/cli/data/cinder.csv
@@ -32,7 +32,7 @@ extra-specs-list,volume type list --long,Lists current volume types and extra sp
32failover-host,volume host failover,Failover a replicating cinder-volume host. 32failover-host,volume host failover,Failover a replicating cinder-volume host.
33force-delete,volume delete --force,"Attempts force-delete of volume, regardless of state." 33force-delete,volume delete --force,"Attempts force-delete of volume, regardless of state."
34freeze-host,volume host set --disable,Freeze and disable the specified cinder-volume host. 34freeze-host,volume host set --disable,Freeze and disable the specified cinder-volume host.
35get-capabilities,,Show backend volume stats and properties. Admin only. 35get-capabilities,volume backend capability show,Show capabilities of a volume backend. Admin only.
36get-pools,,Show pool information for backends. Admin only. 36get-pools,,Show pool information for backends. Admin only.
37image-metadata,volume set --image-property,Sets or deletes volume image metadata. 37image-metadata,volume set --image-property,Sets or deletes volume image metadata.
38image-metadata-show,volume show,Shows volume image metadata. 38image-metadata-show,volume show,Shows volume image metadata.
diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py
index 481509f..ad13f1b 100644
--- a/openstackclient/tests/unit/volume/v2/fakes.py
+++ b/openstackclient/tests/unit/volume/v2/fakes.py
@@ -193,6 +193,65 @@ class FakeService(object):
193 return services 193 return services
194 194
195 195
196class FakeCapability(object):
197 """Fake capability."""
198
199 @staticmethod
200 def create_one_capability(attrs=None):
201 """Create a fake volume backend capability.
202
203 :param Dictionary attrs:
204 A dictionary with all attributes of the Capabilities.
205 :return:
206 A FakeResource object with capability name and attrs.
207 """
208 # Set default attribute
209 capability_info = {
210 "namespace": "OS::Storage::Capabilities::fake",
211 "vendor_name": "OpenStack",
212 "volume_backend_name": "lvmdriver-1",
213 "pool_name": "pool",
214 "driver_version": "2.0.0",
215 "storage_protocol": "iSCSI",
216 "display_name": "Capabilities of Cinder LVM driver",
217 "description": "Blah, blah.",
218 "visibility": "public",
219 "replication_targets": [],
220 "properties": {
221 "compression": {
222 "title": "Compression",
223 "description": "Enables compression.",
224 "type": "boolean"
225 },
226 "qos": {
227 "title": "QoS",
228 "description": "Enables QoS.",
229 "type": "boolean"
230 },
231 "replication": {
232 "title": "Replication",
233 "description": "Enables replication.",
234 "type": "boolean"
235 },
236 "thin_provisioning": {
237 "title": "Thin Provisioning",
238 "description": "Sets thin provisioning.",
239 "type": "boolean"
240 }
241 }
242 }
243
244 # Overwrite default attributes if there are some attributes set
245 capability_info.update(attrs or {})
246
247 capability = fakes.FakeResource(
248 None,
249 capability_info,
250 loaded=True)
251
252 return capability
253
254
196class FakeVolumeClient(object): 255class FakeVolumeClient(object):
197 256
198 def __init__(self, **kwargs): 257 def __init__(self, **kwargs):
@@ -233,6 +292,8 @@ class FakeVolumeClient(object):
233 self.cgsnapshots.resource_class = fakes.FakeResource(None, {}) 292 self.cgsnapshots.resource_class = fakes.FakeResource(None, {})
234 self.auth_token = kwargs['token'] 293 self.auth_token = kwargs['token']
235 self.management_url = kwargs['endpoint'] 294 self.management_url = kwargs['endpoint']
295 self.capabilities = mock.Mock()
296 self.capabilities.resource_class = fakes.FakeResource(None, {})
236 297
237 298
238class TestVolume(utils.TestCommand): 299class TestVolume(utils.TestCommand):
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backend.py b/openstackclient/tests/unit/volume/v2/test_volume_backend.py
new file mode 100644
index 0000000..73df603
--- /dev/null
+++ b/openstackclient/tests/unit/volume/v2/test_volume_backend.py
@@ -0,0 +1,73 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13#
14
15from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
16from openstackclient.volume.v2 import volume_backend
17
18
19class TestShowVolumeCapability(volume_fakes.TestVolume):
20 """Test backend capability functionality."""
21
22 # The capability to be listed
23 capability = volume_fakes.FakeCapability.create_one_capability()
24
25 def setUp(self):
26 super(TestShowVolumeCapability, self).setUp()
27
28 # Get a shortcut to the capability Mock
29 self.capability_mock = self.app.client_manager.volume.capabilities
30 self.capability_mock.get.return_value = self.capability
31
32 # Get the command object to test
33 self.cmd = volume_backend.ShowCapability(self.app, None)
34
35 def test_capability_show(self):
36 arglist = [
37 'fake',
38 ]
39 verifylist = [
40 ('host', 'fake'),
41 ]
42 parsed_args = self.check_parser(self.cmd, arglist, verifylist)
43
44 # In base command class Lister in cliff, abstract method take_action()
45 # returns a tuple containing the column names and an iterable
46 # containing the data to be listed.
47 columns, data = self.cmd.take_action(parsed_args)
48
49 expected_columns = [
50 'Title',
51 'Key',
52 'Type',
53 'Description',
54 ]
55
56 # confirming if all expected columns are present in the result.
57 self.assertEqual(expected_columns, columns)
58
59 capabilities = [
60 'Compression',
61 'Replication',
62 'QoS',
63 'Thin Provisioning',
64 ]
65
66 # confirming if all expected values are present in the result.
67 for cap in data:
68 self.assertTrue(cap[0] in capabilities)
69
70 # checking if proper call was made to get capabilities
71 self.capability_mock.get.assert_called_with(
72 'fake',
73 )
diff --git a/openstackclient/volume/v2/volume_backend.py b/openstackclient/volume/v2/volume_backend.py
new file mode 100644
index 0000000..0dff18c
--- /dev/null
+++ b/openstackclient/volume/v2/volume_backend.py
@@ -0,0 +1,61 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13#
14
15"""Capability action implementations"""
16
17from osc_lib.command import command
18from osc_lib import utils
19
20from openstackclient.i18n import _
21
22
23class ShowCapability(command.Lister):
24 _description = _("Show capability command")
25
26 def get_parser(self, prog_name):
27 parser = super(ShowCapability, self).get_parser(prog_name)
28 parser.add_argument(
29 "host",
30 metavar="<host>",
31 help=_("List capabilities of specified host (host@backend-name)")
32 )
33 return parser
34
35 def take_action(self, parsed_args):
36 volume_client = self.app.client_manager.volume
37
38 columns = [
39 'Title',
40 'Key',
41 'Type',
42 'Description',
43 ]
44
45 data = volume_client.capabilities.get(parsed_args.host)
46
47 # The get capabilities API is... interesting. We only want the names of
48 # the capabilities that can set for a backend through extra specs, so
49 # we need to extract out that part of the mess that is returned.
50 print_data = []
51 keys = data.properties
52 for key in keys:
53 # Stuff the key into the details to make it easier to output
54 capability_data = data.properties[key]
55 capability_data['key'] = key
56 print_data.append(capability_data)
57
58 return (columns,
59 (utils.get_dict_properties(
60 s, columns,
61 ) for s in print_data))
diff --git a/releasenotes/notes/volume-backend-c5faae0b31556a24.yaml b/releasenotes/notes/volume-backend-c5faae0b31556a24.yaml
new file mode 100644
index 0000000..851ab2d
--- /dev/null
+++ b/releasenotes/notes/volume-backend-c5faae0b31556a24.yaml
@@ -0,0 +1,7 @@
1---
2features:
3 - |
4 A new command, ``openstack volume backend capability show <host>`` was
5 added which will provide a list of all capabilities that can be configured
6 for the requested backend. The required `<host>` parameter takes the form
7 `host@backend-name`.
diff --git a/setup.cfg b/setup.cfg
index d9ca47c..888e259 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -629,6 +629,8 @@ openstack.volume.v2 =
629 volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup 629 volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
630 volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup 630 volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
631 631
632 volume_backend_capability_show = openstackclient.volume.v2.volume_backend:ShowCapability
633
632 volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost 634 volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost
633 volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost 635 volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
634 636