1010# License for the specific language governing permissions and limitations
1111# under the License.
1212
13+ import json
1314import time
1415import uuid
1516
@@ -20,61 +21,59 @@ class VolumeTypeTests(common.BaseVolumeTests):
2021 """Functional tests for volume type. """
2122
2223 NAME = uuid .uuid4 ().hex
23- HEADERS = ['"Name"' ]
24- FIELDS = ['name' ]
2524
2625 @classmethod
2726 def setUpClass (cls ):
2827 super (VolumeTypeTests , cls ).setUpClass ()
29- opts = cls .get_opts (cls .FIELDS )
30- raw_output = cls .openstack ('volume type create ' + cls .NAME + opts )
31- expected = cls .NAME + '\n '
32- cls .assertOutput (expected , raw_output )
28+ cmd_output = json .loads (cls .openstack (
29+ 'volume type create -f json ' + cls .NAME ))
30+ cls .assertOutput (cls .NAME , cmd_output ['name' ])
3331
3432 @classmethod
3533 def tearDownClass (cls ):
3634 raw_output = cls .openstack ('volume type delete ' + cls .NAME )
3735 cls .assertOutput ('' , raw_output )
3836
3937 def test_volume_type_list (self ):
40- opts = self .get_opts (self .HEADERS )
41- raw_output = self .openstack ('volume type list' + opts )
42- self .assertIn (self .NAME , raw_output )
38+ cmd_output = json .loads (self .openstack ('volume type list -f json' ))
39+ self .assertIn (self .NAME , [t ['Name' ] for t in cmd_output ])
4340
4441 def test_volume_type_show (self ):
45- opts = self . get_opts (self .FIELDS )
46- raw_output = self . openstack ( 'volume type show ' + self .NAME + opts )
47- self .assertEqual (self .NAME + " \n " , raw_output )
42+ cmd_output = json . loads (self .openstack (
43+ 'volume type show -f json ' + self .NAME ) )
44+ self .assertEqual (self .NAME , cmd_output [ 'name' ] )
4845
4946 def test_volume_type_set_unset_properties (self ):
5047 raw_output = self .openstack (
5148 'volume type set --property a=b --property c=d ' + self .NAME )
5249 self .assertEqual ("" , raw_output )
5350
54- opts = self .get_opts ([ "properties" ])
55- raw_output = self . openstack ( 'volume type show ' + self .NAME + opts )
56- self .assertEqual ("a='b', c='d'\n " , raw_output )
51+ cmd_output = json . loads ( self .openstack (
52+ 'volume type show -f json ' + self .NAME ) )
53+ self .assertEqual ("a='b', c='d'" , cmd_output [ 'properties' ] )
5754
5855 raw_output = self .openstack ('volume type unset --property a '
5956 + self .NAME )
6057 self .assertEqual ("" , raw_output )
61- raw_output = self .openstack ('volume type show ' + self .NAME + opts )
62- self .assertEqual ("c='d'\n " , raw_output )
58+ cmd_output = json .loads (self .openstack (
59+ 'volume type show -f json ' + self .NAME ))
60+ self .assertEqual ("c='d'" , cmd_output ['properties' ])
6361
6462 def test_volume_type_set_unset_multiple_properties (self ):
6563 raw_output = self .openstack (
6664 'volume type set --property a=b --property c=d ' + self .NAME )
6765 self .assertEqual ("" , raw_output )
6866
69- opts = self .get_opts ([ "properties" ])
70- raw_output = self . openstack ( 'volume type show ' + self .NAME + opts )
71- self .assertEqual ("a='b', c='d'\n " , raw_output )
67+ cmd_output = json . loads ( self .openstack (
68+ 'volume type show -f json ' + self .NAME ) )
69+ self .assertEqual ("a='b', c='d'" , cmd_output [ 'properties' ] )
7270
7371 raw_output = self .openstack (
7472 'volume type unset --property a --property c ' + self .NAME )
7573 self .assertEqual ("" , raw_output )
76- raw_output = self .openstack ('volume type show ' + self .NAME + opts )
77- self .assertEqual ("\n " , raw_output )
74+ cmd_output = json .loads (self .openstack (
75+ 'volume type show -f json ' + self .NAME ))
76+ self .assertEqual ("" , cmd_output ['properties' ])
7877
7978 def test_multi_delete (self ):
8079 vol_type1 = uuid .uuid4 ().hex
@@ -84,7 +83,6 @@ def test_multi_delete(self):
8483 self .openstack ('volume type create ' + vol_type2 )
8584 time .sleep (5 )
8685 cmd = 'volume type delete %s %s' % (vol_type1 , vol_type2 )
87- time .sleep (5 )
8886 raw_output = self .openstack (cmd )
8987 self .assertOutput ('' , raw_output )
9088
@@ -95,40 +93,41 @@ def test_multi_delete(self):
9593 def test_encryption_type (self ):
9694 encryption_type = uuid .uuid4 ().hex
9795 # test create new encryption type
98- opts = self .get_opts (['encryption' ])
99- raw_output = self .openstack (
100- 'volume type create '
96+ cmd_output = json .loads (self .openstack (
97+ 'volume type create -f json '
10198 '--encryption-provider LuksEncryptor '
10299 '--encryption-cipher aes-xts-plain64 '
103100 '--encryption-key-size 128 '
104101 '--encryption-control-location front-end ' +
105- encryption_type + opts )
102+ encryption_type ))
103+ # TODO(amotoki): encryption output should be machine-readable
106104 expected = ["provider='LuksEncryptor'" ,
107105 "cipher='aes-xts-plain64'" ,
108106 "key_size='128'" ,
109107 "control_location='front-end'" ]
110108 for attr in expected :
111- self .assertIn (attr , raw_output )
109+ self .assertIn (attr , cmd_output [ 'encryption' ] )
112110 # test show encryption type
113- opts = self .get_opts (['encryption' ])
114- raw_output = self .openstack (
115- 'volume type show --encryption-type ' + encryption_type + opts )
111+ cmd_output = json .loads (self .openstack (
112+ 'volume type show -f json --encryption-type ' + encryption_type ))
116113 expected = ["provider='LuksEncryptor'" ,
117114 "cipher='aes-xts-plain64'" ,
118115 "key_size='128'" ,
119116 "control_location='front-end'" ]
120117 for attr in expected :
121- self .assertIn (attr , raw_output )
118+ self .assertIn (attr , cmd_output [ 'encryption' ] )
122119 # test list encryption type
123- opts = self .get_opts (['Encryption' ])
124- raw_output = self .openstack (
125- 'volume type list --encryption-type ' + opts )
120+ cmd_output = json .loads (self .openstack (
121+ 'volume type list -f json --encryption-type' ))
122+ encryption_output = [t ['Encryption' ] for t in cmd_output
123+ if t ['Name' ] == encryption_type ][0 ]
124+ # TODO(amotoki): encryption output should be machine-readable
126125 expected = ["provider='LuksEncryptor'" ,
127126 "cipher='aes-xts-plain64'" ,
128127 "key_size='128'" ,
129128 "control_location='front-end'" ]
130129 for attr in expected :
131- self .assertIn (attr , raw_output )
130+ self .assertIn (attr , encryption_output )
132131 # test set new encryption type
133132 raw_output = self .openstack (
134133 'volume type set '
@@ -138,23 +137,21 @@ def test_encryption_type(self):
138137 '--encryption-control-location front-end ' +
139138 self .NAME )
140139 self .assertEqual ('' , raw_output )
141- opts = self .get_opts (['encryption' ])
142- raw_output = self .openstack (
143- 'volume type show --encryption-type ' + self .NAME + opts )
140+ cmd_output = json .loads (self .openstack (
141+ 'volume type show -f json --encryption-type ' + self .NAME ))
144142 expected = ["provider='LuksEncryptor'" ,
145143 "cipher='aes-xts-plain64'" ,
146144 "key_size='128'" ,
147145 "control_location='front-end'" ]
148146 for attr in expected :
149- self .assertIn (attr , raw_output )
147+ self .assertIn (attr , cmd_output [ 'encryption' ] )
150148 # test unset encryption type
151149 raw_output = self .openstack (
152150 'volume type unset --encryption-type ' + self .NAME )
153151 self .assertEqual ('' , raw_output )
154- opts = self .get_opts (['encryption' ])
155- raw_output = self .openstack (
156- 'volume type show --encryption-type ' + self .NAME + opts )
157- self .assertEqual ('\n ' , raw_output )
152+ cmd_output = json .loads (self .openstack (
153+ 'volume type show -f json --encryption-type ' + self .NAME ))
154+ self .assertEqual ('' , cmd_output ['encryption' ])
158155 # test delete encryption type
159156 raw_output = self .openstack ('volume type delete ' + encryption_type )
160157 self .assertEqual ('' , raw_output )
0 commit comments