summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-03-17 09:09:11 -0400
committerScott Moser <smoser@ubuntu.com>2015-03-17 09:09:11 -0400
commitad820a9465642fa13aa6f75e5efb3fbe3059dedc (patch)
tree5460097b13a7a67322a2773ae695784bed3e773c
parent516af9ba927dd9b4dcc3461f8a8bb6883c61c036 (diff)
parentc8a7b446de26c6bc19df1b8bb7d2b39cb9487749 (diff)
downloadvyos-cloud-init-ad820a9465642fa13aa6f75e5efb3fbe3059dedc.tar.gz
vyos-cloud-init-ad820a9465642fa13aa6f75e5efb3fbe3059dedc.zip
SmartOS: fixes for python3 reading from serial device.
We were hitting exceptions when writing to the SmartOS serial console and, once that was fixed, we were hanging permanently waiting for b"." == "." to be true. This fixes both of those issues.
-rw-r--r--cloudinit/sources/DataSourceSmartOS.py5
-rw-r--r--tests/unittests/test_datasource/test_smartos.py15
2 files changed, 13 insertions, 7 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index 9d48beab..896fde3f 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -319,7 +319,8 @@ def query_data(noun, seed_device, seed_timeout, strip=False, default=None,
return False
ser = get_serial(seed_device, seed_timeout)
- ser.write("GET %s\n" % noun.rstrip())
+ request_line = "GET %s\n" % noun.rstrip()
+ ser.write(request_line.encode('ascii'))
status = str(ser.readline()).rstrip()
response = []
eom_found = False
@@ -329,7 +330,7 @@ def query_data(noun, seed_device, seed_timeout, strip=False, default=None,
return default
while not eom_found:
- m = ser.readline()
+ m = ser.readline().decode('ascii')
if m.rstrip() == ".":
eom_found = True
else:
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 8b62b1b1..cb0ab984 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -36,6 +36,8 @@ import tempfile
import stat
import uuid
+import six
+
MOCK_RETURNS = {
'hostname': 'test-host',
@@ -78,24 +80,27 @@ class MockSerial(object):
return True
def write(self, line):
- line = line.replace('GET ', '')
+ if not isinstance(line, six.binary_type):
+ raise TypeError("Should be writing binary lines.")
+ line = line.decode('ascii').replace('GET ', '')
self.last = line.rstrip()
def readline(self):
if self.new:
self.new = False
if self.last in self.mockdata:
- return 'SUCCESS\n'
+ line = 'SUCCESS\n'
else:
- return 'NOTFOUND %s\n' % self.last
+ line = 'NOTFOUND %s\n' % self.last
- if self.last in self.mockdata:
+ elif self.last in self.mockdata:
if not self.mocked_out:
self.mocked_out = [x for x in self._format_out()]
if len(self.mocked_out) > self.count:
self.count += 1
- return self.mocked_out[self.count - 1]
+ line = self.mocked_out[self.count - 1]
+ return line.encode('ascii')
def _format_out(self):
if self.last in self.mockdata: