Skip to content

Commit

Permalink
App Services v4 tests stablized
Browse files Browse the repository at this point in the history
Change-Id: Ide5ea4edf9ac14a379eff66d6b6414c2dda96a14
Reviewed-on: https://review.couchbase.org/c/TAF/+/222398
Tested-by: VIPUL BHARDWAJ <[email protected]>
Reviewed-by: VIPUL BHARDWAJ <[email protected]>
Reviewed-by: <[email protected]>
  • Loading branch information
vipbhardwaj committed Jan 27, 2025
1 parent bb717cb commit 81b0ce2
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 98 deletions.
13 changes: 13 additions & 0 deletions pytests/Capella/RestAPIv4/AppEndpoints/app_endpoint_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ class PostActivationStatus(GetAppEndpoints):

def setUp(self, nomenclature="ActivationState_Post"):
GetAppEndpoints.setUp(self, nomenclature)
result = self.capellaAPI.cluster_ops_apis.resume_app_endpoint(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id, self.appEndpointName)
if result.status_code == 429:
self.handle_rate_limit(int(result.headers["Retry-After"]))
result = self.capellaAPI.cluster_ops_apis.resume_app_endpoint(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id, self.appEndpointName)
if result.status_code != 202:
self.log.error(result.content)
self.tearDown()
self.fail("Failed to resume App Endpoint")
self.log.info("App Endpoint resumed successfully")

def tearDown(self):
super(PostActivationStatus, self).tearDown()
Expand Down
12 changes: 12 additions & 0 deletions pytests/Capella/RestAPIv4/AppEndpoints/create_app_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ def test_payload(self):
"message": "The bucket name is not valid. A bucket "
"name can not be empty."
}
else:
testcase["expected_status_code"] = 400
testcase["expected_error"] = {
"code": 400,
"hint": "Please review your request and ensure that "
"all required parameters are correctly "
"provided.",
"httpStatusCode": 400,
"message": "The bucket name provided is not valid. "
"The maximum length of the bucket name can "
"be (100) characters."
}
testcases.append(testcase)

failures = list()
Expand Down
24 changes: 24 additions & 0 deletions pytests/Capella/RestAPIv4/AppEndpoints/get_app_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ def setUp(self, nomenclature="AppEndpoints_GET"):
},
"isRequireResync": True
}
result = self.capellaAPI.cluster_ops_apis.create_app_endpoint(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id,
self.expected_res["name"], self.expected_res["deltaSync"],
self.expected_res["bucket"], self.expected_res["scopes"],
self.expected_res["userXattrKey"])
if result.status_code == 429:
self.handle_rate_limit(int(result.headers["Retry-After"]))
result = self.capellaAPI.cluster_ops_apis.create_app_endpoint(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id,
self.expected_res["name"], self.expected_res["deltaSync"],
self.expected_res["bucket"], self.expected_res["scopes"],
self.expected_res["userXattrKey"])
if result.status_code == 412:
self.log.debug("App endpoint {} already exists".format(
self.expected_res["name"]))
self.appEndpointName = self.expected_res["name"]
elif result.status_code != 201:
self.log.error(result.content)
self.tearDown()
self.fail("!!!...Creating App Endpoint failed...!!!")
self.log.info("Created App Endpoint: {} successfully".format(
self.expected_res["name"]))
self.appEndpointName = self.expected_res["name"]

def tearDown(self):
Expand Down
12 changes: 12 additions & 0 deletions pytests/Capella/RestAPIv4/AppEndpoints/update_app_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ def test_payload(self):
"httpStatusCode": 403,
"message": "Access Denied."
}
else:
testcase["expected_status_code"] = 400
testcase["expected_error"] = {
"code": 400,
"hint": "Please review your request and ensure that "
"all required parameters are correctly "
"provided.",
"httpStatusCode": 400,
"message": "The bucket name provided is not valid. "
"The maximum length of the bucket name can "
"be (100) characters."
}
testcases.append(testcase)

failures = list()
Expand Down
93 changes: 1 addition & 92 deletions pytests/Capella/RestAPIv4/AppService/get_app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import time
from pytests.Capella.RestAPIv4.Clusters.get_clusters import GetCluster
from capellaAPI.capella.dedicated.CapellaAPI import CapellaAPI

class GetAppService(GetCluster):

Expand Down Expand Up @@ -40,47 +39,6 @@ def setUp(self, nomenclature="App_Service_Get"):
self.fail("!!!...App Svc didn't deploy within 30mins...!!!")
self.log.info("Successfully deployed App Svc.")

self.capellaAPI_v2 = CapellaAPI(
"https://" + self.url, "", "", self.user, self.passwd)

