Merge lp:~oddbloke/cloud-init/ssh-equals into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Dan Watkins
Status: Merged
Approved by: Joshua Harlow
Approved revision: 1035
Merged at revision: 1038
Proposed branch: lp:~oddbloke/cloud-init/ssh-equals
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 119 lines (+76/-3)
3 files modified
cloudinit/ssh_util.py (+4/-1)
test-requirements.txt (+1/-0)
tests/unittests/test_sshutil.py (+71/-2)
To merge this branch: bzr merge lp:~oddbloke/cloud-init/ssh-equals
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+241552@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Joshua Harlow (harlowja) :
lp:~oddbloke/cloud-init/ssh-equals updated
1035. By Dan Watkins

Use test_helpers.TestCase for test_sshutil tests.

As requested by harlowja.

Revision history for this message
Dan Watkins (oddbloke) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 13/11/14 09:44, Joshua Harlow wrote:
>> === modified file 'tests/unittests/test_sshutil.py' ---
>> tests/unittests/test_sshutil.py 2013-03-07 19:54:25 +0000 +++
>> tests/unittests/test_sshutil.py 2014-11-12 14:02:22 +0000 @@ -1,5
>> +1,8 @@ +from unittest import TestCase
>
> Can u use
> http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/tests/unittests/helpers.py#L37
> as the base class instead. This ensures that various functions that
> aren't on py26 actually work (or work good enough). Thanks.

