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

showing details about failed respawn/deploy in cli #559

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 24 additions & 2 deletions senza/spotinst/components/elastigroup_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import requests
import json
import boto3
from clickclick import warning, error

from senza.components.elastigroup import ELASTIGROUP_RESOURCE_TYPE
from requests.exceptions import HTTPError

SPOTINST_API_URL = 'https://api.spotinst.io'

Expand Down Expand Up @@ -156,7 +158,9 @@ def deploy(batch_size=20, grace_period=300, strategy=DEPLOY_STRATEGY_REPLACE,
'{}/aws/ec2/group/{}/roll?accountId={}'.format(SPOTINST_API_URL, elastigroup_id,
spotinst_account_data.account_id),
headers=headers, timeout=(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT), data=json.dumps(body))
response.raise_for_status()

raise_for_status(response, elastigroup_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test to validate this behavior?


data = response.json()
deploys = data.get("response", {}).get("items", [])

Expand All @@ -178,8 +182,26 @@ def deploy_status(deploy_id, elastigroup_id, spotinst_account_data):
'{}/aws/ec2/group/{}/roll/{}?accountId={}'.format(SPOTINST_API_URL, elastigroup_id, deploy_id,
spotinst_account_data.account_id),
headers=headers, timeout=(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT))
response.raise_for_status()

raise_for_status(response, elastigroup_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect deploy status to not fail because a deploy is already in progress. Did you observe such a behavior?


data = response.json()
deploys = data.get("response", {}).get("items", [])

return deploys


def raise_for_status(response, elastigroup_id):
try:
response.raise_for_status()
except HTTPError:

status = response.json().get("response", {}).get("status")
details = response.json().get("response", {}).get("errors")[0]

error("HTTP Error: {}[{}]".format(status.get("message"), status.get("code")))
error("{}[{}]".format(details.get("message"), details.get("code")))

if details.get("code") == "DEPLOYMENT_ALREADY_IN_PROGRESS":
warning("An older deploy is still running, check on SpotInst console deployments tab for elastigroup: [{}]."
.format(elastigroup_id))