← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~daniel-thewatkins/cloud-init/fix-smartos into lp:cloud-init

 

Dan Watkins has proposed merging lp:~daniel-thewatkins/cloud-init/fix-smartos into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/fix-smartos/+merge/252874

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.
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~daniel-thewatkins/cloud-init/fix-smartos into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceSmartOS.py'
--- cloudinit/sources/DataSourceSmartOS.py	2015-01-27 20:03:52 +0000
+++ cloudinit/sources/DataSourceSmartOS.py	2015-03-13 10:20:28 +0000
@@ -319,7 +319,8 @@
         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 @@
         return default
 
     while not eom_found:
-        m = ser.readline()
+        m = ser.readline().decode('ascii')
         if m.rstrip() == ".":
             eom_found = True
         else:

=== modified file 'tests/unittests/test_datasource/test_smartos.py'
--- tests/unittests/test_datasource/test_smartos.py	2015-01-27 20:03:52 +0000
+++ tests/unittests/test_datasource/test_smartos.py	2015-03-13 10:20:28 +0000
@@ -36,6 +36,8 @@
 import stat
 import uuid
 
+import six
+
 
 MOCK_RETURNS = {
     'hostname': 'test-host',
@@ -78,24 +80,27 @@
         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:


Follow ups