From ef438a21f762f5f60e61ae4e46e4bac9af6c6526 Mon Sep 17 00:00:00 2001 From: anaik91 Date: Fri, 22 Sep 2023 14:36:49 +0530 Subject: [PATCH 1/2] fix: added minor fixes to api re-deployment --- .gitignore | 3 +- tools/target-server-validator/apigee_utils.py | 61 +++++++++++-------- tools/target-server-validator/main.py | 3 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 05607f38d..123079e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/node_modules/** **/generated/** - +target/ +export/ .settings .project .classpath diff --git a/tools/target-server-validator/apigee_utils.py b/tools/target-server-validator/apigee_utils.py index 89edd3ebe..eb8069d52 100644 --- a/tools/target-server-validator/apigee_utils.py +++ b/tools/target-server-validator/apigee_utils.py @@ -115,9 +115,10 @@ def get_api(self, api_name): headers = self.auth_header.copy() response = requests.request("GET", url, headers=headers) if response.status_code == 200: - return True + revision = response.json().get('revision', ['1']) + return True, revision else: - return False + return False, None def create_api(self, api_name, proxy_bundle_path): url = f"{self.baseurl}/apis?action=import&name={api_name}&validate=true" # noqa @@ -175,16 +176,18 @@ def deploy_api(self, env, api_name, api_rev): print(response.text) return False - def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_rev=1, api_force_redeploy=False): # noqa + def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_force_redeploy=False): # noqa api_deployment_retry = 60 api_deployment_sleep = 5 api_deployment_retry_count = 0 api_exists = False - if self.get_api(api_name): + get_api_status, api_revs = self.get_api(api_name) + if get_api_status: + api_exists = True + api_rev = api_revs[-1] print( - f"Proxy with name {api_name} already exists in Apigee Org {self.org}" # noqa + f"Proxy with name {api_name} with revision {api_rev} already exists in Apigee Org {self.org}" # noqa ) - api_exists = True if api_force_redeploy: api_exists = False if not api_exists: @@ -198,29 +201,35 @@ def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_rev=1, api_for print(f"ERROR : Proxy {api_name} import failed !!! ") return False if api_exists: - if self.deploy_api(env, api_name, api_rev): - print( - f"Proxy with name {api_name} has been deployed to {env} in Apigee Org {self.org}" # noqa - ) - while api_deployment_retry_count < api_deployment_retry: - if self.get_api_revisions_deployment( + if self.get_api_revisions_deployment( env, api_name, api_rev ): - print( - f"Proxy {api_name} active in runtime after {api_deployment_retry_count*api_deployment_sleep} seconds " # noqa - ) - return True - else: - print( - f"Checking API deployment status in {api_deployment_sleep} seconds" # noqa - ) - sleep(api_deployment_sleep) - api_deployment_retry_count += 1 + print(f"INFO : Proxy {api_name} already active in to {env} in Apigee Org {self.org} !") # noqa + return True else: - print( - f"ERROR : Proxy deployment to {env} in Apigee Org {self.org} Failed !!" # noqa - ) - return False + if self.deploy_api(env, api_name, api_rev): + print( + f"Proxy with name {api_name} has been deployed to {env} in Apigee Org {self.org}" # noqa + ) + while api_deployment_retry_count < api_deployment_retry: + if self.get_api_revisions_deployment( + env, api_name, api_rev + ): + print( + f"Proxy {api_name} active in runtime after {api_deployment_retry_count*api_deployment_sleep} seconds " # noqa + ) + return True + else: + print( + f"Checking API deployment status in {api_deployment_sleep} seconds" # noqa + ) + sleep(api_deployment_sleep) + api_deployment_retry_count += 1 + else: + print( + f"ERROR : Proxy deployment to {env} in Apigee Org {self.org} Failed !!" # noqa + ) + return False def get_api_vhost(self, vhost_name, env): if self.apigee_type == "opdk": diff --git a/tools/target-server-validator/main.py b/tools/target-server-validator/main.py index 72410441d..ba94ee12c 100644 --- a/tools/target-server-validator/main.py +++ b/tools/target-server-validator/main.py @@ -147,7 +147,6 @@ def main(): cfg["validation"]["api_env"], cfg["validation"]["api_name"], f"{bundle_path}/{cfg['validation']['api_name']}.zip", - 1, cfg["validation"].getboolean("api_force_redeploy", False) ): print(f"Proxy: {cfg['validation']['api_name']} deployment failed.") @@ -162,7 +161,7 @@ def main(): ) vhost_domain_name = cfg["validation"]["api_hostname"] vhost_ip = cfg["validation"].get("api_ip", "").strip() - api_url = f"https://{vhost_domain_name}/validate_target_server" + api_url = f"https://{vhost_domain_name}/validate-target-server" final_report = [] _cached_hosts = {} From a5c11b23f01531dbc6e44f3a74b935d014bba268 Mon Sep 17 00:00:00 2001 From: anaik91 Date: Mon, 25 Sep 2023 16:12:21 +0530 Subject: [PATCH 2/2] feat: updated gitingore --- .gitignore | 2 -- tools/target-server-validator/.gitignore | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 tools/target-server-validator/.gitignore diff --git a/.gitignore b/.gitignore index 123079e8d..37eb280b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ **/node_modules/** **/generated/** -target/ -export/ .settings .project .classpath diff --git a/tools/target-server-validator/.gitignore b/tools/target-server-validator/.gitignore new file mode 100644 index 000000000..3f7d48a59 --- /dev/null +++ b/tools/target-server-validator/.gitignore @@ -0,0 +1,2 @@ +callout/target/ +export/