Merge ~ltrager/maas:lp1801152 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Blake Rouse
Approved revision: 1ec9e085478de32b65058ea4a2767229f41a2c59
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1801152
Merge into: maas:master
Diff against target: 97 lines (+19/-36)
2 files modified
src/provisioningserver/refresh/node_info_scripts.py (+6/-11)
src/provisioningserver/refresh/tests/test_node_info_scripts.py (+13/-25)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
MAAS Lander Approve
Review via email: mp+358194@code.launchpad.net

Commit message

LP: #1801152 - Ensure 99-maas-02-capture-lldp never sleeps longer than 60s.

Description of the change

Drive by cleanup I missed when fixing LP:1800233 - Remove Trusty support from LLDPD test

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1801152 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 84a0798834f0a09ada5712c633f88a207078b8fd

review: Approve
~ltrager/maas:lp1801152 updated
1ec9e08... by Lee Trager

Use min

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1801152 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 1ec9e085478de32b65058ea4a2767229f41a2c59

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/provisioningserver/refresh/node_info_scripts.py b/src/provisioningserver/refresh/node_info_scripts.py
2index 6d0ab94..bcda1c5 100644
3--- a/src/provisioningserver/refresh/node_info_scripts.py
4+++ b/src/provisioningserver/refresh/node_info_scripts.py
5@@ -373,22 +373,13 @@ def lldpd_install(config_file):
6 node's temporary presence.
7
8 """
9- import os
10 from subprocess import check_call
11 from codecs import open
12 with open(config_file, "a", "ascii") as fd:
13 fd.write('\n') # Ensure there's a newline.
14 fd.write('# Configured by MAAS:\n')
15 fd.write('DAEMON_ARGS="-c -f -s -e -r"\n')
16- if os.path.isdir("/run/systemd/system"):
17- check_call(("systemctl", "restart", "lldpd"))
18- else:
19- # Reload initctl configuration in order to make sure that the
20- # lldpd init script is available before restart, otherwise
21- # it might cause gathering node info to fail. This is due bug
22- # (LP: #882147) in the kernel.
23- check_call(("initctl", "reload-configuration"))
24- check_call(("service", "lldpd", "restart"))
25+ check_call(('systemctl', 'restart', 'lldpd'))
26
27
28 # This function must be entirely self-contained. It must not use
29@@ -406,7 +397,11 @@ def lldpd_capture(reference_file, time_delay):
30 time_ref = getmtime(reference_file)
31 time_remaining = time_ref + time_delay - time()
32 if time_remaining > 0:
33- sleep(time_remaining)
34+ # LP:1801152 - If the hardware clock is in the future when
35+ # 00-maas-03-install-lldpd runs and NTP corrects the clock
36+ # before this script runs time_remaining will be more then
37+ # the time_delay which may cause this script to timeout.
38+ sleep(min(time_remaining, time_delay))
39 check_call(("lldpctl", "-f", "xml"))
40
41
42diff --git a/src/provisioningserver/refresh/tests/test_node_info_scripts.py b/src/provisioningserver/refresh/tests/test_node_info_scripts.py
43index 8b6102d..a4941c6 100644
44--- a/src/provisioningserver/refresh/tests/test_node_info_scripts.py
45+++ b/src/provisioningserver/refresh/tests/test_node_info_scripts.py
46@@ -127,31 +127,6 @@ def isolate_function(function, namespace=None):
47
48 class TestLLDPScripts(MAASTestCase):
49
50- def test_install_script_installs_configures_and_restarts_upstart(self):
51- config_file = self.make_file("config", "# ...")
52- check_call = self.patch(subprocess, "check_call")
53- self.patch(os.path, "isdir").return_value = False
54- lldpd_install = isolate_function(node_info_module.lldpd_install)
55- lldpd_install(config_file)
56- # lldpd is installed and restarted.
57- self.assertEqual(
58- check_call.call_args_list,
59- [
60- call(("initctl", "reload-configuration")),
61- call(("service", "lldpd", "restart"))
62- ])
63- # lldpd's config was updated to include an updated DAEMON_ARGS
64- # setting. Note that the new comment is on a new line, and
65- # does not interfere with existing config.
66- config_expected = dedent("""\
67- # ...
68- # Configured by MAAS:
69- DAEMON_ARGS="-c -f -s -e -r"
70- """).encode("ascii")
71- with open(config_file, "rb") as fd:
72- config_observed = fd.read()
73- self.assertEqual(config_expected, config_observed)
74-
75 def test_install_script_installs_configures_and_restarts_systemd(self):
76 config_file = self.make_file("config", "# ...")
77 check_call = self.patch(subprocess, "check_call")
78@@ -200,6 +175,19 @@ class TestLLDPScripts(MAASTestCase):
79 os.path.getmtime.return_value + time_delay -
80 time.time.return_value))
81
82+ def test_capture_lldpd_script_doesnt_waits_for_more_than_sixty_secs(self):
83+ # Regression test for LP:1801152
84+ reference_file = self.make_file("reference")
85+ lldpd_capture = isolate_function(node_info_module.lldpd_capture)
86+ self.patch(os.path, "getmtime").return_value = 1000.1
87+ self.patch(time, "time").return_value = 10.25
88+ self.patch(time, "sleep")
89+ self.patch(subprocess, "check_call")
90+
91+ lldpd_capture(reference_file, 60)
92+
93+ self.assertThat(time.sleep, MockCalledOnceWith(60))
94+
95 def test_capture_lldpd_calls_lldpdctl(self):
96 reference_file = self.make_file("reference")
97 check_call = self.patch(subprocess, "check_call")

Subscribers

People subscribed via source and target branches