@@ -167,7 +167,7 @@ def _handle_error(self, response):
167
167
except requests .HTTPError as e :
168
168
self .lasterror = f'{ e } { response .text } '
169
169
self ._logger .error (self .lasterror )
170
- return None
170
+ raise e
171
171
return response
172
172
173
173
def _get_token (self ):
@@ -314,6 +314,7 @@ class CloudCluster():
314
314
Creates and deletes a cluster. Will also create a new namespace for
315
315
that cluster.
316
316
"""
317
+ _cid_filename = '.cluster_id'
317
318
318
319
CHECK_TIMEOUT_SEC = 3600
319
320
CHECK_BACKOFF_SEC = 60.0
@@ -410,6 +411,9 @@ def __init__(self,
410
411
if not self .utils .rpk_plugin_uninstall ('byoc' ):
411
412
self .utils .rpk_plugin_uninstall ('byoc' , sudo = True )
412
413
414
+ # save context
415
+ self ._ctx = context
416
+
413
417
@property
414
418
def cluster_id (self ):
415
419
"""
@@ -684,10 +688,33 @@ def update_cluster_acls(self, superuser):
684
688
685
689
return
686
690
691
+ @property
692
+ def _cid_file (self ):
693
+ return os .path .join (self ._ctx .session_context .results_dir ,
694
+ self ._cid_filename )
695
+
687
696
def _cluster_id_updated (self , uuid ):
688
697
_cluster = self .cloudv2 ._http_get (endpoint = f'/api/v1/clusters/{ uuid } ' )
689
698
return _cluster ['id' ] != uuid
690
699
700
+ def save_cluster_id (self , cluster_id ):
701
+ """
702
+ Save cluster id to results folder for next test to use
703
+ """
704
+ with open (self ._cid_file , 'w' ) as cf :
705
+ cf .write (cluster_id )
706
+ return
707
+
708
+ def safe_load_cluster_id (self ):
709
+ """
710
+ Checks if cluster_id is saved by previous test and loads it
711
+ """
712
+ _id = None
713
+ if os .path .exists (self ._cid_file ):
714
+ with open (self ._cid_file , 'r' ) as cf :
715
+ _id = cf .read ()
716
+ return _id
717
+
691
718
def _wait_for_cluster_id (self , uuid ):
692
719
wait_until (lambda : self ._cluster_id_updated (uuid ),
693
720
timeout_sec = 120 ,
@@ -707,10 +734,14 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
707
734
:param config_profile_name: config profile name, default 'tier-1-aws'
708
735
:return: clusterId, e.g. 'cimuhgmdcaa1uc1jtabc'
709
736
"""
710
-
737
+ # Check if previous test saved cluster id
738
+ _id = self .safe_load_cluster_id ()
739
+ if _id :
740
+ self .config .id = _id
741
+ # set network flag
711
742
if not self .isPublicNetwork :
712
743
self .current .connection_type = 'private'
713
-
744
+ # Prepare the cluster
714
745
if self .config .id != '' :
715
746
# Cluster already exist
716
747
# Just load needed info to create peering
@@ -769,12 +800,13 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
769
800
# the workslow, so just wait
770
801
_cluster_id = self ._wait_for_cluster_id (r ['id' ])
771
802
# Handle byoc creation
772
- # Login with out creds
803
+ # Login without saving creds
773
804
self .utils .rpk_cloud_login (self .config .oauth_client_id ,
774
805
self .config .oauth_client_secret )
775
806
# Install proper plugin
776
807
self .utils .rpk_cloud_byoc_install (_cluster_id )
777
808
# Kick off cluster creation
809
+ # Timeout for this is half an hour as this is only agent
778
810
self .utils .rpk_cloud_apply (_cluster_id )
779
811
780
812
# In case of FMC, just poll the cluster and wait when ready
@@ -790,6 +822,11 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
790
822
err_msg = 'Unable to deterimine readiness '
791
823
f'of cloud cluster { self .current .name } ' )
792
824
825
+ # at this point cluster is ready and if this is byoc
826
+ # just save the id to reuse it in next test
827
+ if self .config .type == CLOUD_TYPE_BYOC :
828
+ self .save_cluster_id (_cluster_id )
829
+
793
830
self .config .id , self .current .network_id = \
794
831
self ._get_cluster_id_and_network_id ()
795
832
0 commit comments