Merge lp:~daniel-thewatkins/cloud-init/fix-smartos into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Dan Watkins on 2015-03-13
Status: Merged
Merged at revision: 1083
Proposed branch: lp:~daniel-thewatkins/cloud-init/fix-smartos
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 68 lines (+13/-7)
2 files modified
cloudinit/sources/DataSourceSmartOS.py (+3/-2)
tests/unittests/test_datasource/test_smartos.py (+10/-5)
To merge this branch: bzr merge lp:~daniel-thewatkins/cloud-init/fix-smartos
Reviewer Review Type Date Requested Status
cloud-init commiters 2015-03-13 Pending
Review via email: mp+252874@code.launchpad.net

Description of the Change

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.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/sources/DataSourceSmartOS.py'
2--- cloudinit/sources/DataSourceSmartOS.py 2015-01-27 20:03:52 +0000
3+++ cloudinit/sources/DataSourceSmartOS.py 2015-03-13 10:20:28 +0000
4@@ -319,7 +319,8 @@
5 return False
6
7 ser = get_serial(seed_device, seed_timeout)
8- ser.write("GET %s\n" % noun.rstrip())
9+ request_line = "GET %s\n" % noun.rstrip()
10+ ser.write(request_line.encode('ascii'))
11 status = str(ser.readline()).rstrip()
12 response = []
13 eom_found = False
14@@ -329,7 +330,7 @@
15 return default
16
17 while not eom_found:
18- m = ser.readline()
19+ m = ser.readline().decode('ascii')
20 if m.rstrip() == ".":
21 eom_found = True
22 else:
23
24=== modified file 'tests/unittests/test_datasource/test_smartos.py'
25--- tests/unittests/test_datasource/test_smartos.py 2015-01-27 20:03:52 +0000
26+++ tests/unittests/test_datasource/test_smartos.py 2015-03-13 10:20:28 +0000
27@@ -36,6 +36,8 @@
28 import stat
29 import uuid
30
31+import six
32+
33
34 MOCK_RETURNS = {
35 'hostname': 'test-host',
36@@ -78,24 +80,27 @@
37 return True
38
39 def write(self, line):
40- line = line.replace('GET ', '')
41+ if not isinstance(line, six.binary_type):
42+ raise TypeError("Should be writing binary lines.")
43+ line = line.decode('ascii').replace('GET ', '')
44 self.last = line.rstrip()
45
46 def readline(self):
47 if self.new:
48 self.new = False
49 if self.last in self.mockdata:
50- return 'SUCCESS\n'
51+ line = 'SUCCESS\n'
52 else:
53- return 'NOTFOUND %s\n' % self.last
54+ line = 'NOTFOUND %s\n' % self.last
55
56- if self.last in self.mockdata:
57+ elif self.last in self.mockdata:
58 if not self.mocked_out:
59 self.mocked_out = [x for x in self._format_out()]
60
61 if len(self.mocked_out) > self.count:
62 self.count += 1
63- return self.mocked_out[self.count - 1]
64+ line = self.mocked_out[self.count - 1]
65+ return line.encode('ascii')
66
67 def _format_out(self):
68 if self.last in self.mockdata: