2020class VolumeTypeTests (common .BaseVolumeTests ):
2121 """Functional tests for volume type. """
2222
23- NAME = uuid .uuid4 ().hex
24-
25- @classmethod
26- def setUpClass (cls ):
27- super (VolumeTypeTests , cls ).setUpClass ()
28- cmd_output = json .loads (cls .openstack (
29- 'volume type create -f json --private %s' % cls .NAME ))
30- cls .assertOutput (cls .NAME , cmd_output ['name' ])
31-
32- @classmethod
33- def tearDownClass (cls ):
34- try :
35- raw_output = cls .openstack ('volume type delete %s' % cls .NAME )
36- cls .assertOutput ('' , raw_output )
37- finally :
38- super (VolumeTypeTests , cls ).tearDownClass ()
39-
40- def test_volume_type_list (self ):
23+ def test_volume_type_create_list (self ):
24+ name = uuid .uuid4 ().hex
25+ cmd_output = json .loads (self .openstack (
26+ 'volume type create -f json --private ' +
27+ name ,
28+ ))
29+ self .addCleanup (
30+ self .openstack ,
31+ 'volume type delete ' + name ,
32+ )
33+ self .assertEqual (name , cmd_output ['name' ])
34+
35+ cmd_output = json .loads (self .openstack (
36+ 'volume type show -f json %s' % name
37+ ))
38+ self .assertEqual (name , cmd_output ['name' ])
39+
4140 cmd_output = json .loads (self .openstack ('volume type list -f json' ))
42- self .assertIn (self . NAME , [t ['Name' ] for t in cmd_output ])
41+ self .assertIn (name , [t ['Name' ] for t in cmd_output ])
4342
44- def test_volume_type_list_default (self ):
4543 cmd_output = json .loads (self .openstack (
46- 'volume type list -f json --default' ))
44+ 'volume type list -f json --default'
45+ ))
4746 self .assertEqual (1 , len (cmd_output ))
4847 self .assertEqual ('lvmdriver-1' , cmd_output [0 ]['Name' ])
4948
50- def test_volume_type_show (self ):
49+ def test_volume_type_set_unset_properties (self ):
50+ name = uuid .uuid4 ().hex
5151 cmd_output = json .loads (self .openstack (
52- 'volume type show -f json %s' % self .NAME ))
53- self .assertEqual (self .NAME , cmd_output ['name' ])
52+ 'volume type create -f json --private ' +
53+ name ,
54+ ))
55+ self .addCleanup (
56+ self .openstack ,
57+ 'volume type delete ' + name
58+ )
59+ self .assertEqual (name , cmd_output ['name' ])
5460
55- def test_volume_type_set_unset_properties (self ):
5661 raw_output = self .openstack (
57- 'volume type set --property a=b --property c=d %s' % self .NAME )
62+ 'volume type set --property a=b --property c=d %s' % name
63+ )
5864 self .assertEqual ("" , raw_output )
5965 cmd_output = json .loads (self .openstack (
60- 'volume type show -f json %s' % self .NAME ))
66+ 'volume type show -f json %s' % name
67+ ))
6168 # TODO(amotoki): properties output should be machine-readable
6269 self .assertEqual ("a='b', c='d'" , cmd_output ['properties' ])
6370
64- raw_output = self .openstack ('volume type unset --property a %s' %
65- self .NAME )
71+ raw_output = self .openstack (
72+ 'volume type unset --property a %s' % name
73+ )
6674 self .assertEqual ("" , raw_output )
6775 cmd_output = json .loads (self .openstack (
68- 'volume type show -f json %s' % self .NAME ))
76+ 'volume type show -f json %s' % name
77+ ))
6978 self .assertEqual ("c='d'" , cmd_output ['properties' ])
7079
7180 def test_volume_type_set_unset_multiple_properties (self ):
81+ name = uuid .uuid4 ().hex
82+ cmd_output = json .loads (self .openstack (
83+ 'volume type create -f json --private ' +
84+ name ,
85+ ))
86+ self .addCleanup (
87+ self .openstack ,
88+ 'volume type delete ' + name
89+ )
90+ self .assertEqual (name , cmd_output ['name' ])
91+
7292 raw_output = self .openstack (
73- 'volume type set --property a=b --property c=d %s' % self .NAME )
93+ 'volume type set --property a=b --property c=d %s' % name
94+ )
7495 self .assertEqual ("" , raw_output )
7596 cmd_output = json .loads (self .openstack (
76- 'volume type show -f json %s' % self .NAME ))
97+ 'volume type show -f json %s' % name
98+ ))
7799 self .assertEqual ("a='b', c='d'" , cmd_output ['properties' ])
78100
79101 raw_output = self .openstack (
80- 'volume type unset --property a --property c %s' % self .NAME )
102+ 'volume type unset --property a --property c %s' % name
103+ )
81104 self .assertEqual ("" , raw_output )
82105 cmd_output = json .loads (self .openstack (
83- 'volume type show -f json %s' % self .NAME ))
106+ 'volume type show -f json %s' % name
107+ ))
84108 self .assertEqual ("" , cmd_output ['properties' ])
85109
86110 def test_volume_type_set_unset_project (self ):
111+ name = uuid .uuid4 ().hex
112+ cmd_output = json .loads (self .openstack (
113+ 'volume type create -f json --private ' +
114+ name ,
115+ ))
116+ self .addCleanup (
117+ self .openstack ,
118+ 'volume type delete ' + name
119+ )
120+ self .assertEqual (name , cmd_output ['name' ])
121+
87122 raw_output = self .openstack (
88- 'volume type set --project admin %s' % self .NAME )
123+ 'volume type set --project admin %s' % name
124+ )
89125 self .assertEqual ("" , raw_output )
90126
91127 raw_output = self .openstack (
92- 'volume type unset --project admin %s' % self .NAME )
128+ 'volume type unset --project admin %s' % name
129+ )
93130 self .assertEqual ("" , raw_output )
94131
95132 def test_multi_delete (self ):
@@ -108,6 +145,7 @@ def test_multi_delete(self):
108145 # these to new test format when beef up all tests for
109146 # volume tye commands.
110147 def test_encryption_type (self ):
148+ name = uuid .uuid4 ().hex
111149 encryption_type = uuid .uuid4 ().hex
112150 # test create new encryption type
113151 cmd_output = json .loads (self .openstack (
@@ -162,16 +200,28 @@ def test_encryption_type(self):
162200 for attr in expected :
163201 self .assertIn (attr , cmd_output ['encryption' ])
164202 # test set new encryption type
203+ cmd_output = json .loads (self .openstack (
204+ 'volume type create -f json --private ' +
205+ name ,
206+ ))
207+ self .addCleanup (
208+ self .openstack ,
209+ 'volume type delete ' + name ,
210+ )
211+ self .assertEqual (name , cmd_output ['name' ])
212+
165213 raw_output = self .openstack (
166214 'volume type set '
167215 '--encryption-provider LuksEncryptor '
168216 '--encryption-cipher aes-xts-plain64 '
169217 '--encryption-key-size 128 '
170218 '--encryption-control-location front-end ' +
171- self . NAME )
219+ name )
172220 self .assertEqual ('' , raw_output )
221+
173222 cmd_output = json .loads (self .openstack (
174- 'volume type show -f json --encryption-type ' + self .NAME ))
223+ 'volume type show -f json --encryption-type ' + name
224+ ))
175225 expected = ["provider='LuksEncryptor'" ,
176226 "cipher='aes-xts-plain64'" ,
177227 "key_size='128'" ,
@@ -180,10 +230,12 @@ def test_encryption_type(self):
180230 self .assertIn (attr , cmd_output ['encryption' ])
181231 # test unset encryption type
182232 raw_output = self .openstack (
183- 'volume type unset --encryption-type ' + self .NAME )
233+ 'volume type unset --encryption-type ' + name
234+ )
184235 self .assertEqual ('' , raw_output )
185236 cmd_output = json .loads (self .openstack (
186- 'volume type show -f json --encryption-type ' + self .NAME ))
237+ 'volume type show -f json --encryption-type ' + name
238+ ))
187239 self .assertEqual ('' , cmd_output ['encryption' ])
188240 # test delete encryption type
189241 raw_output = self .openstack ('volume type delete ' + encryption_type )
0 commit comments