diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2015-03-25 15:54:19 +0000 |
---|---|---|
committer | Daniel Watkins <daniel.watkins@canonical.com> | 2015-03-25 15:54:19 +0000 |
commit | d52feae7ad38670964edebb0eea5db2c8c80f760 (patch) | |
tree | 103bb23c3dbe8f71486406daf4438a37048b94d7 /cloudinit/sources | |
parent | 1828ac3fa151ec7ff761b34305ed5fb85a9020d1 (diff) | |
download | vyos-cloud-init-d52feae7ad38670964edebb0eea5db2c8c80f760.tar.gz vyos-cloud-init-d52feae7ad38670964edebb0eea5db2c8c80f760.zip |
Ensure that the serial console is always closed.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/DataSourceSmartOS.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index 61dd044f..237fc140 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -30,9 +30,11 @@ # Comments with "@datadictionary" are snippets of the definition import binascii +import contextlib import os import random import re + import serial from cloudinit import log as logging @@ -371,11 +373,10 @@ def query_data(noun, seed_device, seed_timeout, strip=False, default=None, if not noun: return False - ser = get_serial(seed_device, seed_timeout) + with contextlib.closing(get_serial(seed_device, seed_timeout)) as ser: + client = JoyentMetadataClient(ser) + response = client.get_metadata(noun) - client = JoyentMetadataClient(ser) - response = client.get_metadata(noun) - ser.close() if response is None: return default |