Merge ~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp:master into maas:master

Proposed by Andre Ruiz
Status: Merged
Approved by: Adam Collard
Approved revision: 15410675b843458eb7f744ad47558d353038dd1b
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp:master
Merge into: maas:master
Diff against target: 140 lines (+75/-26)
2 files modified
src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py (+55/-26)
src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py (+20/-0)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+389824@code.launchpad.net

Commit message

LP: #1750688 Disable embedded LLDP on Intel CNA cards

Improved lldp_install script to disable embedded lldp processing on Intel CNA cards using i40e driver so that the host can receive LLDP packets on those cards.

Description of the change

Implemented fix for lldp on intel cna cards

- Improved lldp_install script to disable embedded lldp processing
  on intel cna cards using i40e driver so that the host can receive
  lldp packets on those cards.

fixes: lp#1750688

To post a comment you must log in.
Revision history for this message
Andre Ruiz (andre-ruiz) wrote :

Please note that the large number of changes in install_lldpd.py are mostly because of re-indentation of text when moving to inside the function.

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

UNIT TESTS
-b master lp:~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8180/console
COMMIT: 8234e85b91b214cf14dff60c965d00b28762c594

review: Needs Fixing
153391d... by Andre Ruiz

Changes to make lint happy

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

UNIT TESTS
-b master lp:~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8181/console
COMMIT: 153391d645efbe175edbead7398e4923561a62d0

review: Needs Fixing
Revision history for this message
Andre Ruiz (andre-ruiz) wrote :

I'm failing to see how this test failure is connected to the changes I made in a different part of the code.

At the same time, although I also get the same failure here on my side on the first run, it goes away (finishes ok) if I re-run the test just after it failed (??).

My last full test run just passed:

Ran 17326 tests in 2508.329s
OK (skipped=22)

Also, it always passes when I run that test alone, using "LC_ALL=en_US.UTF-8 ./bin/test.region -v src/provisioningserver/refresh/tests/test_refresh.py".

So I'm not sure what to do. Suggestions?

Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

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

UNIT TESTS
-b master lp:~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 153391d645efbe175edbead7398e4923561a62d0

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Needs Fixing
1541067... by Andre Ruiz

Fixes per review requests

- moved static string attribution to outside of try/except
- added "\n" to command string
- swapped f-string for format() everywhere
- improved test function to check what was written too

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

