diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2015-02-23 09:22:50 +0000 |
---|---|---|
committer | Daniel Watkins <daniel.watkins@canonical.com> | 2015-02-23 09:22:50 +0000 |
commit | ef84bd214a1d5e0b922c0dd38096f694f8ff406e (patch) | |
tree | b4e0a083cfac9fcb42a887712a8a71aa3147e426 | |
parent | f8d9ebbe3743bcada75bc1a980b49f493e2da2f1 (diff) | |
download | vyos-cloud-init-ef84bd214a1d5e0b922c0dd38096f694f8ff406e.tar.gz vyos-cloud-init-ef84bd214a1d5e0b922c0dd38096f694f8ff406e.zip |
Always close the password server connection, even on failure.
-rw-r--r-- | cloudinit/sources/DataSourceCloudStack.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py index 0c3c51c0..996076b1 100644 --- a/cloudinit/sources/DataSourceCloudStack.py +++ b/cloudinit/sources/DataSourceCloudStack.py @@ -66,10 +66,12 @@ class CloudStackPasswordServerClient(object): # Because we're reading off the socket directly, we can't re-use the # connection. conn = http_client.HTTPConnection(self.virtual_router_address, 8080) - conn.request('GET', '', headers={'DomU_Request': domu_request}) - conn.sock.settimeout(30) - output = conn.sock.recv(1024).decode('utf-8').strip() - conn.close() + try: + conn.request('GET', '', headers={'DomU_Request': domu_request}) + conn.sock.settimeout(30) + output = conn.sock.recv(1024).decode('utf-8').strip() + finally: + conn.close() return output def get_password(self): |