Skip to content

Commit 46ef850

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use cliff formattable columns in volume v2 commands"
2 parents d3df7d6 + 4cd6143 commit 46ef850

16 files changed

Lines changed: 360 additions & 229 deletions

openstackclient/tests/functional/volume/v2/test_qos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_volume_qos_set_show_unset(self):
7474
cmd_output['consumer']
7575
)
7676
self.assertEqual(
77-
"Alpha='a'",
77+
{'Alpha': 'a'},
7878
cmd_output['properties']
7979
)
8080

@@ -97,7 +97,7 @@ def test_volume_qos_set_show_unset(self):
9797
cmd_output['name']
9898
)
9999
self.assertEqual(
100-
"Alpha='c', Beta='b'",
100+
{'Alpha': 'c', 'Beta': 'b'},
101101
cmd_output['properties']
102102
)
103103

@@ -118,7 +118,7 @@ def test_volume_qos_set_show_unset(self):
118118
cmd_output['name']
119119
)
120120
self.assertEqual(
121-
"Beta='b'",
121+
{'Beta': 'b'},
122122
cmd_output['properties']
123123
)
124124

openstackclient/tests/functional/volume/v2/test_volume.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_volume_set_and_unset(self):
128128
cmd_output["description"],
129129
)
130130
self.assertEqual(
131-
"Alpha='a'",
131+
{'Alpha': 'a'},
132132
cmd_output["properties"],
133133
)
134134
self.assertEqual(
@@ -170,7 +170,7 @@ def test_volume_set_and_unset(self):
170170
cmd_output["description"],
171171
)
172172
self.assertEqual(
173-
"Beta='b', Gamma='c'",
173+
{'Beta': 'b', 'Gamma': 'c'},
174174
cmd_output["properties"],
175175
)
176176
self.assertEqual(
@@ -196,7 +196,7 @@ def test_volume_set_and_unset(self):
196196
new_name
197197
))
198198
self.assertEqual(
199-
"Gamma='c'",
199+
{'Gamma': 'c'},
200200
cmd_output["properties"],
201201
)
202202
self.assertEqual(

openstackclient/tests/functional/volume/v2/test_volume_snapshot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_volume_snapshot_set(self):
182182
cmd_output["description"],
183183
)
184184
self.assertEqual(
185-
"Alpha='a'",
185+
{'Alpha': 'a'},
186186
cmd_output["properties"],
187187
)
188188
self.wait_for_status('volume snapshot', name, 'available')
@@ -216,7 +216,7 @@ def test_volume_snapshot_set(self):
216216
cmd_output["description"],
217217
)
218218
self.assertEqual(
219-
"Alpha='c', Beta='b'",
219+
{'Alpha': 'c', 'Beta': 'b'},
220220
cmd_output["properties"],
221221
)
222222

@@ -233,7 +233,7 @@ def test_volume_snapshot_set(self):
233233
new_name
234234
))
235235
self.assertEqual(
236-
"Beta='b'",
236+
{'Beta': 'b'},
237237
cmd_output["properties"],
238238
)
239239

@@ -249,6 +249,6 @@ def test_volume_snapshot_set(self):
249249
new_name
250250
))
251251
self.assertNotIn(
252-
"Beta='b'",
252+
{'Beta': 'b'},
253253
cmd_output["properties"],
254254
)

openstackclient/tests/functional/volume/v2/test_volume_type.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def test_volume_type_set_unset_properties(self):
6565
cmd_output = json.loads(self.openstack(
6666
'volume type show -f json %s' % name
6767
))
68-
# TODO(amotoki): properties output should be machine-readable
69-
self.assertEqual("a='b', c='d'", cmd_output['properties'])
68+
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
7069

