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
diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py b/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
index e319775..f875011 100644
--- a/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/install_lldpd.py
@@ -25,43 +25,45 @@
25# packages: {apt: lldpd}25# packages: {apt: lldpd}
26# timeout: 3026# timeout: 30
27# --- End MAAS 1.0 script metadata ---27# --- End MAAS 1.0 script metadata ---
28"""Installs and configures `lldpd` for passive capture.
2928
30`config_file` refers to a shell script that is sourced by29from codecs import open
31`lldpd`'s init script, i.e. it's Upstart config on Ubuntu.30import os
31from subprocess import check_call
3232
33It selects the following options for the `lldpd` daemon:
3433
35-c Enable the support of CDP protocol to deal with Cisco routers34def lldpd_install(config_file):
36 that do not speak LLDP. If repeated, CDPv1 packets will be35 """Installs and configures `lldpd` for passive capture.
37 sent even when there is no CDP peer detected.
3836
39-f Enable the support of FDP protocol to deal with Foundry routers37 `config_file` refers to a shell script that is sourced by
40 that do not speak LLDP. If repeated, FDP packets will be sent38 `lldpd`'s init script, i.e. it's Upstart config on Ubuntu.
41 even when there is no FDP peer detected.
4239
43-s Enable the support of SONMP protocol to deal with Nortel40 It selects the following options for the `lldpd` daemon:
44 routers and switches that do not speak LLDP. If repeated,
45 SONMP packets will be sent even when there is no SONMP peer
46 detected.
4741
48-e Enable the support of EDP protocol to deal with Extreme42 -c Enable the support of CDP protocol to deal with Cisco routers
49 routers and switches that do not speak LLDP. If repeated, EDP43 that do not speak LLDP. If repeated, CDPv1 packets will be
50 packets will be sent even when there is no EDP peer detected.44 sent even when there is no CDP peer detected.
5145
52-r Receive-only mode. With this switch, lldpd will not send any46 -f Enable the support of FDP protocol to deal with Foundry routers
53 frame. It will only listen to neighbors.47 that do not speak LLDP. If repeated, FDP packets will be sent
48 even when there is no FDP peer detected.
5449
55These flags are chosen so that we're able to capture information50 -s Enable the support of SONMP protocol to deal with Nortel
56from a broad spectrum of equipment, but without advertising the51 routers and switches that do not speak LLDP. If repeated,
57node's temporary presence.52 SONMP packets will be sent even when there is no SONMP peer
53 detected.
5854
59"""55 -e Enable the support of EDP protocol to deal with Extreme
60from codecs import open56 routers and switches that do not speak LLDP. If repeated, EDP
61from subprocess import check_call57 packets will be sent even when there is no EDP peer detected.
6258
59 -r Receive-only mode. With this switch, lldpd will not send any
60 frame. It will only listen to neighbors.
6361
64def lldpd_install(config_file):62 These flags are chosen so that we're able to capture information
63 from a broad spectrum of equipment, but without advertising the
64 node's temporary presence.
65
66 """
65 print("INFO: Configuring lldpd...")67 print("INFO: Configuring lldpd...")
6668
67 with open(config_file, "a", "ascii") as fd:69 with open(config_file, "a", "ascii") as fd:
@@ -73,5 +75,32 @@ def lldpd_install(config_file):
73 check_call(("systemctl", "restart", "lldpd"))75 check_call(("systemctl", "restart", "lldpd"))
7476
7577
78def disable_embedded_lldp_agent_in_intel_cna_cards():
79 """Intel cards that use i40e driver have an internal lldp processor
80 on the NIC that filter out lldp packets before they can reach the
81 host. For the linux lldp daemon to receive such packets, we have to
82 disable that feature.
83
84 """
85 addr_path = "/sys/kernel/debug/i40e"
86 if not os.path.exists(addr_path):
87 return
88 for inner_dir in os.listdir(addr_path):
89 command_path = "{}/{}/command".format(addr_path, inner_dir)
90 try:
91 with open(command_path, "w", encoding="ascii") as command_file:
92 command_file.write("lldp stop\n")
93 print(
94 "INFO: Disabled embedded lldp agent for {}".format(inner_dir)
95 )
96 except (OSError, IOError):
97 print(
98 "WARNING: Failed to disable the embedded lldp agent for {}".format(
99 inner_dir
100 )
101 )
102
103
76if __name__ == "__main__":104if __name__ == "__main__":
105 disable_embedded_lldp_agent_in_intel_cna_cards()
77 lldpd_install("/etc/default/lldpd")106 lldpd_install("/etc/default/lldpd")
diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
index 0afdd92..dda2740 100644
--- a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
+++ b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_lldp.py
@@ -44,6 +44,26 @@ class TestLLDPScripts(MAASTestCase):
44 config_observed = fd.read()44 config_observed = fd.read()
45 self.assertEqual(config_expected, config_observed)45 self.assertEqual(config_expected, config_observed)
4646
47 def test_install_script_disables_intel_lldp(self):
48 self.patch(os.path, "exists").return_value = True
49 self.patch(os, "listdir").return_value = ["0000:1a:00.0"]
50 temp_file = self.make_file("temp", "")
51 mock_open = self.patch(install_lldpd, "open")
52 mock_open.return_value = open(temp_file, "w", encoding="ascii")
53 install_lldpd.disable_embedded_lldp_agent_in_intel_cna_cards()
54 output_expected = "lldp stop\n".encode("ascii")
55 with open(temp_file, "rb") as fd:
56 output_observed = fd.read()
57 self.assertEqual(output_expected, output_observed)
58 self.assertThat(
59 mock_open,
60 MockCalledOnceWith(
61 "/sys/kernel/debug/i40e/0000:1a:00.0/command",
62 "w",
63 encoding="ascii",
64 ),
65 )
66
47 def test_capture_lldpd_script_waits_for_lldpd(self):67 def test_capture_lldpd_script_waits_for_lldpd(self):
48 reference_file = self.make_file("reference")68 reference_file = self.make_file("reference")
49 time_delay = 8.98 # seconds69 time_delay = 8.98 # seconds

Subscribers

People subscribed via source and target branches