Skip to content

Commit 53e7d71

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Migrate volume backend commands to SDK"
2 parents 491e5b9 + 39a084f commit 53e7d71

4 files changed

Lines changed: 40 additions & 49 deletions

File tree

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from cinderclient import api_versions
2222
from openstack.block_storage.v2 import _proxy as block_storage_v2_proxy
2323
from openstack.block_storage.v3 import backup as _backup
24+
from openstack.block_storage.v3 import capabilities as _capabilities
25+
from openstack.block_storage.v3 import stats as _stats
2426
from openstack.block_storage.v3 import volume as _volume
2527
from openstack.image.v2 import _proxy as image_v2_proxy
2628
from osc_lib.cli import format_columns
@@ -301,7 +303,7 @@ def create_one_capability(attrs=None):
301303
# Overwrite default attributes if there are some attributes set
302304
capability_info.update(attrs or {})
303305

304-
capability = fakes.FakeResource(None, capability_info, loaded=True)
306+
capability = _capabilities.Capabilities(**capability_info)
305307

306308
return capability
307309

@@ -317,19 +319,21 @@ def create_one_pool(attrs=None):
317319
# Set default attribute
318320
pool_info = {
319321
'name': 'host@lvmdriver-1#lvmdriver-1',
320-
'storage_protocol': 'iSCSI',
321-
'thick_provisioning_support': False,
322-
'thin_provisioning_support': True,
323-
'total_volumes': 99,
324-
'total_capacity_gb': 1000.00,
325-
'allocated_capacity_gb': 100,
326-
'max_over_subscription_ratio': 200.0,
322+
'capabilities': {
323+
'storage_protocol': 'iSCSI',
324+
'thick_provisioning_support': False,
325+
'thin_provisioning_support': True,
326+
'total_volumes': 99,
327+
'total_capacity_gb': 1000.00,
328+
'allocated_capacity_gb': 100,
329+
'max_over_subscription_ratio': 200.0,
330+
},
327331
}
328332

329333
# Overwrite default attributes if there are some attributes set
330334
pool_info.update(attrs or {})
331335

332-
pool = fakes.FakeResource(None, pool_info, loaded=True)
336+
pool = _stats.Pools(**pool_info)
333337

334338
return pool
335339

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# under the License.
1313
#
1414

15+
from osc_lib.cli import format_columns
16+
1517
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
1618
from openstackclient.volume.v2 import volume_backend
1719

@@ -25,9 +27,8 @@ class TestShowVolumeCapability(volume_fakes.TestVolume):
2527
def setUp(self):
2628
super().setUp()
2729

28-
# Get a shortcut to the capability Mock
29-
self.capability_mock = self.volume_client.capabilities
30-
self.capability_mock.get.return_value = self.capability
30+
# Assign return value to capabilities mock
31+
self.volume_sdk_client.get_capabilities.return_value = self.capability
3132

3233
# Get the command object to test
3334
self.cmd = volume_backend.ShowCapability(self.app, None)
@@ -68,7 +69,7 @@ def test_capability_show(self):
6869
self.assertIn(cap[0], capabilities)
6970