7170
raw_output = self.openstack(
7271
'volume type unset --property a %s' % name
@@ -75,7 +74,7 @@ def test_volume_type_set_unset_properties(self):
7574
cmd_output = json.loads(self.openstack(
7675
'volume type show -f json %s' % name
7776
))
78-
self.assertEqual("c='d'", cmd_output['properties'])
77+
self.assertEqual({'c': 'd'}, cmd_output['properties'])
7978

8079
def test_volume_type_set_unset_multiple_properties(self):
8180
name = uuid.uuid4().hex
@@ -96,7 +95,7 @@ def test_volume_type_set_unset_multiple_properties(self):
9695
cmd_output = json.loads(self.openstack(
9796
'volume type show -f json %s' % name
9897
))
99-
self.assertEqual("a='b', c='d'", cmd_output['properties'])
98+
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
10099

101100
raw_output = self.openstack(
102101
'volume type unset --property a --property c %s' % name
@@ -105,7 +104,7 @@ def test_volume_type_set_unset_multiple_properties(self):
105104
cmd_output = json.loads(self.openstack(
106105
'volume type show -f json %s' % name
107106
))
108-
self.assertEqual("", cmd_output['properties'])
107+
self.assertEqual({}, cmd_output['properties'])
109108

110109
def test_volume_type_set_unset_project(self):
111110
name = uuid.uuid4().hex
@@ -155,35 +154,32 @@ def test_encryption_type(self):
155154
'--encryption-key-size 128 '
156155
'--encryption-control-location front-end ' +
157156
encryption_type))
158-
# TODO(amotoki): encryption output should be machine-readable
159-
expected = ["provider='LuksEncryptor'",
160-
"cipher='aes-xts-plain64'",
161-
"key_size='128'",
162-
"control_location='front-end'"]
163-
for attr in expected:
164-
self.assertIn(attr, cmd_output['encryption'])
157+
expected = {'provider': 'LuksEncryptor',
158+
'cipher': 'aes-xts-plain64',
159+
'key_size': 128,
160+
'control_location': 'front-end'}
161+
for attr, value in expected.items():
162+
self.assertEqual(value, cmd_output['encryption'][attr])
165163
# test show encryption type
166164
cmd_output = json.loads(self.openstack(
167165
'volume type show -f json --encryption-type ' + encryption_type))
168-
# TODO(amotoki): encryption output should be machine-readable
169-
expected = ["provider='LuksEncryptor'",
170-
"cipher='aes-xts-plain64'",
171-
"key_size='128'",
172-
"control_location='front-end'"]
173-
for attr in expected:
174-
self.assertIn(attr, cmd_output['encryption'])
166+
expected = {'provider': 'LuksEncryptor',
167+
'cipher': 'aes-xts-plain64',
168+
'key_size': 128,
169+
'control_location': 'front-end'}
170+
for attr, value in expected.items():
171+
self.assertEqual(value, cmd_output['encryption'][attr])
175172
# test list encryption type
176173
cmd_output = json.loads(self.openstack(
177174
'volume type list -f json --encryption-type'))
178175
encryption_output = [t['Encryption'] for t in cmd_output
179176
if t['Name'] == encryption_type][0]
180-
# TODO(amotoki): encryption output should be machine-readable
181-
expected = ["provider='LuksEncryptor'",
182-
"cipher='aes-xts-plain64'",
183-
"key_size='128'",
184-
"control_location='front-end'"]
185-
for attr in expected:
186-
self.assertIn(attr, encryption_output)
177+
expected = {'provider': 'LuksEncryptor',
178+
'cipher': 'aes-xts-plain64',
179+
'key_size': 128,
180+
'control_location': 'front-end'}
181+
for attr, value in expected.items():
182+
self.assertEqual(value, encryption_output[attr])
187183
# test set existing encryption type
188184
raw_output = self.openstack(
189185
'volume type set '
@@ -193,12 +189,12 @@ def test_encryption_type(self):
193189
self.assertEqual('', raw_output)
194190
cmd_output = json.loads(self.openstack(
195191
'volume type show -f json --encryption-type ' + encryption_type))
196-
expected = ["provider='LuksEncryptor'",
197-
"cipher='aes-xts-plain64'",
198-
"key_size='256'",
199-
"control_location='back-end'"]
200-
for attr in expected:
201-
self.assertIn(attr, cmd_output['encryption'])
192+
expected = {'provider': 'LuksEncryptor',
193+
'cipher': 'aes-xts-plain64',
194+
'key_size': 256,
195+
'control_location': 'back-end'}
196+
for attr, value in expected.items():
197+
self.assertEqual(value, cmd_output['encryption'][attr])
202198
# test set new encryption type
203199
cmd_output = json.loads(self.openstack(
204200
'volume type create -f json --private ' +
@@ -222,12 +218,12 @@ def test_encryption_type(self):
222218
cmd_output = json.loads(self.openstack(
223219
'volume type show -f json --encryption-type ' + name
224220
))
225-
expected = ["provider='LuksEncryptor'",
226-
"cipher='aes-xts-plain64'",
227-
"key_size='128'",
228-
"control_location='front-end'"]
229-
for attr in expected:
230-
self.assertIn(attr, cmd_output['encryption'])
221+
expected = {'provider': 'LuksEncryptor',
222+
'cipher': 'aes-xts-plain64',
223+
'key_size': 128,
224+
'control_location': 'front-end'}
225+
for attr, value in expected.items():
226+
self.assertEqual(value, cmd_output['encryption'][attr])
231227
# test unset encryption type
232228
raw_output = self.openstack(
233229
'volume type unset --encryption-type ' + name
@@ -236,7 +232,7 @@ def test_encryption_type(self):
236232
cmd_output = json.loads(self.openstack(
237233
'volume type show -f json --encryption-type ' + name
238234
))
239-
self.assertEqual('', cmd_output['encryption'])
235+
self.assertEqual({}, cmd_output['encryption'])
240236
# test delete encryption type
241237
raw_output = self.openstack('volume type delete ' + encryption_type)
242238
self.assertEqual('', raw_output)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import uuid
1818

1919
import mock
20-
from osc_lib import utils as common_utils
20+
21+
from osc_lib.cli import format_columns
2122

2223
from openstackclient.tests.unit import fakes
2324
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
@@ -468,7 +469,7 @@ def get_volume_data(volume=None):
468469
if x == 'tags':
469470
# The 'tags' should be format_list
470471
data_list.append(
471-
common_utils.format_list(volume.info.get(x)))
472+
format_columns.ListColumn(volume.info.get(x)))
472473
else:
473474
data_list.append(volume.info.get(x))
474475
return tuple(data_list)

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import mock
1616
from mock import call
1717

18+
from osc_lib.cli import format_columns
1819
from osc_lib import exceptions
1920
from osc_lib import utils
2021

@@ -250,7 +251,7 @@ def test_consistency_group_create_without_name(self):
250251
)
251252

252253
self.assertEqual(self.columns, columns)
253-
self.assertEqual(self.data, data)
254+
self.assertItemEqual(self.data, data)
254255

255256
def test_consistency_group_create_from_source(self):
256257
arglist = [
@@ -278,7 +279,7 @@ def test_consistency_group_create_from_source(self):
278279
)
279280

280281
self.assertEqual(self.columns, columns)
281-
self.assertEqual(self.data, data)
282+
self.assertItemEqual(self.data, data)
282283

283284
def test_consistency_group_create_from_snapshot(self):
284285
arglist = [
@@ -306,7 +307,7 @@ def test_consistency_group_create_from_snapshot(self):
306307
)
307308

308309
self.assertEqual(self.columns, columns)
309-
self.assertEqual(self.data, data)
310+
self.assertItemEqual(self.data, data)
310311

311312

312313
class TestConsistencyGroupDelete(TestConsistencyGroup):
@@ -439,7 +440,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
439440
c.availability_zone,
440441
c.name,
441442
c.description,
442-
utils.format_list(c.volume_types)
443+
format_columns.ListColumn(c.volume_types)
443444
))
444445

