Merge lp:~rvb/maas/tftp-bug-1317705 into lp:maas/trunk

Proposed by Raphaël Badin on 2015-06-15
Status: Merged
Approved by: Raphaël Badin on 2015-06-15
Approved revision: 4014
Merged at revision: 4014
Proposed branch: lp:~rvb/maas/tftp-bug-1317705
Merge into: lp:maas/trunk
Diff against target: 110 lines (+49/-2)
4 files modified
src/provisioningserver/monkey.py (+13/-0)
src/provisioningserver/plugin.py (+5/-1)
src/provisioningserver/tests/test_monkey.py (+22/-1)
src/provisioningserver/tests/test_plugin.py (+9/-0)
To merge this branch: bzr merge lp:~rvb/maas/tftp-bug-1317705
Reviewer Review Type Date Requested Status
Gavin Panella (community) 2015-06-15 Approve on 2015-06-15
Review via email: mp+261937@code.launchpad.net

Commit message

Monkey patch the TFTP server to add error code 8.

Description of the change

Fix has landed upstream but this is taking forever to be SRUed so I think it's worth monkey patching this since the patch is simple.

To post a comment you must log in.
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/monkey.py'
2--- src/provisioningserver/monkey.py 2015-06-08 06:17:54 +0000
3+++ src/provisioningserver/monkey.py 2015-06-15 09:18:42 +0000
4@@ -13,6 +13,7 @@
5
6 __metaclass__ = type
7 __all__ = [
8+ "add_term_error_code_to_tftp",
9 "force_simplestreams_to_use_urllib2",
10 ]
11
12@@ -38,3 +39,15 @@
13 URL_READER=simplestreams.contentsource.Urllib2UrlReader,
14 URL_READER_CLASSNAME="Urllib2UrlReader", urllib_error=urllib_error,
15 urllib_request=urllib_request)
16+
17+
18+def add_term_error_code_to_tftp():
19+ """Add error code 8 to TFT server as introduced by RFC 2347.
20+
21+ Manually apply the fix to python-tx-tftp landed in
22+ https://github.com/shylent/python-tx-tftp/pull/20
23+ """
24+ import tftp.datagram
25+ if tftp.datagram.errors.get(8) is None:
26+ tftp.datagram.errors[8] = (
27+ "Terminate transfer due to option negotiation")
28
29=== modified file 'src/provisioningserver/plugin.py'
30--- src/provisioningserver/plugin.py 2015-06-08 06:17:54 +0000
31+++ src/provisioningserver/plugin.py 2015-06-15 09:18:42 +0000
32@@ -21,7 +21,10 @@
33 import socket
34 from socket import error as socket_error
35
36-from provisioningserver.monkey import force_simplestreams_to_use_urllib2
37+from provisioningserver.monkey import (
38+ add_term_error_code_to_tftp,
39+ force_simplestreams_to_use_urllib2,
40+)
41 from provisioningserver.utils.debug import (
42 register_sigusr2_thread_dump_handler,
43 )
44@@ -233,6 +236,7 @@
45 """Construct the MAAS Cluster service."""
46 register_sigusr2_thread_dump_handler()
47 force_simplestreams_to_use_urllib2()
48+ add_term_error_code_to_tftp()
49
50 from provisioningserver import services
51 from provisioningserver.config import Config
52
53=== modified file 'src/provisioningserver/tests/test_monkey.py'
54--- src/provisioningserver/tests/test_monkey.py 2015-06-08 06:17:54 +0000
55+++ src/provisioningserver/tests/test_monkey.py 2015-06-15 09:18:42 +0000
56@@ -20,8 +20,12 @@
57
58 from maastesting.testcase import MAASTestCase
59 from mock import sentinel
60-from provisioningserver.monkey import force_simplestreams_to_use_urllib2
61+from provisioningserver.monkey import (
62+ add_term_error_code_to_tftp,
63+ force_simplestreams_to_use_urllib2,
64+)
65 from simplestreams import contentsource
66+import tftp.datagram
67
68
69 if sys.version_info > (3, 0):
70@@ -62,3 +66,20 @@
71 force_simplestreams_to_use_urllib2()
72 self.assertEqual(
73 self.value, getattr(contentsource, self.key))
74+
75+
76+class TestAddTermErrorCodeToTFT(MAASTestCase):
77+
78+ def test_adds_error_code_8(self):
79+ self.patch(tftp.datagram, 'errors', {})
80+ add_term_error_code_to_tftp()
81+ self.assertIn(8, tftp.datagram.errors)
82+ self.assertEqual(
83+ "Terminate transfer due to option negotiation",
84+ tftp.datagram.errors.get(8))
85+
86+ def test_skips_adding_error_code_if_already_present(self):
87+ self.patch(tftp.datagram, 'errors', {8: sentinel.error_8})
88+ add_term_error_code_to_tftp()
89+ self.assertEqual(
90+ sentinel.error_8, tftp.datagram.errors.get(8))
91
92=== modified file 'src/provisioningserver/tests/test_plugin.py'
93--- src/provisioningserver/tests/test_plugin.py 2015-06-08 06:17:54 +0000
94+++ src/provisioningserver/tests/test_plugin.py 2015-06-15 09:18:42 +0000
95@@ -132,6 +132,15 @@
96 service_maker.makeService(options)
97 self.assertThat(mock_simplestreams_patch, MockCalledOnceWith())
98
99+ def test_makeService_patches_tftp_service(self):
100+ mock_tftp_patch = (
101+ self.patch(plugin_module, 'add_term_error_code_to_tftp'))
102+ options = Options()
103+ options["config-file"] = self.write_config({})
104+ service_maker = ProvisioningServiceMaker("Harry", "Hill")
105+ service_maker.makeService(options)
106+ self.assertThat(mock_tftp_patch, MockCalledOnceWith())
107+
108 def test_image_download_service(self):
109 options = Options()
110 options["config-file"] = self.write_config({})