diff --git a/pytests/Capella/RestAPIv4/AppEndpoints/app_endpoint_online.py b/pytests/Capella/RestAPIv4/AppEndpoints/app_endpoint_online.py index fb51ecc0f..298b36328 100644 --- a/pytests/Capella/RestAPIv4/AppEndpoints/app_endpoint_online.py +++ b/pytests/Capella/RestAPIv4/AppEndpoints/app_endpoint_online.py @@ -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() diff --git a/pytests/Capella/RestAPIv4/AppEndpoints/create_app_endpoints.py b/pytests/Capella/RestAPIv4/AppEndpoints/create_app_endpoints.py index 123f955e5..6b96803f7 100644 --- a/pytests/Capella/RestAPIv4/AppEndpoints/create_app_endpoints.py +++ b/pytests/Capella/RestAPIv4/AppEndpoints/create_app_endpoints.py @@ -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() diff --git a/pytests/Capella/RestAPIv4/AppEndpoints/get_app_endpoints.py b/pytests/Capella/RestAPIv4/AppEndpoints/get_app_endpoints.py index a907ce5e4..074261d76 100644 --- a/pytests/Capella/RestAPIv4/AppEndpoints/get_app_endpoints.py +++ b/pytests/Capella/RestAPIv4/AppEndpoints/get_app_endpoints.py @@ -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): diff --git a/pytests/Capella/RestAPIv4/AppEndpoints/update_app_endpoints.py b/pytests/Capella/RestAPIv4/AppEndpoints/update_app_endpoints.py index 7045964ee..2f6c38a10 100644 --- a/pytests/Capella/RestAPIv4/AppEndpoints/update_app_endpoints.py +++ b/pytests/Capella/RestAPIv4/AppEndpoints/update_app_endpoints.py @@ -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() diff --git a/pytests/Capella/RestAPIv4/AppService/get_app_service.py b/pytests/Capella/RestAPIv4/AppService/get_app_service.py index 085880eb2..ee42903b4 100644 --- a/pytests/Capella/RestAPIv4/AppService/get_app_service.py +++ b/pytests/Capella/RestAPIv4/AppService/get_app_service.py @@ -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): @@ -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( @@ -99,6 +57,7 @@ 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() @@ -106,56 +65,6 @@ def setUp(self, nomenclature="App_Service_Get"): 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() diff --git a/pytests/Capella/RestAPIv4/AppServicesAuditLogging/get_app_endpoint_audit_log_configs.py b/pytests/Capella/RestAPIv4/AppServicesAuditLogging/get_app_endpoint_audit_log_configs.py index 3f157da96..1d699886c 100644 --- a/pytests/Capella/RestAPIv4/AppServicesAuditLogging/get_app_endpoint_audit_log_configs.py +++ b/pytests/Capella/RestAPIv4/AppServicesAuditLogging/get_app_endpoint_audit_log_configs.py @@ -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": [ diff --git a/pytests/Capella/RestAPIv4/AppServicesAuditLogging/list_app_service_audit_log_events.py b/pytests/Capella/RestAPIv4/AppServicesAuditLogging/list_app_service_audit_log_events.py index 62cd3e390..8423ab207 100644 --- a/pytests/Capella/RestAPIv4/AppServicesAuditLogging/list_app_service_audit_log_events.py +++ b/pytests/Capella/RestAPIv4/AppServicesAuditLogging/list_app_service_audit_log_events.py @@ -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()