UNIT TESTS
-b master lp:~andre-ruiz/maas/+git/maas-fix-intel-cna-lldp into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 15410675b843458eb7f744ad47558d353038dd1b

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py b/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
2index e319775..f875011 100644
3--- a/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
4+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
5@@ -25,43 +25,45 @@
6 # packages: {apt: lldpd}
7 # timeout: 30
8 # --- End MAAS 1.0 script metadata ---
9-"""Installs and configures `lldpd` for passive capture.
10
11-`config_file` refers to a shell script that is sourced by
12-`lldpd`'s init script, i.e. it's Upstart config on Ubuntu.
13+from codecs import open
14+import os
15+from subprocess import check_call
16
17-It selects the following options for the `lldpd` daemon:
18
19--c Enable the support of CDP protocol to deal with Cisco routers
20- that do not speak LLDP. If repeated, CDPv1 packets will be
21- sent even when there is no CDP peer detected.
22+def lldpd_install(config_file):
23+ """Installs and configures `lldpd` for passive capture.
24
25--f Enable the support of FDP protocol to deal with Foundry routers
26- that do not speak LLDP. If repeated, FDP packets will be sent
27- even when there is no FDP peer detected.
28+ `config_file` refers to a shell script that is sourced by
29+ `lldpd`'s init script, i.e. it's Upstart config on Ubuntu.
30
31--s Enable the support of SONMP protocol to deal with Nortel
32- routers and switches that do not speak LLDP. If repeated,
33- SONMP packets will be sent even when there is no SONMP peer
34- detected.
35+ It selects the following options for the `lldpd` daemon:
36
37--e Enable the support of EDP protocol to deal with Extreme
38- routers and switches that do not speak LLDP. If repeated, EDP
39- packets will be sent even when there is no EDP peer detected.
40+ -c Enable the support of CDP protocol to deal with Cisco routers
41+ that do not speak LLDP. If repeated, CDPv1 packets will be
42+ sent even when there is no CDP peer detected.
43
44--r Receive-only mode. With this switch, lldpd will not send any
45- frame. It will only listen to neighbors.
46+ -f Enable the support of FDP protocol to deal with Foundry routers
47+ that do not speak LLDP. If repeated, FDP packets will be sent
48+ even when there is no FDP peer detected.
49
50-These flags are chosen so that we're able to capture information
51-from a broad spectrum of equipment, but without advertising the
52-node's temporary presence.
53+ -s Enable the support of SONMP protocol to deal with Nortel
54+ routers and switches that do not speak LLDP. If repeated,
55+ SONMP packets will be sent even when there is no SONMP peer
56+ detected.
57
58-"""
59-from codecs import open
60-from subprocess import check_call
61+ -e Enable the support of EDP protocol to deal with Extreme
62+ routers and switches that do not speak LLDP. If repeated, EDP
63+ packets will be sent even when there is no EDP peer detected.
64
65+ -r Receive-only mode. With this switch, lldpd will not send any
66+ frame. It will only listen to neighbors.
67
68-def lldpd_install(config_file):
69+ These flags are chosen so that we're able to capture information
70+ from a broad spectrum of equipment, but without advertising the
71+ node's temporary presence.
72+
73+ """
74 print("INFO: Configuring lldpd...")
75
76 with open(config_file, "a", "ascii") as fd:
77@@ -73,5 +75,32 @@ def lldpd_install(config_file):
78 check_call(("systemctl", "restart", "lldpd"))
79
80
81+def disable_embedded_lldp_agent_in_intel_cna_cards():
82+ """Intel cards that use i40e driver have an internal lldp processor
83+ on the NIC that filter out lldp packets before they can reach the
84+ host. For the linux lldp daemon to receive such packets, we have to
85+ disable that feature.
86+
87+ """
88+ addr_path = "/sys/kernel/debug/i40e"
89+ if not os.path.exists(addr_path):
90+ return
91+ for inner_dir in os.listdir(addr_path):
92+ command_path = "{}/{}/command".format(addr_path, inner_dir)
93+ try:
94+ with open(command_path, "w", encoding="ascii") as command_file:
95+ command_file.write("lldp stop\n")
96+ print(
97+ "INFO: Disabled embedded lldp agent for {}".format(inner_dir)
98+ )
99+ except (OSError, IOError):
100+ print(
101+ "WARNING: Failed to disable the embedded lldp agent for {}".format(
102+ inner_dir
103+ )
104+ )
105+
106+
107 if __name__ == "__main__":
108+ disable_embedded_lldp_agent_in_intel_cna_cards()
109 lldpd_install("/etc/default/lldpd")
110diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
111index 0afdd92..dda2740 100644
112--- a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
113+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
114@@ -44,6 +44,26 @@ class TestLLDPScripts(MAASTestCase):
115 config_observed = fd.read()
116 self.assertEqual(config_expected, config_observed)
117
118+ def test_install_script_disables_intel_lldp(self):
119+ self.patch(os.path, "exists").return_value = True
120+ self.patch(os, "listdir").return_value = ["0000:1a:00.0"]
121+ temp_file = self.make_file("temp", "")
122+ mock_open = self.patch(install_lldpd, "open")
123+ mock_open.return_value = open(temp_file, "w", encoding="ascii")
124+ install_lldpd.disable_embedded_lldp_agent_in_intel_cna_cards()
125+ output_expected = "lldp stop\n".encode("ascii")
126+ with open(temp_file, "rb") as fd:
127+ output_observed = fd.read()
128+ self.assertEqual(output_expected, output_observed)
129+ self.assertThat(
130+ mock_open,
131+ MockCalledOnceWith(
132+ "/sys/kernel/debug/i40e/0000:1a:00.0/command",
133+ "w",
134+ encoding="ascii",
135+ ),
136+ )
137+
138 def test_capture_lldpd_script_waits_for_lldpd(self):
139 reference_file = self.make_file("reference")
140 time_delay = 8.98 # seconds

Subscribers

People subscribed via source and target branches