Merge ~smoser/cloud-init:bug/1732917-fix-fallback-interface into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 281a82181716183d526e76f4e0415e0a6f680cbe
Proposed branch: ~smoser/cloud-init:bug/1732917-fix-fallback-interface
Merge into: cloud-init:master
Diff against target: 85 lines (+22/-10)
2 files modified
cloudinit/net/dhcp.py (+1/-2)
cloudinit/sources/DataSourceEc2.py (+21/-8)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email: mp+333923@code.launchpad.net

Commit message

EC2: Fix bug using fallback nic restoring from old pickled object.

If user upgraded to new cloud-init and rebooted, the restored
object never was pickled with a value in fallback_nic. That caused
an attempt to configure networking with a None device.

We support reading the old .fallback_nic attribute if it ever
got set, but new versions will call net.find_fallback_nic() if
there has not been one found.

LP: #1732917

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:a565685505638011947186bc7f2a437548d2afa8
https://jenkins.ubuntu.com/server/job/cloud-init-ci/512/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/512/rebuild

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

Chad extended this
 https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/333927

and we're going with that branch.

Revision history for this message
Scott Moser (smoser) wrote :

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py
2index 0cba703..1a561be 100644
3--- a/cloudinit/net/dhcp.py
4+++ b/cloudinit/net/dhcp.py
5@@ -41,8 +41,7 @@ def maybe_perform_dhcp_discovery(nic=None):
6 if nic is None:
7 nic = find_fallback_nic()
8 if nic is None:
9- LOG.debug(
10- 'Skip dhcp_discovery: Unable to find fallback nic.')
11+ LOG.debug('Skip dhcp_discovery: Unable to find fallback nic.')
12 return {}
13 elif nic not in get_devicelist():
14 LOG.debug(
15diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
16index 0ef2217..ccf41cd 100644
17--- a/cloudinit/sources/DataSourceEc2.py
18+++ b/cloudinit/sources/DataSourceEc2.py
19@@ -65,7 +65,7 @@ class DataSourceEc2(sources.DataSource):
20 get_network_metadata = False
21
22 # Track the discovered fallback nic for use in configuration generation.
23- fallback_nic = None
24+ _fallback_interface = None
25
26 def __init__(self, sys_cfg, distro, paths):
27 sources.DataSource.__init__(self, sys_cfg, distro, paths)
28@@ -92,18 +92,17 @@ class DataSourceEc2(sources.DataSource):
29 elif self.cloud_platform == Platforms.NO_EC2_METADATA:
30 return False
31
32- self.fallback_nic = net.find_fallback_nic()
33 if self.get_network_metadata: # Setup networking in init-local stage.
34 if util.is_FreeBSD():
35 LOG.debug("FreeBSD doesn't support running dhclient with -sf")
36 return False
37- dhcp_leases = dhcp.maybe_perform_dhcp_discovery(self.fallback_nic)
38+ dhcp_leases = dhcp.maybe_perform_dhcp_discovery(
39+ self.fallback_interface)
40 if not dhcp_leases:
41 # DataSourceEc2Local failed in init-local stage. DataSourceEc2
42 # will still run in init-network stage.
43 return False
44 dhcp_opts = dhcp_leases[-1]
45- self.fallback_nic = dhcp_opts.get('interface')
46 net_params = {'interface': dhcp_opts.get('interface'),
47 'ip': dhcp_opts.get('fixed-address'),
48 'prefix_or_mask': dhcp_opts.get('subnet-mask'),
49@@ -303,12 +302,11 @@ class DataSourceEc2(sources.DataSource):
50 result = None
51 net_md = self.metadata.get('network')
52 # Limit network configuration to only the primary/fallback nic
53- macs_to_nics = {
54- net.get_interface_mac(self.fallback_nic): self.fallback_nic}
55+ iface = self.fallback_interface
56+ macs_to_nics = {net.get_interface_mac(iface): iface}
57 if isinstance(net_md, dict):
58 result = convert_ec2_metadata_network_config(
59- net_md, macs_to_nics=macs_to_nics,
60- fallback_nic=self.fallback_nic)
61+ net_md, macs_to_nics=macs_to_nics, fallback_nic=iface)
62 else:
63 LOG.warning("unexpected metadata 'network' key not valid: %s",
64 net_md)
65@@ -316,6 +314,21 @@ class DataSourceEc2(sources.DataSource):
66
67 return self._network_config
68
69+ @property
70+ def fallback_interface(self):
71+ if self._fallback_interface is None:
72+ # fallback_nic was used at one point, so restored objects may
73+ # have an attribute there. respect that if found.
74+ _legacy_fbnic = getattr(self, 'fallback_nic', None)
75+ if _legacy_fbnic:
76+ self._fallback_interface = _legacy_fbnic
77+ self.fallback_nic = None
78+ else:
79+ self._fallback_interface = net.find_fallback_nic()
80+ if self._fallback_interface is None:
81+ LOG.warning("Did not find a fallback interface on EC2.")
82+ return self._fallback_interface
83+
84 def _crawl_metadata(self):
85 """Crawl metadata service when available.
86

Subscribers

People subscribed via source and target branches