Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a723ab

Browse filesBrowse files
committed
volume: Migrate 'block storage cluster *' to SDK
Change-Id: Ib7d5069af7b81810df66234efe8f063eeae1ab20 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 2fdd42c commit 8a723ab
Copy full SHA for 8a723ab

2 files changed

+60-64Lines changed: 60 additions & 64 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py‎

Copy file name to clipboardExpand all lines: openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py
+32-46Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,24 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
from openstack.block_storage.v3 import cluster as _cluster
14+
from openstack.test import fakes as sdk_fakes
1315
from osc_lib import exceptions
1416

1517
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
1618
from openstackclient.volume.v3 import block_storage_cluster
1719

1820

19-
class TestBlockStorageCluster(volume_fakes.TestVolume):
20-
def setUp(self):
21-
super().setUp()
22-
23-
# Get a shortcut to the BlockStorageClusterManager Mock
24-
self.cluster_mock = self.volume_client.clusters
25-
self.cluster_mock.reset_mock()
26-
27-
28-
class TestBlockStorageClusterList(TestBlockStorageCluster):
29-
# The cluster to be listed
30-
fake_clusters = volume_fakes.create_clusters()
21+
class TestBlockStorageClusterList(volume_fakes.TestVolume):
22+
fake_clusters = list(
23+
sdk_fakes.generate_fake_resources(_cluster.Cluster, count=2)
24+
)
3125

3226
def setUp(self):
3327
super().setUp()
3428

35-
self.cluster_mock.list.return_value = self.fake_clusters
29+
self.volume_sdk_client.clusters.return_value = self.fake_clusters
3630

37-
# Get the command object to test
3831
self.cmd = block_storage_cluster.ListBlockStorageCluster(
3932
self.app, None
4033
)
@@ -69,15 +62,14 @@ def test_cluster_list(self):
6962
self.assertEqual(expected_columns, columns)
7063
self.assertEqual(expected_data, tuple(data))
7164

