1010# License for the specific language governing permissions and limitations
1111# under the License.
1212
13+ import json
1314import time
1415import uuid
1516
@@ -20,9 +21,6 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
2021 """Functional tests for volume snapshot. """
2122
2223 VOLLY = uuid .uuid4 ().hex
23- NAME = uuid .uuid4 ().hex
24- OTHER_NAME = uuid .uuid4 ().hex
25- HEADERS = ['"Name"' ]
2624
2725 @classmethod
2826 def wait_for_status (cls , command , status , tries ):
@@ -37,52 +35,211 @@ def wait_for_status(cls, command, status, tries):
3735 @classmethod
3836 def setUpClass (cls ):
3937 super (VolumeSnapshotTests , cls ).setUpClass ()
40- cls . openstack ( 'volume create --size 1 ' + cls . VOLLY )
41- cls . wait_for_status ( 'volume show ' + cls .VOLLY , 'available \n ' , 3 )
42- opts = cls . get_opts ([ 'status' ])
43- raw_output = cls . openstack ( 'volume snapshot create --volume ' +
44- cls .VOLLY + ' ' + cls . NAME + opts )
45- cls . assertOutput ( 'creating \n ' , raw_output )
46- cls .wait_for_status (
47- 'volume snapshot show ' + cls .NAME , 'available \n ' , 3 )
38+ # create a volume for all tests to create snapshot
39+ cmd_output = json . loads ( cls .openstack (
40+ 'volume create -f json ' +
41+ '--size 1 ' +
42+ cls .VOLLY
43+ ) )
44+ cls .wait_for_status ('volume show ' + cls . VOLLY , 'available \n ' , 6 )
45+ cls .VOLUME_ID = cmd_output [ 'id' ]
4846
4947 @classmethod
5048 def tearDownClass (cls ):
51- # Rename test
52- raw_output = cls .openstack (
53- 'volume snapshot set --name ' + cls .OTHER_NAME + ' ' + cls .NAME )
54- cls .assertOutput ('' , raw_output )
55- # Delete test
56- raw_output_snapshot = cls .openstack (
57- 'volume snapshot delete ' + cls .OTHER_NAME )
5849 cls .wait_for_status ('volume show ' + cls .VOLLY , 'available\n ' , 6 )
59- raw_output_volume = cls .openstack ('volume delete --force ' + cls .VOLLY )
60- cls .assertOutput ('' , raw_output_snapshot )
61- cls .assertOutput ('' , raw_output_volume )
50+ raw_output = cls .openstack ('volume delete --force ' + cls .VOLLY )
51+ cls .assertOutput ('' , raw_output )
6252
63- def test_snapshot_list (self ):
64- opts = self .get_opts (self .HEADERS )
65- raw_output = self .openstack ('volume snapshot list' + opts )
66- self .assertIn (self .NAME , raw_output )
53+ def test_volume_snapshot__delete (self ):
54+ """Test create, delete multiple"""
55+ name1 = uuid .uuid4 ().hex
56+ cmd_output = json .loads (self .openstack (
57+ 'volume snapshot create -f json ' +
58+ name1 +
59+ ' --volume ' + self .VOLLY
60+ ))
61+ self .assertEqual (
62+ name1 ,
63+ cmd_output ["name" ],
64+ )
6765
68- def test_snapshot_properties (self ):
69- raw_output = self .openstack (
70- 'volume snapshot set --property a=b --property c=d ' + self .NAME )
71- self .assertEqual ("" , raw_output )
72- opts = self .get_opts (["properties" ])
73- raw_output = self .openstack ('volume snapshot show ' + self .NAME + opts )
74- self .assertEqual ("a='b', c='d'\n " , raw_output )
66+ name2 = uuid .uuid4 ().hex
67+ cmd_output = json .loads (self .openstack (
68+ 'volume snapshot create -f json ' +
69+ name2 +
70+ ' --volume ' + self .VOLLY
71+ ))
72+ self .assertEqual (
73+ name2 ,
74+ cmd_output ["name" ],
75+ )
76+
77+ self .wait_for_status (
78+ 'volume snapshot show ' + name1 , 'available\n ' , 6 )
79+ self .wait_for_status (
80+ 'volume snapshot show ' + name2 , 'available\n ' , 6 )
81+
82+ del_output = self .openstack (
83+ 'volume snapshot delete ' + name1 + ' ' + name2 )
84+ self .assertOutput ('' , del_output )
85+
86+ def test_volume_snapshot_list (self ):
87+ """Test create, list filter"""
88+ name1 = uuid .uuid4 ().hex
89+ cmd_output = json .loads (self .openstack (
90+ 'volume snapshot create -f json ' +
91+ name1 +
92+ ' --volume ' + self .VOLLY
93+ ))
94+ self .addCleanup (self .openstack , 'volume snapshot delete ' + name1 )
95+ self .assertEqual (
96+ name1 ,
97+ cmd_output ["name" ],
98+ )
99+ self .assertEqual (
100+ self .VOLUME_ID ,
101+ cmd_output ["volume_id" ],
102+ )
103+ self .assertEqual (
104+ 1 ,
105+ cmd_output ["size" ],
106+ )
107+ self .wait_for_status (
108+ 'volume snapshot show ' + name1 , 'available\n ' , 6 )
75109
110+ name2 = uuid .uuid4 ().hex
111+ cmd_output = json .loads (self .openstack (
112+ 'volume snapshot create -f json ' +
113+ name2 +
114+ ' --volume ' + self .VOLLY
115+ ))
116+ self .addCleanup (self .openstack , 'volume snapshot delete ' + name2 )
117+ self .assertEqual (
118+ name2 ,
119+ cmd_output ["name" ],
120+ )
121+ self .assertEqual (
122+ self .VOLUME_ID ,
123+ cmd_output ["volume_id" ],
124+ )
125+ self .assertEqual (
126+ 1 ,
127+ cmd_output ["size" ],
128+ )
129+ self .wait_for_status (
130+ 'volume snapshot show ' + name2 , 'available\n ' , 6 )
76131 raw_output = self .openstack (
77- 'volume snapshot unset --property a ' + self .NAME )
78- self .assertEqual ("" , raw_output )
79- raw_output = self .openstack ('volume snapshot show ' + self .NAME + opts )
80- self .assertEqual ("c='d'\n " , raw_output )
132+ 'volume snapshot set ' +
133+ '--state error ' +
134+ name2
135+ )
136+ self .assertOutput ('' , raw_output )
137+
138+ # Test list --long, --status
139+ cmd_output = json .loads (self .openstack (
140+ 'volume snapshot list -f json ' +
141+ '--long ' +
142+ '--status error'
143+ ))
144+ names = [x ["Name" ] for x in cmd_output ]
145+ self .assertNotIn (name1 , names )
146+ self .assertIn (name2 , names )
147+
148+ # Test list --volume
149+ cmd_output = json .loads (self .openstack (
150+ 'volume snapshot list -f json ' +
151+ '--volume ' + self .VOLLY
152+ ))
153+ names = [x ["Name" ] for x in cmd_output ]
154+ self .assertIn (name1 , names )
155+ self .assertIn (name2 , names )
156+
157+ # Test list --name
158+ cmd_output = json .loads (self .openstack (
159+ 'volume snapshot list -f json ' +
160+ '--name ' + name1
161+ ))
162+ names = [x ["Name" ] for x in cmd_output ]
163+ self .assertIn (name1 , names )
164+ self .assertNotIn (name2 , names )
81165
82166 def test_snapshot_set (self ):
167+ """Test create, set, unset, show, delete volume snapshot"""
168+ name = uuid .uuid4 ().hex
169+ new_name = name + "_"
170+ cmd_output = json .loads (self .openstack (
171+ 'volume snapshot create -f json ' +
172+ '--volume ' + self .VOLLY +
173+ ' --description aaaa ' +
174+ '--property Alpha=a ' +
175+ name
176+ ))
177+ self .addCleanup (self .openstack , 'volume snapshot delete ' + new_name )
178+ self .assertEqual (
179+ name ,
180+ cmd_output ["name" ],
181+ )
182+ self .assertEqual (
183+ 1 ,
184+ cmd_output ["size" ],
185+ )
186+ self .assertEqual (
187+ 'aaaa' ,
188+ cmd_output ["description" ],
189+ )
190+ self .assertEqual (
191+ "Alpha='a'" ,
192+ cmd_output ["properties" ],
193+ )
194+ self .wait_for_status (
195+ 'volume snapshot show ' + name , 'available\n ' , 6 )
196+
197+ # Test volume snapshot set
83198 raw_output = self .openstack (
84- 'volume snapshot set --description backup ' + self .NAME )
85- self .assertEqual ("" , raw_output )
86- opts = self .get_opts (["description" , "name" ])
87- raw_output = self .openstack ('volume snapshot show ' + self .NAME + opts )
88- self .assertEqual ("backup\n " + self .NAME + "\n " , raw_output )
199+ 'volume snapshot set ' +
200+ '--name ' + new_name +
201+ ' --description bbbb ' +
202+ '--property Alpha=c ' +
203+ '--property Beta=b ' +
204+ name ,
205+ )
206+ self .assertOutput ('' , raw_output )
207+
208+ # Show snapshot set result
209+ cmd_output = json .loads (self .openstack (
210+ 'volume snapshot show -f json ' +
211+ new_name
212+ ))
213+ self .assertEqual (
214+ new_name ,
215+ cmd_output ["name" ],
216+ )
217+ self .assertEqual (
218+ 1 ,
219+ cmd_output ["size" ],
220+ )
221+ self .assertEqual (
222+ 'bbbb' ,
223+ cmd_output ["description" ],
224+ )
225+ self .assertEqual (
226+ "Alpha='c', Beta='b'" ,
227+ cmd_output ["properties" ],
228+ )
229+
230+ # Test volume unset
231+ raw_output = self .openstack (
232+ 'volume snapshot unset ' +
233+ '--property Alpha ' +
234+ new_name ,
235+ )
236+ self .assertOutput ('' , raw_output )
237+
238+ cmd_output = json .loads (self .openstack (
239+ 'volume snapshot show -f json ' +
240+ new_name
241+ ))
242+ self .assertEqual (
243+ "Beta='b'" ,
244+ cmd_output ["properties" ],
245+ )
0 commit comments