Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added minor fixes to api re-deployment #703

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
**/node_modules/**
**/generated/**

.settings
.project
.classpath
Expand Down
2 changes: 2 additions & 0 deletions tools/target-server-validator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
callout/target/
export/
61 changes: 35 additions & 26 deletions tools/target-server-validator/apigee_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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":
Expand Down
3 changes: 1 addition & 2 deletions tools/target-server-validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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 = {}

Expand Down
Loading