Merge lp:~blake-rouse/maas/fix-1524482 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4548
Proposed branch: lp:~blake-rouse/maas/fix-1524482
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 55 lines (+11/-5)
2 files modified
src/provisioningserver/rpc/dhcp.py (+4/-2)
src/provisioningserver/rpc/tests/test_dhcp.py (+7/-3)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1524482
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+280097@code.launchpad.net

Commit message

Fix writing DHCP configuration so that it is encoded into a byte string before calling sudo_write_file.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/provisioningserver/rpc/dhcp.py'
--- src/provisioningserver/rpc/dhcp.py 2015-12-09 19:53:51 +0000
+++ src/provisioningserver/rpc/dhcp.py 2015-12-10 00:35:47 +0000
@@ -84,8 +84,10 @@
84 interfaces = {subnet['interface'] for subnet in subnet_configs}84 interfaces = {subnet['interface'] for subnet in subnet_configs}
85 interfaces_config = ' '.join(sorted(interfaces))85 interfaces_config = ' '.join(sorted(interfaces))
86 try:86 try:
87 sudo_write_file(server.config_filename, dhcpd_config)87 sudo_write_file(
88 sudo_write_file(server.interfaces_filename, interfaces_config)88 server.config_filename, dhcpd_config.encode("utf-8"))
89 sudo_write_file(
90 server.interfaces_filename, interfaces_config.encode("utf-8"))
89 except ExternalProcessError as e:91 except ExternalProcessError as e:
90 # ExternalProcessError.__str__ contains a generic failure message92 # ExternalProcessError.__str__ contains a generic failure message
91 # as well as the command and its error output. On the other hand,93 # as well as the command and its error output. On the other hand,
9294
=== modified file 'src/provisioningserver/rpc/tests/test_dhcp.py'
--- src/provisioningserver/rpc/tests/test_dhcp.py 2015-12-09 21:00:58 +0000
+++ src/provisioningserver/rpc/tests/test_dhcp.py 2015-12-10 00:35:47 +0000
@@ -76,11 +76,13 @@
76 self.patch_restart_service()76 self.patch_restart_service()
77 subnets = [make_subnet_config() for _ in range(3)]77 subnets = [make_subnet_config() for _ in range(3)]
78 self.configure(factory.make_name('key'), subnets)78 self.configure(factory.make_name('key'), subnets)
79 interfaces = ' '.join(
80 sorted(subnet['interface'] for subnet in subnets))
79 self.assertThat(81 self.assertThat(
80 write_file,82 write_file,
81 MockCalledWith(83 MockCalledWith(
82 ANY,84 ANY,
83 ' '.join(sorted(subnet['interface'] for subnet in subnets))))85 interfaces.encode("utf-8")))
8486
85 def test__eliminates_duplicate_interfaces(self):87 def test__eliminates_duplicate_interfaces(self):
86 write_file = self.patch_sudo_write_file()88 write_file = self.patch_sudo_write_file()
@@ -90,7 +92,8 @@
90 for subnet in subnets:92 for subnet in subnets:
91 subnet['interface'] = interface93 subnet['interface'] = interface
92 self.configure(factory.make_name('key'), subnets)94 self.configure(factory.make_name('key'), subnets)
93 self.assertThat(write_file, MockCalledWith(ANY, interface))95 self.assertThat(
96 write_file, MockCalledWith(ANY, interface.encode("utf-8")))
9497
95 def test__composes_dhcp_config(self):98 def test__composes_dhcp_config(self):
96 self.patch_sudo_write_file()99 self.patch_sudo_write_file()
@@ -117,7 +120,8 @@
117120
118 self.assertThat(121 self.assertThat(
119 write_file,122 write_file,
120 MockAnyCall(self.server.config_filename, expected_config))123 MockAnyCall(
124 self.server.config_filename, expected_config.encode("utf-8")))
121125
122 def test__writes_interfaces_file(self):126 def test__writes_interfaces_file(self):
123 write_file = self.patch_sudo_write_file()127 write_file = self.patch_sudo_write_file()