Skip to content

Commit

Permalink
tests: implement RedpandaServiceCloudv2.start()
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhsu committed May 11, 2023
1 parent 66cbfe5 commit 3d33ba4
Showing 1 changed file with 115 additions and 6 deletions.
121 changes: 115 additions & 6 deletions tests/rptest/services/redpanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,15 +1119,124 @@ def __init__(self, context, num_brokers):
target = os.getenv('TARGET')
self._kubectl = KubectlTool(self, ['tsh', 'ssh', target])

self._cloudv2_cluster_name = f'rp-ducktape-{uuid.uuid1()}'

# TODO get these values from ducktape --cluster-file
self._cloudv2_oauth_url = os.getenv('RP_DUCKTAPE_CLOUDV2_OAUTH_URL')
self._cloudv2_oauth_client_id = os.getenv(
'RP_DUCKTAPE_CLOUDV2_OAUTH_CLIENT_ID')
self._cloudv2_oauth_client_secret = os.getenv(
'RP_DUCKTAPE_CLOUDV2_CLIENT_SECRET')
self._cloudv2_oauth_audience = os.getenv(
'RP_DUCKTAPE_CLOUDV2_AUDIENCE')
self._cloudv2_api_url = os.getenv('RP_DUCKTAPE_CLOUDV2_API_URL')
self._cloudv2_namespace_uuid = os.getenv(
'RP_DUCKTAPE_CLOUDV2_NAMESPACE_UUID')

def start_node(self, node, **kwargs):
pass

@staticmethod
def _cluster_ready(token, namespaceUuid, name):
logger.debug(f'checking readiness of cloudv2 cluster {name}')
params = {'namespaceUuid': namespaceUuid}
headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/json'
}
response = requests.get(f'{self.__cloudv2_api_url}/api/v1/clusters',
params=params,
headers=headers)
response.raise_for_status()
clusters = response.json()
for c in clusters:
if c['name'] == name:
if c['state'] == 'ready':
return True
return False

def _get_oauth_token():
"""
Install the helm chart which will launch the entire cluster. If
the cluster is already running, then noop. This function will not
return until redpanda appears to have started successfully. If
redpanda does not start within a timeout period the service will
fail to start.
Returns token from oauth server.
"""
pass

headers = {'Content-Type': "application/x-www-form-urlencoded"}
data = {
'grant_type': 'client_credentials',
'client_id': self._cloudv2_oauth_client_id,
'client_secret': self._cloudv2_oauth_client_secret,
'audience': self._cloudv2_oauth_audience
}
r = requests.post(f'{self._cloudv2_oauth_url}/oauth/token',
headers=headers,
data=data)
r.raise_for_status()
j = r.json()
return j['access_token']

def _create_cluster(token):
"""
Creates a cloudv2 cluster but does not wait for it to be ready,
which could take several minutes.
"""

headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/json'
}

# TODO get these values from ducktape --cluster-file
body = {
"namespaceUuid": self._cloudv2_namespace_uuid,
"connectionType": "public",
"network": {
"displayName": f"public-network-{self._cloudv2_cluster_name}",
"spec": {
"deploymentType": "FMC",
"provider": "AWS",
"regionId": "ccpfuvec6lhdao925q10",
"zones": ["usw2-az1"],
"installPackVersion": "23.1.20230502184729",
"cidr": "10.0.0.0/16"
}
},
"cluster": {
"name": self._cloudv2_cluster_name,
"productId": "cgrdrd9jiflmsknn2nl0",
"spec": {
"clusterType": "FMC",
"provider": "AWS",
"region": "us-west-2",
"isMultiAz": False,
"zones": ["usw2-az1"],
"installPackVersion": "23.1.20230502184729",
"connectors": {
"enabled": True
},
"networkId": ""
}
}
}

r = requests.post(
f'{self._cloudv2_api_url}/api/v1/workflows/network-cluster',
json=body,
headers=headers)
r.raise_for_status()

def start(self, **kwargs):
token = self._get_oauth_token()
self._create_cluster(token)

# periodically check if cluster is ready to be used
wait_until(
lambda: RedpandaServiceCloudv2._cluster_ready(
token, self._cloudv2_namespace_uuid, self._cloudv2_cluster_name
),
timeout_sec=3600,
backoff_sec=5.0,
err_msg=f'Unable to deterimine readiness of cloudv2 cluster {name}'
)

def stop_node(self, node, **kwargs):
"""
Expand Down

0 comments on commit 3d33ba4

Please sign in to comment.