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

Update checkout_account.py to not reuse connections #700

Merged
merged 1 commit into from
Apr 4, 2019
Merged
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: 15 additions & 11 deletions hack/checkout_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
RESOURCE_TYPE = "aws-account"
USER = "cluster-api-provider-aws"

def post_request(conn, input_state = "free"):
def post_request(host, input_state = "clean"):
conn = httplib.HTTPConnection(host)
conn.request("POST", "/acquire?%s" % urllib.urlencode({
'type': RESOURCE_TYPE,
'owner': USER,
Expand All @@ -36,22 +37,25 @@ def post_request(conn, input_state = "free"):
})

)
return conn.getresponse()
resp = conn.getresponse()
status = resp.status
reason = resp.reason
body = resp.read()
conn.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fairly certain that if you close the connection before reading the response (done below in json.load(resp)), that you won't get any of the data.

Copy link
Member Author

Choose a reason for hiding this comment

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

arrgh, of course it would behave that way 😂 Let me fix up to return the json.

return status, reason, body

if __name__ == "__main__":
conn = httplib.HTTPConnection(BOSKOS_HOST)

resp = post_request(conn)
status, reason, result = post_request(BOSKOS_HOST)
# we're working around an issue with the data in boskos.
# We'll remove the code that tries both free and clean once all the data is good.
if resp.status == 404:
resp = post_request(conn, "clean")
# Afterwards we should just check for free
if status == 404:
status, reason, result = post_request(BOSKOS_HOST, "free")

if resp.status != 200:
sys.exit("Got invalid response %d: %s" % (resp.status, resp.reason))
if status != 200:
sys.exit("Got invalid response %d: %s" % (status, reason))

body = json.load(resp)
conn.close()
body = json.load(result)
print 'export BOSKOS_RESOURCE_NAME="%s";' % body['name']
print 'export AWS_ACCESS_KEY_ID="%s";' % body['userdata']['access-key-id']
print 'export AWS_SECRET_ACCESS_KEY="%s";' % body['userdata']['secret-access-key']
Expand Down