Skip to content

Commit d3df7d6

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use cliff formattable columns in volume v1 commands"
2 parents 3258b9e + 1af3056 commit d3df7d6

13 files changed

Lines changed: 323 additions & 169 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_volume_qos_set_show_unset(self):
9393
cmd_output['name']
9494
)
9595
self.assertEqual(
96-
"Alpha='c', Beta='b'",
96+
{'Alpha': 'c', 'Beta': 'b'},
9797
cmd_output['properties']
9898
)
9999

@@ -114,7 +114,7 @@ def test_volume_qos_set_show_unset(self):
114114
cmd_output['name']
115115
)
116116
self.assertEqual(
117-
"Beta='b'",
117+
{'Beta': 'b'},
118118
cmd_output['properties']
119119
)
120120

openstackclient/tests/functional/volume/v1/test_snapshot.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_snapshot_set(self):
204204
cmd_output["display_description"],
205205
)
206206
self.assertEqual(
207-
"Alpha='a', Beta='b'",
207+
{'Alpha': 'a', 'Beta': 'b'},
208208
cmd_output["properties"],
209209
)
210210

@@ -221,7 +221,7 @@ def test_snapshot_set(self):
221221
new_name
222222
))
223223
self.assertEqual(
224-
"Beta='b'",
224+
{'Beta': 'b'},
225225
cmd_output["properties"],
226226
)
227227

@@ -236,7 +236,4 @@ def test_snapshot_set(self):
236236
'volume snapshot show -f json ' +
237237
new_name
238238
))
239-
self.assertNotIn(
240-
"Beta='b'",
241-
cmd_output["properties"],
242-
)
239+
self.assertEqual({}, cmd_output["properties"])

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_volume_set_and_unset(self):
123123
cmd_output["display_description"],
124124
)
125125
self.assertEqual(
126-
"Alpha='a'",
126+
{'Alpha': 'a'},
127127
cmd_output["properties"],
128128
)
129129
self.assertEqual(
@@ -165,7 +165,7 @@ def test_volume_set_and_unset(self):
165165
cmd_output["display_description"],
166166
)
167167
self.assertEqual(
168-
"Beta='b', Gamma='c'",
168+
{'Beta': 'b', 'Gamma': 'c'},
169169
cmd_output["properties"],
170170
)
171171
self.assertEqual(
@@ -186,7 +186,7 @@ def test_volume_set_and_unset(self):
186186
new_name
187187
))
188188
self.assertEqual(
189-
"Gamma='c'",
189+
{'Gamma': 'c'},
190190
cmd_output["properties"],
191191
)
192192

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

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

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

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

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

111110
def test_multi_delete(self):
112111
vol_type1 = uuid.uuid4().hex
@@ -133,34 +132,32 @@ def test_encryption_type(self):
133132
'--encryption-key-size 128 '
134133
'--encryption-control-location front-end ' +
135134
encryption_type))
136-
# TODO(amotoki): encryption output should be machine-readable
137-
expected = ["provider='LuksEncryptor'",
138-
"cipher='aes-xts-plain64'",
139-
"key_size='128'",
140-
"control_location='front-end'"]
141-
for attr in expected:
142-
self.assertIn(attr, cmd_output['encryption'])
135+
expected = {'provider': 'LuksEncryptor',
136+
'cipher': 'aes-xts-plain64',
137+
'key_size': 128,
138+
'control_location': 'front-end'}
139+
for attr, value in expected.items():
140+
self.assertEqual(value, cmd_output['encryption'][attr])
143141
# test show encryption type
144142
cmd_output = json.loads(self.openstack(
145143
'volume type show -f json --encryption-type ' + encryption_type))
146-
expected = ["provider='LuksEncryptor'",
147-
"cipher='aes-xts-plain64'",
148-
"key_size='128'",
149-
"control_location='front-end'"]
150-
for attr in expected:
151-
self.assertIn(attr, cmd_output['encryption'])
144+
expected = {'provider': 'LuksEncryptor',
145+
'cipher': 'aes-xts-plain64',
146+
'key_size': 128,
147+
'control_location': 'front-end'}
148+
for attr, value in expected.items():
149+
self.assertEqual(value, cmd_output['encryption'][attr])
152150
# test list encryption type
153151
cmd_output = json.loads(self.openstack(
154152
'volume type list -f json --encryption-type'))
155153
encryption_output = [t['Encryption'] for t in cmd_output
156154
if t['Name'] == encryption_type][0]
157-
# TODO(amotoki): encryption output should be machine-readable
158-
expected = ["provider='LuksEncryptor'",
159-
"cipher='aes-xts-plain64'",
160-
"key_size='128'",
161-
"control_location='front-end'"]
162-
for attr in expected:
163-
self.assertIn(attr, encryption_output)
155+
expected = {'provider': 'LuksEncryptor',
156+
'cipher': 'aes-xts-plain64',
157+
'key_size': 128,
158+
'control_location': 'front-end'}
159+
for attr, value in expected.items():
160+
self.assertEqual(value, encryption_output[attr])
164161
# test set new encryption type
165162
raw_output = self.openstack(
166163
'volume type set '
@@ -185,12 +182,12 @@ def test_encryption_type(self):
185182
cmd_output = json.loads(self.openstack(
186183
'volume type show -f json --encryption-type ' + name
187184
))
188-
expected = ["provider='LuksEncryptor'",
189-
"cipher='aes-xts-plain64'",
190-
"key_size='128'",
191-
"control_location='front-end'"]
192-
for attr in expected:
193-
self.assertIn(attr, cmd_output['encryption'])
185+
expected = {'provider': 'LuksEncryptor',
186+
'cipher': 'aes-xts-plain64',
187+
'key_size': 128,
188+
'control_location': 'front-end'}
189+
for attr, value in expected.items():
190+
self.assertEqual(value, cmd_output['encryption'][attr])
194191
# test unset encryption type
195192
raw_output = self.openstack(
196193
'volume type unset --encryption-type ' + name
@@ -199,7 +196,7 @@ def test_encryption_type(self):
199196
cmd_output = json.loads(self.openstack(
200197
'volume type show -f json --encryption-type ' + name
201198
))
202-
self.assertEqual('', cmd_output['encryption'])
199+
self.assertEqual({}, cmd_output['encryption'])
203200
# test delete encryption type
204201
raw_output = self.openstack('volume type delete ' + encryption_type)
205202
self.assertEqual('', raw_output)

openstackclient/tests/unit/volume/v1/test_qos_specs.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import mock
1919
from mock import call
20+
21+
from osc_lib.cli import format_columns
2022
from osc_lib import exceptions
2123
from osc_lib import utils
2224

@@ -85,7 +87,7 @@ def setUp(self):
8587
self.new_qos_spec.consumer,
8688
self.new_qos_spec.id,
8789
self.new_qos_spec.name,
88-
utils.format_dict(self.new_qos_spec.specs)
90+
format_columns.DictColumn(self.new_qos_spec.specs)
8991
)
9092
self.qos_mock.create.return_value = self.new_qos_spec
9193
# Get the command object to test
@@ -108,7 +110,7 @@ def test_qos_create_without_properties(self):
108110
)
109111

