1111# under the License.
1212
1313import json
14- import time
1514import uuid
1615
1716from openstackclient .tests .functional .volume .v1 import common
@@ -22,16 +21,6 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
2221
2322 VOLLY = uuid .uuid4 ().hex
2423
25- @classmethod
26- def wait_for_status (cls , command , status , tries ):
27- opts = cls .get_opts (['status' ])
28- for attempt in range (tries ):
29- time .sleep (1 )
30- raw_output = cls .openstack (command + opts )
31- if (raw_output .rstrip () == status ):
32- return
33- cls .assertOutput (status , raw_output )
34-
3524 @classmethod
3625 def setUpClass (cls ):
3726 super (VolumeSnapshotTests , cls ).setUpClass ()
@@ -41,12 +30,12 @@ def setUpClass(cls):
4130 '--size 1 ' +
4231 cls .VOLLY
4332 ))
44- cls .wait_for_status ('volume show ' + cls .VOLLY , 'available' , 6 )
33+ cls .wait_for_status ('volume' , cls .VOLLY , 'available' )
4534 cls .VOLUME_ID = cmd_output ['id' ]
4635
4736 @classmethod
4837 def tearDownClass (cls ):
49- cls .wait_for_status ('volume show ' + cls .VOLLY , 'available' , 6 )
38+ cls .wait_for_status ('volume' , cls .VOLLY , 'available' )
5039 raw_output = cls .openstack ('volume delete --force ' + cls .VOLLY )
5140 cls .assertOutput ('' , raw_output )
5241
@@ -74,14 +63,14 @@ def test_volume_snapshot__delete(self):
7463 cmd_output ["display_name" ],
7564 )
7665
77- self .wait_for_status (
78- 'volume snapshot show ' + name1 , 'available' , 6 )
79- self .wait_for_status (
80- 'volume snapshot show ' + name2 , 'available' , 6 )
66+ self .wait_for_status ('volume snapshot' , name1 , 'available' )
67+ self .wait_for_status ('volume snapshot' , name2 , 'available' )
8168
8269 del_output = self .openstack (
8370 'volume snapshot delete ' + name1 + ' ' + name2 )
8471 self .assertOutput ('' , del_output )
72+ self .wait_for_delete ('volume snapshot' , name1 )
73+ self .wait_for_delete ('volume snapshot' , name2 )
8574
8675 def test_volume_snapshot_list (self ):
8776 """Test create, list filter"""
@@ -91,6 +80,7 @@ def test_volume_snapshot_list(self):
9180 name1 +
9281 ' --volume ' + self .VOLLY
9382 ))
83+ self .addCleanup (self .wait_for_delete , 'volume snapshot' , name1 )
9484 self .addCleanup (self .openstack , 'volume snapshot delete ' + name1 )
9585 self .assertEqual (
9686 name1 ,
@@ -104,15 +94,15 @@ def test_volume_snapshot_list(self):
10494 1 ,
10595 cmd_output ["size" ],
10696 )
107- self .wait_for_status (
108- 'volume snapshot show ' + name1 , 'available' , 6 )
97+ self .wait_for_status ('volume snapshot' , name1 , 'available' )
10998
11099 name2 = uuid .uuid4 ().hex
111100 cmd_output = json .loads (self .openstack (
112101 'volume snapshot create -f json ' +
113102 name2 +
114103 ' --volume ' + self .VOLLY
115104 ))
105+ self .addCleanup (self .wait_for_delete , 'volume snapshot' , name2 )
116106 self .addCleanup (self .openstack , 'volume snapshot delete ' + name2 )
117107 self .assertEqual (
118108 name2 ,
@@ -126,8 +116,7 @@ def test_volume_snapshot_list(self):
126116 1 ,
127117 cmd_output ["size" ],
128118 )
129- self .wait_for_status (
130- 'volume snapshot show ' + name2 , 'available' , 6 )
119+ self .wait_for_status ('volume snapshot' , name2 , 'available' )
131120
132121 # Test list --long, --status
133122 cmd_output = json .loads (self .openstack (
@@ -167,6 +156,7 @@ def test_snapshot_set(self):
167156 ' --description aaaa ' +
168157 name
169158 ))
159+ self .addCleanup (self .wait_for_delete , 'volume snapshot' , new_name )
170160 self .addCleanup (self .openstack , 'volume snapshot delete ' + new_name )
171161 self .assertEqual (
172162 name ,
@@ -180,8 +170,7 @@ def test_snapshot_set(self):
180170 'aaaa' ,
181171 cmd_output ["display_description" ],
182172 )
183- self .wait_for_status (
184- 'volume snapshot show ' + name , 'available' , 6 )
173+ self .wait_for_status ('volume snapshot' , name , 'available' )
185174
186175 # Test volume snapshot set
187176 raw_output = self .openstack (
0 commit comments