From c4ff1ea7460bae67d1e1c1a2d842e8ccf995c433 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Thu, 4 Apr 2019 10:28:05 -0400 Subject: [PATCH] Update checkout_account.py to not reuse connections --- 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']