# If an app endpoint already exists, don't bother creating another one
self.log.debug("...Checking if an App Endpoint already exists...")
res = self.capellaAPI_v2.get_sgw_databases(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id)
self.log.debug("Res: {}".format(res.content))
try:
retry = 1
while res.json()["errorType"] == "AppServiceConnectionRefused" \
and retry < 6:
self.log.warning(res.json()["message"])
retry += 1
self.log.debug("...Waiting for 5 seconds before retrying...")
time.sleep(5)
res = self.capellaAPI_v2.get_sgw_databases(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id)
if res.json()["errorType"] == "EntityStateInvalid":
self.log.warning("App service is off, so skipping the App "
"Endpoint gibberish")
return
except Exception as e:
self.log.warning("Exception: {}".format(e))
self.log.error("Exception encountered in conversion of res to "
"JSON / or fetching the key `errorType` from "
"JSONified res.")
if res.status_code != 200:
self.log.error("Error: {}".format(res.content))
self.tearDown()
self.fail("!!!...Listing App Endpoints Failed...!!!")
appEndpoints = res.json()["data"]
if len(appEndpoints):
self.appEndpointName = appEndpoints[0]["data"]["name"]
self.log.info("The App Endpoint: {}, is already present inside "
"the App Service.".format(self.appEndpointName))
return

# Create a bucket for the App endpoint to reside in
self.log.debug("...Creating a bucket for the App Endpoint to be "
"linked to...")
res = self.capellaAPI.cluster_ops_apis.create_bucket(
Expand All @@ -99,63 +57,14 @@ def setUp(self, nomenclature="App_Service_Get"):
("The bucket name provided already exists. Please "
"choose a different name for the bucket."):
self.log.warning("...Bucket already exists...")
return
except (Exception,):
self.log.error("Error : {}".format(res.content))
self.tearDown()
self.fail("!!!..Bucket creation failed...!!!")
self.app_endpoint_bucket_id = res.json()['id']
self.app_endpoint_bucket_name = "bucketForAppEndpoint"

# Allow my IP for this App Service.
self.log.debug("Adding current IP in the allow list for the APP SVC")
res = self.capellaAPI_v2.allow_my_ip_sgw(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id)
if res.status_code != 200:
self.log.error(res.content)
self.tearDown()
self.fail("!!!...Failed to allow my IP...!!!")

# Create an App Endpoint.
self.log.debug("...Creating a App Endpoint inside the App Service: "
"{}...".format(self.app_service_id))
res = self.capellaAPI_v2.create_sgw_database(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id, {
"name": "test_vipul",
"bucket": "bucketForAppEndpoint",
"delta_sync": False,
"scopes": {
"_default": {
"collections": {
"_default": {
"sync": "",
"import_filter": ""
}
}
}
}
}
)
if res.status_code != 200:
self.log.error("Error: {}".format(res.content))
self.tearDown()
self.fail("!!!...App Endpoint creation Failed...!!!")
self.log.info("App Endpoint created successfully.")
self.appEndpointName = "test_vipul"

# Resume App Endpoint
self.log.debug("...Starting the App Endpoint: {}..."
.format(self.appEndpointName))
res = self.capellaAPI_v2.resume_sgw_database(
self.organisation_id, self.project_id, self.cluster_id,
self.app_service_id, self.appEndpointName)
if res.status_code != 200:
self.log.error("Error: {}".format(res.content))
self.tearDown()
self.fail("!!!...App Endpoint resume resume request failed...!!!")
self.log.info("Successfully resumed App Endpoint.")

def tearDown(self):
self.update_auth_with_api_token(self.curr_owner_key)
super(GetAppService, self).tearDown()
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
@author: Created using cbRAT cbModule by Vipul Bhardwaj
"""

from pytests.Capella.RestAPIv4.AppService.get_app_service import GetAppService
from pytests.Capella.RestAPIv4.AppEndpoints.app_endpoint_online \
import PostActivationStatus


class GetAuditLogConfig(GetAppService):
class GetAuditLogConfig(PostActivationStatus):

def setUp(self, nomenclature="AppServicesAuditLogging_GET"):
GetAppService.setUp(self, nomenclature)
PostActivationStatus.setUp(self, nomenclature)
self.expected_res = {
"auditEnabled": True,
"enabledEventIds": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
@author: Created using cbRAT cbModule by Vipul Bhardwaj
"""

from pytests.Capella.RestAPIv4.AppService.get_app_service import GetAppService
from pytests.Capella.RestAPIv4.AppEndpoints.app_endpoint_online \
import PostActivationStatus


class ListAuditLogEvents(GetAppService):
class ListAuditLogEvents(PostActivationStatus):

def setUp(self, nomenclature="AppServicesAuditLogging_GET"):
GetAppService.setUp(self, nomenclature)
PostActivationStatus.setUp(self, nomenclature)

def tearDown(self):
super(ListAuditLogEvents, self).tearDown()
Expand Down

0 comments on commit 81b0ce2

Please sign in to comment.