Ensure that the serial console is always closed.
This commit is contained in:
parent
4a44c1bb73
commit
cbff834a01
@ -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
|
||||
|
||||
|
@ -409,6 +409,18 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
|
||||
self.assertEqual(dsrc.device_name_to_device('FOO'),
|
||||
mydscfg['disk_aliases']['FOO'])
|
||||
|
||||
@mock.patch('cloudinit.sources.DataSourceSmartOS.JoyentMetadataClient')
|
||||
@mock.patch('cloudinit.sources.DataSourceSmartOS.get_serial')
|
||||
def test_serial_console_closed_on_error(self, get_serial, metadata_client):
|
||||
class OurException(Exception):
|
||||
pass
|
||||
metadata_client.side_effect = OurException
|
||||
try:
|
||||
DataSourceSmartOS.query_data('noun', 'device', 0)
|
||||
except OurException:
|
||||
pass
|
||||
self.assertEqual(1, get_serial.return_value.close.call_count)
|
||||
|
||||
|
||||
def apply_patches(patches):
|
||||
ret = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user