7071
# checking if proper call was made to get capabilities
71-
self.capability_mock.get.assert_called_with(
72+
self.volume_sdk_client.get_capabilities.assert_called_with(
7273
'fake',
7374
)
7475

@@ -82,8 +83,7 @@ class TestListVolumePool(volume_fakes.TestVolume):
8283
def setUp(self):
8384
super().setUp()
8485

85-
self.pool_mock = self.volume_client.pools
86-
self.pool_mock.list.return_value = [self.pools]
86+
self.volume_sdk_client.backend_pools.return_value = [self.pools]
8787

8888
# Get the command object to test
8989
self.cmd = volume_backend.ListPool(self.app, None)
@@ -111,7 +111,7 @@ def test_pool_list(self):
111111
self.assertEqual(datalist, tuple(data))
112112

113113
# checking if proper call was made to list pools
114-
self.pool_mock.list.assert_called_with(
114+
self.volume_sdk_client.backend_pools.assert_called_with(
115115
detailed=False,
116116
)
117117

@@ -131,13 +131,7 @@ def test_service_list_with_long_option(self):
131131

132132
expected_columns = [
133133
'Name',
134-
'Protocol',
135-
'Thick',
136-
'Thin',
137-
'Volumes',
138-
'Capacity',
139-
'Allocated',
140-
'Max Over Ratio',
134+
'Capabilities',
141135
]
142136

143137
# confirming if all expected columns are present in the result.
@@ -146,19 +140,13 @@ def test_service_list_with_long_option(self):
146140
datalist = (
147141
(
148142
self.pools.name,
149-
self.pools.storage_protocol,
150-
self.pools.thick_provisioning_support,
151-
self.pools.thin_provisioning_support,
152-
self.pools.total_volumes,
153-
self.pools.total_capacity_gb,
154-
self.pools.allocated_capacity_gb,
155-
self.pools.max_over_subscription_ratio,
143+
format_columns.DictColumn(self.pools.capabilities),
156144
),
157145
)
158146

159147
# confirming if all expected values are present in the result.
160148
self.assertEqual(datalist, tuple(data))
161149

162-
self.pool_mock.list.assert_called_with(
150+
self.volume_sdk_client.backend_pools.assert_called_with(
163151
detailed=True,
164152
)

openstackclient/volume/v2/volume_backend.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Storage backend action implementations"""
1616

17+
from osc_lib.cli import format_columns
1718
from osc_lib.command import command
1819
from osc_lib import utils
1920

@@ -33,7 +34,7 @@ def get_parser(self, prog_name):
3334
return parser
3435

3536
def take_action(self, parsed_args):
36-
volume_client = self.app.client_manager.volume
37+
volume_client = self.app.client_manager.sdk_connection.volume
3738

3839
columns = [
3940
'Title',
@@ -42,7 +43,7 @@ def take_action(self, parsed_args):
4243
'Description',
4344
]
4445

45-
data = volume_client.capabilities.get(parsed_args.host)
46+
data = volume_client.get_capabilities(parsed_args.host)
4647

4748
# The get capabilities API is... interesting. We only want the names of
4849
# the capabilities that can set for a backend through extra specs, so
@@ -83,42 +84,33 @@ def get_parser(self, prog_name):
8384
return parser
8485

8586
def take_action(self, parsed_args):
86-
volume_client = self.app.client_manager.volume
87+
volume_client = self.app.client_manager.sdk_connection.volume
8788

8889
if parsed_args.long:
8990
columns = [
9091
'name',
91-
'storage_protocol',
92-
'thick_provisioning_support',
93-
'thin_provisioning_support',
94-
'total_volumes',
95-
'total_capacity_gb',
96-
'allocated_capacity_gb',
97-
'max_over_subscription_ratio',
92+
'capabilities',
9893
]
94+
9995
headers = [
10096
'Name',
101-
'Protocol',
102-
'Thick',
103-
'Thin',
104-
'Volumes',
105-
'Capacity',
106-
'Allocated',
107-
'Max Over Ratio',
97+
'Capabilities',
10898
]
10999
else:
110100
columns = [
111101
'Name',
112102
]
113103
headers = columns
114104

115-
data = volume_client.pools.list(detailed=parsed_args.long)
105+
data = volume_client.backend_pools(detailed=parsed_args.long)
106+
formatters = {'capabilities': format_columns.DictColumn}
116107
return (
117108
headers,
118109
(
119110
utils.get_item_properties(
120111
s,
121112
columns,
113+
formatters=formatters,
122114
)
123115
for s in data
124116
),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Migrated following volume backends commands to SDK.
5+
6+
* Capability Show
7+
* Pool List

0 commit comments

Comments
 (0)