110112
self.assertEqual(self.columns, columns)
111-
self.assertEqual(self.datalist, data)
113+
self.assertItemEqual(self.datalist, data)
112114

113115
def test_qos_create_with_consumer(self):
114116
arglist = [
@@ -128,7 +130,7 @@ def test_qos_create_with_consumer(self):
128130
{'consumer': self.new_qos_spec.consumer}
129131
)
130132
self.assertEqual(self.columns, columns)
131-
self.assertEqual(self.datalist, data)
133+
self.assertItemEqual(self.datalist, data)
132134

133135
def test_qos_create_with_properties(self):
134136
arglist = [
@@ -154,7 +156,7 @@ def test_qos_create_with_properties(self):
154156
)
155157

156158
self.assertEqual(self.columns, columns)
157-
self.assertEqual(self.datalist, data)
159+
self.assertItemEqual(self.datalist, data)
158160

159161

160162
class TestQosDelete(TestQos):
@@ -326,8 +328,8 @@ class TestQosList(TestQos):
326328
q.id,
327329
q.name,
328330
q.consumer,
329-
qos_association.name,
330-
utils.format_dict(q.specs),
331+
format_columns.ListColumn([qos_association.name]),
332+
format_columns.DictColumn(q.specs),
331333
))
332334

333335
def setUp(self):
@@ -349,7 +351,7 @@ def test_qos_list(self):
349351
self.qos_mock.list.assert_called_with()
350352

351353
self.assertEqual(self.columns, columns)
352-
self.assertEqual(self.data, list(data))
354+
self.assertListItemEqual(self.data, list(data))
353355

354356
def test_qos_list_no_association(self):
355357
self.qos_mock.reset_mock()
@@ -373,10 +375,10 @@ def test_qos_list_no_association(self):
373375
self.qos_specs[1].id,
374376
self.qos_specs[1].name,
375377
self.qos_specs[1].consumer,
376-
None,
377-
utils.format_dict(self.qos_specs[1].specs),
378+
format_columns.ListColumn(None),
379+
format_columns.DictColumn(self.qos_specs[1].specs),
378380
)
379-
self.assertEqual(ex_data, list(data))
381+
self.assertListItemEqual(ex_data, list(data))
380382

381383

382384
class TestQosSet(TestQos):
@@ -447,13 +449,13 @@ def test_qos_show(self):
447449
)
448450
self.assertEqual(collist, columns)
449451
datalist = (
450-
self.qos_association.name,
452+
format_columns.ListColumn([self.qos_association.name]),
451453
self.qos_spec.consumer,
452454
self.qos_spec.id,
453455
self.qos_spec.name,
454-
utils.format_dict(self.qos_spec.specs),
456+
format_columns.DictColumn(self.qos_spec.specs),
455457
)
456-
self.assertEqual(datalist, tuple(data))
458+
self.assertItemEqual(datalist, tuple(data))
457459

458460

459461
class TestQosUnset(TestQos):

0 commit comments

Comments
 (0)