Skip to content

Commit 19d5340

Browse files
committed
address PR feedback
Signed-off-by: Zachary Raines <[email protected]>
1 parent 594c912 commit 19d5340

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

cloudinit/sources/DataSourceEc2.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -888,22 +888,18 @@ def _collect_platform_data():
888888
}
889889

890890

891-
def _is_elastic_driver(nic: str) -> bool:
892-
"""Check if the NIC is using the Elastic Network Adapter (ENA)
893-
or Elastic Fabric Adapter (EFA) drivers
894-
"""
895-
return device_driver(nic) in ELASTIC_DRIVERS
896-
897-
898891
def _prefer_elastic_drivers(nic: str) -> int:
899-
"""Sorts the NICs so that amazon drivers are first.
892+
"""Sorts the NICs so that Amazon drivers are first.
900893
901-
This helps speed up finding the metadata server since it
902-
should only be attached to one of these.
894+
This helps speed up finding the metadata server since it will generally
895+
be reachable via the first ENA/EFA NIC if one is present. Each incorrect
896+
NIC that we are able to skip shortens boot by approximately
897+
DataSourceEc2.url_max_wait seconds.
903898
"""
904-
# sorted is guaranteed to be stable, so we only need to sort
899+
# The python builtin `sorted` is guaranteed to be stable,
900+
# so we only need to sort
905901
# based on whether the NIC is an elastic driver or not
906-
if _is_elastic_driver(nic):
902+
if device_driver(nic) in ELASTIC_DRIVERS:
907903
return 0
908904
return 1
909905

tests/unittests/sources/test_ec2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,17 @@ def test_false_on_wrong_product_name(self, m_collect):
18611861

18621862

18631863
class TestPreferElasticNics:
1864+
"""Tests to ensure we are sorting NICs with Amazon drivers ahead of other
1865+
candidate NICs.
1866+
1867+
If a NIC is present with an Amazon driver, it is more likely to be the
1868+
interface which can reach the metadata server. Sorting it first speeds
1869+
up boot due to minimizing wait time in DataSourceEc2.wait_for_metadata.
1870+
1871+
See Also
1872+
=========
1873+
cloudinit.sources.DataSourceEc2._prefer_elastic_drivers
1874+
"""
18641875

18651876
@pytest.fixture
18661877
def nics(self):

0 commit comments

Comments
 (0)