Skip to content

Commit 310432e

Browse files
committed
rptest: Create and reuse BYOC cluster
Cloud class uses session results folder to share cluster ID between tests. Also, each time, byoc plugin should be reinstalled for new cluster as it tightly in sync with its version.
1 parent 53401cd commit 310432e

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

tests/rptest/services/redpanda_cloud.py

+41-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _handle_error(self, response):
167167
except requests.HTTPError as e:
168168
self.lasterror = f'{e} {response.text}'
169169
self._logger.error(self.lasterror)
170-
return None
170+
raise e
171171
return response
172172

173173
def _get_token(self):
@@ -314,6 +314,7 @@ class CloudCluster():
314314
Creates and deletes a cluster. Will also create a new namespace for
315315
that cluster.
316316
"""
317+
_cid_filename = '.cluster_id'
317318

318319
CHECK_TIMEOUT_SEC = 3600
319320
CHECK_BACKOFF_SEC = 60.0
@@ -410,6 +411,9 @@ def __init__(self,
410411
if not self.utils.rpk_plugin_uninstall('byoc'):
411412
self.utils.rpk_plugin_uninstall('byoc', sudo=True)
412413

414+
# save context
415+
self._ctx = context
416+
413417
@property
414418
def cluster_id(self):
415419
"""
@@ -684,10 +688,33 @@ def update_cluster_acls(self, superuser):
684688

685689
return
686690

691+
@property
692+
def _cid_file(self):
693+
return os.path.join(self._ctx.session_context.results_dir,
694+
self._cid_filename)
695+
687696
def _cluster_id_updated(self, uuid):
688697
_cluster = self.cloudv2._http_get(endpoint=f'/api/v1/clusters/{uuid}')
689698
return _cluster['id'] != uuid
690699

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+
691718
def _wait_for_cluster_id(self, uuid):
692719
wait_until(lambda: self._cluster_id_updated(uuid),
693720
timeout_sec=120,
@@ -707,10 +734,14 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
707734
:param config_profile_name: config profile name, default 'tier-1-aws'
708735
:return: clusterId, e.g. 'cimuhgmdcaa1uc1jtabc'
709736
"""
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
711742
if not self.isPublicNetwork:
712743
self.current.connection_type = 'private'
713-
744+
# Prepare the cluster
714745
if self.config.id != '':
715746
# Cluster already exist
716747
# Just load needed info to create peering
@@ -769,12 +800,13 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
769800
# the workslow, so just wait
770801
_cluster_id = self._wait_for_cluster_id(r['id'])
771802
# Handle byoc creation
772-
# Login with out creds
803+
# Login without saving creds
773804
self.utils.rpk_cloud_login(self.config.oauth_client_id,
774805
self.config.oauth_client_secret)
775806
# Install proper plugin
776807
self.utils.rpk_cloud_byoc_install(_cluster_id)
777808
# Kick off cluster creation
809+
# Timeout for this is half an hour as this is only agent
778810
self.utils.rpk_cloud_apply(_cluster_id)
779811

780812
# In case of FMC, just poll the cluster and wait when ready
@@ -790,6 +822,11 @@ def create(self, superuser: Optional[SaslCredentials] = None) -> str:
790822
err_msg='Unable to deterimine readiness '
791823
f'of cloud cluster {self.current.name}')
792824

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+
793830
self.config.id, self.current.network_id = \
794831
self._get_cluster_id_and_network_id()
795832

0 commit comments

Comments
 (0)