72-
# checking if proper call was made to list clusters
73-
self.cluster_mock.list.assert_called_with(
65+
self.volume_sdk_client.clusters.assert_called_once_with(
7466
name=None,
7567
binary=None,
7668
is_up=None,
7769
disabled=None,
7870
num_hosts=None,
7971
num_down_hosts=None,
80-
detailed=False,
72+
details=False,
8173
)
8274

8375
def test_cluster_list_with_full_options(self):
@@ -139,15 +131,14 @@ def test_cluster_list_with_full_options(self):
139131
self.assertEqual(expected_columns, columns)
140132
self.assertEqual(expected_data, tuple(data))
141133

142-
# checking if proper call was made to list clusters
143-
self.cluster_mock.list.assert_called_with(
134+
self.volume_sdk_client.clusters.assert_called_once_with(
144135
name='foo',
145136
binary='bar',
146137
is_up=True,
147138
disabled=True,
148139
num_hosts=5,
149140
num_down_hosts=0,
150-
detailed=True,
141+
details=True,
151142
)
152143

153144
def test_cluster_list_pre_v37(self):
@@ -173,8 +164,8 @@ def test_cluster_list_pre_v37(self):
173164
)
174165

175166

176-
class TestBlockStorageClusterSet(TestBlockStorageCluster):
177-
cluster = volume_fakes.create_one_cluster()
167+
class TestBlockStorageClusterSet(volume_fakes.TestVolume):
168+
cluster = sdk_fakes.generate_fake_resource(_cluster.Cluster)
178169
columns = (
179170
'Name',
180171
'Binary',
@@ -209,11 +200,12 @@ class TestBlockStorageClusterSet(TestBlockStorageCluster):
209200
def setUp(self):
210201
super().setUp()
211202

212-
self.cluster_mock.update.return_value = self.cluster
203+
self.volume_sdk_client.enable_cluster.return_value = self.cluster
204+
self.volume_sdk_client.disable_cluster.return_value = self.cluster
213205

214206
self.cmd = block_storage_cluster.SetBlockStorageCluster(self.app, None)
215207

216-
def test_cluster_set(self):
208+
def test_cluster_set_enable(self):
217209
self.set_volume_api_version('3.7')
218210

219211
arglist = [
@@ -233,12 +225,10 @@ def test_cluster_set(self):
233225
self.assertEqual(self.columns, columns)
234226
self.assertEqual(self.data, tuple(data))
235227

236-
self.cluster_mock.update.assert_called_once_with(
237-
self.cluster.name,
238-
'cinder-volume',
239-
disabled=False,
240-
disabled_reason=None,
228+
self.volume_sdk_client.enable_cluster.assert_called_once_with(
229+
_cluster.Cluster(name=self.cluster.name, binary='cinder-volume')
241230
)
231+
self.volume_sdk_client.disable_cluster.assert_not_called()
242232

243233
def test_cluster_set_disable_with_reason(self):
244234
self.set_volume_api_version('3.7')
@@ -263,12 +253,13 @@ def test_cluster_set_disable_with_reason(self):
263253
self.assertEqual(self.columns, columns)
264254
self.assertEqual(self.data, tuple(data))
265255

266-
self.cluster_mock.update.assert_called_once_with(
267-
self.cluster.name,
268-
self.cluster.binary,
269-
disabled=True,
270-
disabled_reason='foo',
256+
self.volume_sdk_client.disable_cluster.assert_called_once_with(
257+
_cluster.Cluster(
258+
name=self.cluster.name, binary=self.cluster.binary
259+
),
260+
reason='foo',
271261
)
262+
self.volume_sdk_client.enable_cluster.assert_not_called()
272263

273264
def test_cluster_set_only_with_disable_reason(self):
274265
self.set_volume_api_version('3.7')
@@ -341,8 +332,8 @@ def test_cluster_set_pre_v37(self):
341332
)
342333

343334

344-
class TestBlockStorageClusterShow(TestBlockStorageCluster):
345-
cluster = volume_fakes.create_one_cluster()
335+
class TestBlockStorageClusterShow(volume_fakes.TestVolume):
336+
cluster = sdk_fakes.generate_fake_resource(_cluster.Cluster)
346337
columns = (
347338
'Name',
348339
'Binary',
@@ -377,7 +368,7 @@ class TestBlockStorageClusterShow(TestBlockStorageCluster):
377368
def setUp(self):
378369
super().setUp()
379370

380-
self.cluster_mock.show.return_value = self.cluster
371+
self.volume_sdk_client.get_cluster.return_value = self.cluster
381372

382373
self.cmd = block_storage_cluster.ShowBlockStorageCluster(
383374
self.app, None
@@ -387,13 +378,11 @@ def test_cluster_show(self):
387378
self.set_volume_api_version('3.7')
388379

389380
arglist = [
390-
'--binary',
391-
self.cluster.binary,
392381
self.cluster.name,
393382
]
394383
verifylist = [
395384
('cluster', self.cluster.name),
396-
('binary', self.cluster.binary),
385+
('binary', None),
397386
]
398387

399388
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -402,22 +391,19 @@ def test_cluster_show(self):
402391
self.assertEqual(self.columns, columns)
403392
self.assertEqual(self.data, tuple(data))
404393

405-
self.cluster_mock.show.assert_called_once_with(
406-
self.cluster.name,
407-
binary=self.cluster.binary,
394+
self.volume_sdk_client.get_cluster.assert_called_once_with(
395+
self.cluster.name
408396
)
409397

410398
def test_cluster_show_pre_v37(self):
411399
self.set_volume_api_version('3.6')
412400

413401
arglist = [
414-
'--binary',
415-
self.cluster.binary,
416402
self.cluster.name,
417403
]
418404
verifylist = [
419405
('cluster', self.cluster.name),
420-
('binary', self.cluster.binary),
406+
('binary', None),
421407
]
422408

423409
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
Collapse file

‎openstackclient/volume/v3/block_storage_cluster.py‎

Copy file name to clipboardExpand all lines: openstackclient/volume/v3/block_storage_cluster.py
+28-18Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from collections.abc import Iterable, Sequence
1515
from typing import Any
1616

17-
from cinderclient import api_versions
17+
from openstack.block_storage.v3 import cluster as _cluster
18+
from openstack import utils as sdk_utils
1819
from osc_lib import exceptions
1920
from osc_lib import utils
2021

@@ -146,9 +147,11 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
146147
def take_action(
147148
self, parsed_args: argparse.Namespace
148149
) -> tuple[tuple[str, ...], Iterable[tuple[Any, ...]]]:
149-
volume_client = self.app.client_manager.volume
150+
volume_client = sdk_utils.ensure_service_version(
151+
self.app.client_manager.sdk_connection.volume, '3'
152+
)
150153

151-
if volume_client.api_version < api_versions.APIVersion('3.7'):
154+
if not sdk_utils.supports_microversion(volume_client, '3.7'):
152155
msg = _(
153156
"--os-volume-api-version 3.7 or greater is required to "
154157
"support the 'block storage cluster list' command"
@@ -166,14 +169,14 @@ def take_action(
166169
'Updated At',
167170
)
168171

169-
data = volume_client.clusters.list(
172+
data = volume_client.clusters(
170173
name=parsed_args.cluster,
171174
binary=parsed_args.binary,
172175
is_up=parsed_args.is_up,
173176
disabled=parsed_args.is_disabled,
174177
num_hosts=parsed_args.num_hosts,
175178
num_down_hosts=parsed_args.num_down_hosts,
176-
detailed=parsed_args.long,
179+
details=parsed_args.long,
177180
)
178181

179182
return (
@@ -232,9 +235,11 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
232235
def take_action(
233236
self, parsed_args: argparse.Namespace
234237
) -> tuple[Sequence[str], Iterable[Any]]:
235-
volume_client = self.app.client_manager.volume
238+
volume_client = sdk_utils.ensure_service_version(
239+
self.app.client_manager.sdk_connection.volume, '3'
240+
)
236241

237-
if volume_client.api_version < api_versions.APIVersion('3.7'):
242+
if not sdk_utils.supports_microversion(volume_client, '3.7'):
238243
msg = _(
239244
"--os-volume-api-version 3.7 or greater is required to "
240245
"support the 'block storage cluster set' command"
@@ -245,13 +250,19 @@ def take_action(
245250
msg = _("Cannot specify --disable-reason without --disable")
246251
raise exceptions.CommandError(msg)
247252

248-
cluster = volume_client.clusters.update(
249-
parsed_args.cluster,
250-
parsed_args.binary,
251-
disabled=parsed_args.disabled,
252-
disabled_reason=parsed_args.disabled_reason,
253+
cluster_obj = _cluster.Cluster(
254+
name=parsed_args.cluster,
255+
binary=parsed_args.binary,
253256
)
254257

258+
if parsed_args.disabled:
259+
cluster = volume_client.disable_cluster(
260+
cluster_obj,
261+
reason=parsed_args.disabled_reason,
262+
)
263+
else:
264+
cluster = volume_client.enable_cluster(cluster_obj)
265+
255266
return _format_cluster(cluster, detailed=True)
256267

257268

@@ -278,18 +289,17 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
278289
def take_action(
279290
self, parsed_args: argparse.Namespace
280291
) -> tuple[Sequence[str], Iterable[Any]]:
281-
volume_client = self.app.client_manager.volume
292+
volume_client = sdk_utils.ensure_service_version(
293+
self.app.client_manager.sdk_connection.volume, '3'
294+
)
282295

283-
if volume_client.api_version < api_versions.APIVersion('3.7'):
296+
if not sdk_utils.supports_microversion(volume_client, '3.7'):
284297
msg = _(
285298
"--os-volume-api-version 3.7 or greater is required to "
286299
"support the 'block storage cluster show' command"
287300
)
288301
raise exceptions.CommandError(msg)
289302

290-
cluster = volume_client.clusters.show(
291-
parsed_args.cluster,
292-
binary=parsed_args.binary,
293-
)
303+
cluster = volume_client.get_cluster(parsed_args.cluster)
294304

295305
return _format_cluster(cluster, detailed=True)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.