From 72bebae0b10526cf944de26722fe7326343e59bd Mon Sep 17 00:00:00 2001 From: Jason DeTiberus <detiberusj@vmware.com> Date: Thu, 4 Apr 2019 11:32:50 -0400 Subject: [PATCH] Update checkout_account.py to not reuse connections (#700) --- hack/checkout_account.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hack/checkout_account.py b/hack/checkout_account.py index d1dbaba741..c8d8da6fac 100755 --- a/hack/checkout_account.py +++ b/hack/checkout_account.py @@ -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, @@ -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() + 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']