Skip to content

Commit 4039d0d

Browse files
committed
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>
1 parent 4e6f47e commit 4039d0d

8 files changed

Lines changed: 214 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
==============
2+
volume backend
3+
==============
4+
5+
Volume v2
6+
7+
.. autoprogram-cliff:: openstack.volume.v2
8+
:command: volume backend *

doc/source/cli/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ referring to both Compute and Volume quotas.
156156
* ``user role``: (**Identity**) roles assigned to a user
157157
* ``volume``: (**Volume**) block volumes
158158
* ``volume backup``: (**Volume**) backup for volumes
159+
* ``volume backend``: (**volume**) volume backend storage
159160
* ``volume host``: (**Volume**) the physical computer for volumes
160161
* ``volume qos``: (**Volume**) quality-of-service (QoS) specification for volumes
161162
* ``volume snapshot``: (**Volume**) a point-in-time copy of a volume

doc/source/cli/data/cinder.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extra-specs-list,volume type list --long,Lists current volume types and extra sp
3232
failover-host,volume host failover,Failover a replicating cinder-volume host.
3333
force-delete,volume delete --force,"Attempts force-delete of volume, regardless of state."
3434
freeze-host,volume host set --disable,Freeze and disable the specified cinder-volume host.
35-
get-capabilities,,Show backend volume stats and properties. Admin only.
35+
get-capabilities,volume backend capability show,Show capabilities of a volume backend. Admin only.
3636
get-pools,,Show pool information for backends. Admin only.
3737
image-metadata,volume set --image-property,Sets or deletes volume image metadata.
3838
image-metadata-show,volume show,Shows volume image metadata.

openstackclient/tests/unit/volume/v2/fakes.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,65 @@ def create_services(attrs=None, count=2):
193193
return services
194194

195195

196+
class 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+
196255
class FakeVolumeClient(object):
197256

198257
def __init__(self, **kwargs):
@@ -233,6 +292,8 @@ def __init__(self, **kwargs):
233292
self.cgsnapshots.resource_class = fakes.FakeResource(None, {})
234293
self.auth_token = kwargs['token']
235294
self.management_url = kwargs['endpoint']
295+
self.capabilities = mock.Mock()
296+
self.capabilities.resource_class = fakes.FakeResource(None, {})
236297

237298

238299
class TestVolume(utils.TestCommand):
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
15+
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
16+
from openstackclient.volume.v2 import volume_backend
17+
18+
19+
class 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+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
17+
from osc_lib.command import command
18+
from osc_lib import utils
19+
20+
from openstackclient.i18n import _
21+
22+
23+
class 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))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
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`.

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ openstack.volume.v2 =
629629
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
630630
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
631631

632+
volume_backend_capability_show = openstackclient.volume.v2.volume_backend:ShowCapability
633+
632634
volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost
633635
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
634636

0 commit comments

Comments
 (0)