1010# License for the specific language governing permissions and limitations
1111# under the License.
1212
13+ import time
1314import uuid
1415
1516from openstack import exceptions as sdk_exceptions
1617from openstack import resource
1718
1819
1920class PrivateNatEnvironmentMixin (object ):
21+ def _wait_for_subnet_active (self , subnet , timeout = 60 , retries = 3 ):
22+ """Wait for a VPC subnet to become ACTIVE.
23+
24+ The OTC VPC subnet API is occasionally read-after-write
25+ inconsistent: a GET right after creation can 404 even though a
26+ previous GET already returned the resource. Retry the wait a
27+ few times before giving up so such transient 404s don't fail
28+ the test.
29+ """
30+ for attempt in range (retries ):
31+ try :
32+ return resource .wait_for_status (
33+ self .conn .vpc , subnet , "ACTIVE" , None , 2 , timeout
34+ )
35+ except sdk_exceptions .ResourceNotFound :
36+ if attempt == retries - 1 :
37+ raise
38+ time .sleep (2 )
39+
2040 def _delete_private_transit_ip (self , transit_ip_id ):
2141 self .conn .natv3 .delete_private_transit_ip (transit_ip_id , ignore_missing = True )
2242
@@ -43,7 +63,7 @@ def _create_private_nat_subnet(self, vpc, prefix, suffix):
4363 gateway_ip = gw [:- 2 ] + ".1" ,
4464 dns_list = ["100.125.4.25" , "100.125.129.199" ],
4565 )
46- resource . wait_for_status ( self .conn . vpc , subnet , "ACTIVE" , None , 2 , 60 )
66+ self ._wait_for_subnet_active ( subnet )
4767 return subnet
4868
4969 def _delete_private_nat_subnet (self , subnet ):
@@ -52,7 +72,7 @@ def _delete_private_nat_subnet(self, subnet):
5272 except sdk_exceptions .ResourceNotFound :
5373 return
5474
55- resource . wait_for_status ( self .conn . vpc , subnet , "ACTIVE" , None , 2 , 60 )
75+ self ._wait_for_subnet_active ( subnet )
5676 self .conn .vpc .delete_subnet (subnet , ignore_missing = True )
5777 resource .wait_for_delete (self .conn .vpc , subnet , 2 , 120 )
5878
0 commit comments