Done and pushed.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJUZInfAAoJEO7mh3btsT6gZ10P/3i9a3OpwmQWwzVhuqLb8JLO
hS8OKWYIAT3bpMg9gsVDlY7i+65mxh62Yy6z/im6mlI1ZVggcVplZBjNJjYIbLFu
zzDRBh2OSMki4NNqSIv70m79FYyhNhP1hzibWD9yc2N2XmLc8rEz+DvK/ra5Q9FZ
f3n06YddpXgttVhyGtrAAeHMmki5215B4xfFTyLyK6WDnq7S+lke66M9AQxJBuMO
tvy9XtK0fPOH3G0XRo3Qh9IxqIciI/VEKLcTvaPIHZyF52RKB1QN8bvDWOZZ4aZ/
UPF+zDUbSGtbX26ASqpyB1opEXwf2n2gXaJqo+8XEczyyR8V5Rej7LlIhW+fpY7U
L1iOEUk7pF8wHFJBRPKDPy2jLclnR4wjt1WYujik8rPCgKTdaPUBQZsXNqW12iue
Pg9ZpuI8y8G5WnCx4UJGcp0jZ435oKb6B7Yb/9AhahhWZvGiYvLL7sZltxUQpz16
UN+Dv446YwnIZxxyVAzWaSJJKSuwYtFTAPH6Ekfw099IgR3WmqtMvedvw/Br+SZm
ePZ3R/Ncnb65pi3ZxYo6zQeNaKjwmXt5yulspVaXkRCLBp/LgMdzN0AGrrYaTWEn
JrRQs/mMHUj/NL9UHmghzRILQzA1uJFOOzJSwA0gEqL8TrcDIueff4YLZ5w79E60
KYYBDzrkLftL6ch8zZQA
=k8vE
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cloudinit/ssh_util.py'
--- cloudinit/ssh_util.py 2013-06-19 06:44:00 +0000
+++ cloudinit/ssh_util.py 2014-11-13 10:36:24 +0000
@@ -293,7 +293,10 @@
293 if not line or line.startswith("#"):293 if not line or line.startswith("#"):
294 lines.append(SshdConfigLine(line))294 lines.append(SshdConfigLine(line))
295 continue295 continue
296 (key, val) = line.split(None, 1)296 try:
297 key, val = line.split(None, 1)
298 except ValueError:
299 key, val = line.split('=', 1)
297 lines.append(SshdConfigLine(line, key, val))300 lines.append(SshdConfigLine(line, key, val))
298 return lines301 return lines
299302
300303
=== modified file 'test-requirements.txt'
--- test-requirements.txt 2014-08-26 18:53:44 +0000
+++ test-requirements.txt 2014-11-13 10:36:24 +0000
@@ -1,4 +1,5 @@
1httpretty>=0.7.11httpretty>=0.7.1
2mock
2mocker3mocker
3nose4nose
4pep8==1.5.75pep8==1.5.7
56
=== modified file 'tests/unittests/test_sshutil.py'
--- tests/unittests/test_sshutil.py 2013-03-07 19:54:25 +0000
+++ tests/unittests/test_sshutil.py 2014-11-13 10:36:24 +0000
@@ -1,5 +1,7 @@
1from mock import patch
2
3from . import helpers as test_helpers
1from cloudinit import ssh_util4from cloudinit import ssh_util
2from unittest import TestCase
35
46
5VALID_CONTENT = {7VALID_CONTENT = {
@@ -35,7 +37,7 @@
35 'user \"root\".\';echo;sleep 10"')37 'user \"root\".\';echo;sleep 10"')
3638
3739
38class TestAuthKeyLineParser(TestCase):40class TestAuthKeyLineParser(test_helpers.TestCase):
39 def test_simple_parse(self):41 def test_simple_parse(self):
40 # test key line with common 3 fields (keytype, base64, comment)42 # test key line with common 3 fields (keytype, base64, comment)
41 parser = ssh_util.AuthKeyLineParser()43 parser = ssh_util.AuthKeyLineParser()
@@ -98,4 +100,71 @@
98 self.assertFalse(key.valid())100 self.assertFalse(key.valid())
99101
100102
103class TestParseSSHConfig(test_helpers.TestCase):
104
105 def setUp(self):
106 self.load_file_patch = patch('cloudinit.ssh_util.util.load_file')
107 self.load_file = self.load_file_patch.start()
108 self.isfile_patch = patch('cloudinit.ssh_util.os.path.isfile')
109 self.isfile = self.isfile_patch.start()
110 self.isfile.return_value = True
111
112 def tearDown(self):
113 self.load_file_patch.stop()
114 self.isfile_patch.stop()
115
116 def test_not_a_file(self):
117 self.isfile.return_value = False
118 self.load_file.side_effect = IOError
119 ret = ssh_util.parse_ssh_config('not a real file')
120 self.assertEqual([], ret)
121
122 def test_empty_file(self):
123 self.load_file.return_value = ''
124 ret = ssh_util.parse_ssh_config('some real file')
125 self.assertEqual([], ret)
126
127 def test_comment_line(self):
128 comment_line = '# This is a comment'
129 self.load_file.return_value = comment_line
130 ret = ssh_util.parse_ssh_config('some real file')
131 self.assertEqual(1, len(ret))
132 self.assertEqual(comment_line, ret[0].line)
133
134 def test_blank_lines(self):
135 lines = ['', '\t', ' ']
136 self.load_file.return_value = '\n'.join(lines)
137 ret = ssh_util.parse_ssh_config('some real file')
138 self.assertEqual(len(lines), len(ret))
139 for line in ret:
140 self.assertEqual('', line.line)
141
142 def test_lower_case_config(self):
143 self.load_file.return_value = 'foo bar'
144 ret = ssh_util.parse_ssh_config('some real file')
145 self.assertEqual(1, len(ret))
146 self.assertEqual('foo', ret[0].key)
147 self.assertEqual('bar', ret[0].value)
148
149 def test_upper_case_config(self):
150 self.load_file.return_value = 'Foo Bar'
151 ret = ssh_util.parse_ssh_config('some real file')
152 self.assertEqual(1, len(ret))
153 self.assertEqual('foo', ret[0].key)
154 self.assertEqual('Bar', ret[0].value)
155
156 def test_lower_case_with_equals(self):
157 self.load_file.return_value = 'foo=bar'
158 ret = ssh_util.parse_ssh_config('some real file')
159 self.assertEqual(1, len(ret))
160 self.assertEqual('foo', ret[0].key)
161 self.assertEqual('bar', ret[0].value)
162
163 def test_upper_case_with_equals(self):
164 self.load_file.return_value = 'Foo=bar'
165 ret = ssh_util.parse_ssh_config('some real file')
166 self.assertEqual(1, len(ret))
167 self.assertEqual('foo', ret[0].key)
168 self.assertEqual('bar', ret[0].value)
169
101# vi: ts=4 expandtab170# vi: ts=4 expandtab