Merge lp:~allenap/maas/mac-n-cheese--bug-1398159 into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 3410
Proposed branch: lp:~allenap/maas/mac-n-cheese--bug-1398159
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 123 lines (+56/-7)
2 files modified
src/provisioningserver/boot/tests/test_windows.py (+43/-0)
src/provisioningserver/boot/windows.py (+13/-7)
To merge this branch: bzr merge lp:~allenap/maas/mac-n-cheese--bug-1398159
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+244096@code.launchpad.net

Commit message

Don't query for node info when we don't have a MAC address.

When accessing the TFTP server from the local machine we can't look-up the MAC address via the ARP cache. Given that we will never be provisioning the local machine, because it's a cluster controller, we can return early.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

QA done locally.

Revision history for this message
Gavin Panella (allenap) wrote :

Thanks for the review Blake!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/boot/tests/test_windows.py'
2--- src/provisioningserver/boot/tests/test_windows.py 2014-09-27 01:44:10 +0000
3+++ src/provisioningserver/boot/tests/test_windows.py 2014-12-09 09:23:02 +0000
4@@ -15,9 +15,11 @@
5 __metaclass__ = type
6 __all__ = []
7
8+import logging
9 import os
10 import shutil
11
12+from fixtures import FakeLogger
13 from maastesting.factory import factory
14 from maastesting.matchers import MockCalledOnceWith
15 from maastesting.testcase import (
16@@ -25,6 +27,7 @@
17 MAASTwistedRunTest,
18 )
19 import mock
20+from mock import sentinel
21 from provisioningserver.boot import (
22 BootMethodError,
23 BytesReader,
24@@ -35,7 +38,15 @@
25 WindowsPXEBootMethod,
26 )
27 from provisioningserver.config import Config
28+from provisioningserver.rpc.exceptions import NoSuchNode
29+from provisioningserver.rpc.region import RequestNodeInfoByMACAddress
30+from provisioningserver.rpc.testing import (
31+ always_fail_with,
32+ always_succeed_with,
33+ )
34 from provisioningserver.tests.test_kernel_opts import make_kernel_parameters
35+from testtools.deferredruntest import extract_result
36+from testtools.matchers import Is
37 from tftp.backend import FilesystemReader
38 from twisted.internet.defer import inlineCallbacks
39
40@@ -145,6 +156,38 @@
41 self.assertThat(bcd.hive.commit, MockCalledOnceWith(None))
42
43
44+class TestRequestNodeInfoByMACAddress(MAASTestCase):
45+
46+ run_tests_with = MAASTwistedRunTest.make_factory(timeout=5)
47+
48+ def test__returns_None_when_MAC_is_None(self):
49+ logger = self.useFixture(FakeLogger("maas", logging.DEBUG))
50+ d = windows_module.request_node_info_by_mac_address(None)
51+ self.assertThat(extract_result(d), Is(None))
52+ self.assertDocTestMatches(
53+ "Cannot determine node; MAC address is unknown.",
54+ logger.output)
55+
56+ def test__returns_None_when_node_not_found(self):
57+ logger = self.useFixture(FakeLogger("maas", logging.DEBUG))
58+ client = self.patch(windows_module, "getRegionClient").return_value
59+ client.side_effect = always_fail_with(NoSuchNode())
60+ mac = factory.make_mac_address()
61+ d = windows_module.request_node_info_by_mac_address(mac)
62+ self.assertThat(extract_result(d), Is(None))
63+ self.assertDocTestMatches(
64+ "Node doesn't exist for MAC address: %s" % mac,
65+ logger.output)
66+
67+ def test__returns_output_from_RequestNodeInfoByMACAddress(self):
68+ client = self.patch(windows_module, "getRegionClient").return_value
69+ client.side_effect = always_succeed_with(sentinel.node_info)
70+ d = windows_module.request_node_info_by_mac_address(sentinel.mac)
71+ self.assertThat(extract_result(d), Is(sentinel.node_info))
72+ self.assertThat(client, MockCalledOnceWith(
73+ RequestNodeInfoByMACAddress, mac_address=sentinel.mac))
74+
75+
76 class TestWindowsPXEBootMethod(MAASTestCase):
77
78 run_tests_with = MAASTwistedRunTest.make_factory(timeout=5)
79
80=== modified file 'src/provisioningserver/boot/windows.py'
81--- src/provisioningserver/boot/windows.py 2014-11-17 11:56:49 +0000
82+++ src/provisioningserver/boot/windows.py 2014-12-09 09:23:02 +0000
83@@ -42,6 +42,7 @@
84 from twisted.internet.defer import (
85 inlineCallbacks,
86 returnValue,
87+ succeed,
88 )
89 from twisted.python.context import get
90 from twisted.python.filepath import FilePath
91@@ -89,20 +90,25 @@
92
93
94 @asynchronous
95-@inlineCallbacks
96 def request_node_info_by_mac_address(mac_address):
97 """Request node info for the given mac address.
98
99 :param mac_address: The MAC Address of the node of the event.
100 :type mac_address: unicode
101 """
102+ if mac_address is None:
103+ maaslog.debug("Cannot determine node; MAC address is unknown.")
104+ return succeed(None)
105+
106 client = getRegionClient()
107- try:
108- yield client(
109- RequestNodeInfoByMACAddress, mac_address=mac_address)
110- except NoSuchNode:
111- maaslog.debug(
112- "Node doesn't exist for MAC address: %s" % mac_address)
113+ d = client(RequestNodeInfoByMACAddress, mac_address=mac_address)
114+
115+ def eb_request_node_info(failure):
116+ failure.trap(NoSuchNode)
117+ maaslog.debug("Node doesn't exist for MAC address: %s", mac_address)
118+ return None
119+
120+ return d.addErrback(eb_request_node_info)
121
122
123 class Bcd: