Merge ~jasonzio/cloud-init:wireserverFallback into cloud-init:master

Proposed by Jason Zions
Status: Merged
Approved by: Ryan Harper
Approved revision: 2e4c10e6d1868b004bc3e40dbac2216e895b90e5
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~jasonzio/cloud-init:wireserverFallback
Merge into: cloud-init:master
Diff against target: 64 lines (+18/-5)
2 files modified
cloudinit/sources/helpers/azure.py (+11/-3)
tests/unittests/test_datasource/test_azure_helper.py (+7/-2)
Reviewer Review Type Date Requested Status
Ryan Harper Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+367233@code.launchpad.net

Commit message

Azure: Return static fallback address as if failed to find endpoint

The Azure data source helper attempts to use information in the dhcp
lease to find the Wireserver endpoint (IP address). Under some unusual
circumstances, those attempts will fail. This change uses a static
address, known to be always correct in the Azure public and sovereign
clouds, when the helper fails to locate a valid dhcp lease. This
address is not guaranteed to be correct in Azure Stack environments;
it's still best to use the information from the lease whenever possible.

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:57dfd00f086c34f761a905e23e405b18be236dd1
https://jenkins.ubuntu.com/server/job/cloud-init-ci/715/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Couple of inline comments and suggestions.

review: Needs Fixing
2e4c10e... by "Jason Zions (MSFT)" <email address hidden>

Address review comments

Revision history for this message
Jason Zions (jasonzio) wrote :

> Couple of inline comments and suggestions.

Good feedback, thanks for that.

Revision history for this message
Jason Zions (jasonzio) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

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

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

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks that looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
2index d3af05e..82c4c8c 100755
3--- a/cloudinit/sources/helpers/azure.py
4+++ b/cloudinit/sources/helpers/azure.py
5@@ -20,6 +20,9 @@ from cloudinit.reporting import events
6
7 LOG = logging.getLogger(__name__)
8
9+# This endpoint matches the format as found in dhcp lease files, since this
10+# value is applied if the endpoint can't be found within a lease file
11+DEFAULT_WIRESERVER_ENDPOINT = "a8:3f:81:10"
12
13 azure_ds_reporter = events.ReportEventStack(
14 name="azure-ds",
15@@ -297,7 +300,12 @@ class WALinuxAgentShim(object):
16 @azure_ds_telemetry_reporter
17 def _get_value_from_leases_file(fallback_lease_file):
18 leases = []
19- content = util.load_file(fallback_lease_file)
20+ try:
21+ content = util.load_file(fallback_lease_file)
22+ except IOError as ex:
23+ LOG.error("Failed to read %s: %s", fallback_lease_file, ex)
24+ return None
25+
26 LOG.debug("content is %s", content)
27 option_name = _get_dhcp_endpoint_option_name()
28 for line in content.splitlines():
29@@ -372,9 +380,9 @@ class WALinuxAgentShim(object):
30 fallback_lease_file)
31 value = WALinuxAgentShim._get_value_from_leases_file(
32 fallback_lease_file)
33-
34 if value is None:
35- raise ValueError('No endpoint found.')
36+ LOG.warning("No lease found; using default endpoint")
37+ value = DEFAULT_WIRESERVER_ENDPOINT
38
39 endpoint_ip_address = WALinuxAgentShim.get_ip_from_lease_value(value)
40 LOG.debug('Azure endpoint found at %s', endpoint_ip_address)
41diff --git a/tests/unittests/test_datasource/test_azure_helper.py b/tests/unittests/test_datasource/test_azure_helper.py
42index 0255616..bd006ab 100644
43--- a/tests/unittests/test_datasource/test_azure_helper.py
44+++ b/tests/unittests/test_datasource/test_azure_helper.py
45@@ -67,12 +67,17 @@ class TestFindEndpoint(CiTestCase):
46 self.networkd_leases.return_value = None
47
48 def test_missing_file(self):
49- self.assertRaises(ValueError, wa_shim.find_endpoint)
50+ """wa_shim find_endpoint uses default endpoint if leasefile not found
51+ """
52+ self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
53
54 def test_missing_special_azure_line(self):
55+ """wa_shim find_endpoint uses default endpoint if leasefile is found
56+ but does not contain DHCP Option 245 (whose value is the endpoint)
57+ """
58 self.load_file.return_value = ''
59 self.dhcp_options.return_value = {'eth0': {'key': 'value'}}
60- self.assertRaises(ValueError, wa_shim.find_endpoint)
61+ self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
62
63 @staticmethod
64 def _build_lease_content(encoded_address):

Subscribers

People subscribed via source and target branches