445446
def setUp(self):
@@ -462,7 +463,7 @@ def test_consistency_group_list_without_options(self):
462463
self.consistencygroups_mock.list.assert_called_once_with(
463464
detailed=True, search_opts={'all_tenants': False})
464465
self.assertEqual(self.columns, columns)
465-
self.assertEqual(self.data, list(data))
466+
self.assertListItemEqual(self.data, list(data))
466467

467468
def test_consistency_group_list_with_all_project(self):
468469
arglist = [
@@ -479,7 +480,7 @@ def test_consistency_group_list_with_all_project(self):
479480
self.consistencygroups_mock.list.assert_called_once_with(
480481
detailed=True, search_opts={'all_tenants': True})
481482
self.assertEqual(self.columns, columns)
482-
self.assertEqual(self.data, list(data))
483+
self.assertListItemEqual(self.data, list(data))
483484

484485
def test_consistency_group_list_with_long(self):
485486
arglist = [
@@ -496,7 +497,7 @@ def test_consistency_group_list_with_long(self):
496497
self.consistencygroups_mock.list.assert_called_once_with(
497498
detailed=True, search_opts={'all_tenants': False})
498499
self.assertEqual(self.columns_long, columns)
499-
self.assertEqual(self.data_long, list(data))
500+
self.assertListItemEqual(self.data_long, list(data))
500501

501502

502503
class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
@@ -704,4 +705,4 @@ def test_consistency_group_show(self):
704705
self.consistencygroups_mock.get.assert_called_once_with(
705706
self.consistency_group.id)
706707
self.assertEqual(self.columns, columns)
707-
self.assertEqual(self.data, data)
708+
self.assertItemEqual(self.data, data)

0 commit comments

Comments
 (0)