Merge ~chad.smith/cloud-init:feature/azure-region-instance-data into cloud-init:master

Proposed by Chad Smith
Status: Merged
Approved by: Chad Smith
Approved revision: 46a452d2a580b2b95d44e10ae7df80557c5650dc
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~chad.smith/cloud-init:feature/azure-region-instance-data
Merge into: cloud-init:master
Diff against target: 99 lines (+49/-7)
2 files modified
cloudinit/sources/DataSourceAzure.py (+9/-0)
tests/unittests/test_datasource/test_azure.py (+40/-7)
Reviewer Review Type Date Requested Status
Ryan Harper Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+369199@code.launchpad.net

Commit message

azure: add region and AZ properties from imds compute location metadata

This allows cloud-init query region to show valid region data for Azure

Description of the change

to test:
make deb;
deploy an azumre vm and install cloud-init deb
cloud-init clean --logs --reboot
cloud-init query --all
cloud-init query region

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:a363bdd8d4795d3a11292bf59be93a061097ecca
https://jenkins.ubuntu.com/server/job/cloud-init-ci/747/
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/747/rebuild

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

Do we need to do anything with availability_zone ?

review: Needs Information
46a452d... by Chad Smith

azure: availability_zone from IMDS fault domain

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

PASSED: Continuous integration, rev:46a452d2a580b2b95d44e10ae7df80557c5650dc
https://jenkins.ubuntu.com/server/job/cloud-init-ci/748/
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/748/rebuild

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

Some inline comment/questions on what to return if we don't have 'imds' in metadata?

review: Needs Information
Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks for walking me through that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
2index b7440c1..d2fad9b 100755
3--- a/cloudinit/sources/DataSourceAzure.py
4+++ b/cloudinit/sources/DataSourceAzure.py
5@@ -684,6 +684,11 @@ class DataSourceAzure(sources.DataSource):
6 return
7
8 @property
9+ def availability_zone(self):
10+ return self.metadata.get(
11+ 'imds', {}).get('compute', {}).get('platformFaultDomain')
12+
13+ @property
14 def network_config(self):
15 """Generate a network config like net.generate_fallback_network() with
16 the following exceptions.
17@@ -701,6 +706,10 @@ class DataSourceAzure(sources.DataSource):
18 self._network_config = parse_network_config(nc_src)
19 return self._network_config
20
21+ @property
22+ def region(self):
23+ return self.metadata.get('imds', {}).get('compute', {}).get('location')
24+
25
26 def _partitions_on_device(devpath, maxnum=16):
27 # return a list of tuples (ptnum, path) for each part on devpath
28diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
29index afb614e..f27ef21 100644
30--- a/tests/unittests/test_datasource/test_azure.py
31+++ b/tests/unittests/test_datasource/test_azure.py
32@@ -84,6 +84,25 @@ def construct_valid_ovf_env(data=None, pubkeys=None,
33
34
35 NETWORK_METADATA = {
36+ "compute": {
37+ "location": "eastus2",
38+ "name": "my-hostname",
39+ "offer": "UbuntuServer",
40+ "osType": "Linux",
41+ "placementGroupId": "",
42+ "platformFaultDomain": "0",
43+ "platformUpdateDomain": "0",
44+ "publisher": "Canonical",
45+ "resourceGroupName": "srugroup1",
46+ "sku": "19.04-DAILY",
47+ "subscriptionId": "12aad61c-6de4-4e53-a6c6-5aff52a83777",
48+ "tags": "",
49+ "version": "19.04.201906190",
50+ "vmId": "ff702a6b-cb6a-4fcd-ad68-b4ce38227642",
51+ "vmScaleSetName": "",
52+ "vmSize": "Standard_DS1_v2",
53+ "zone": ""
54+ },
55 "network": {
56 "interface": [
57 {
58@@ -478,13 +497,7 @@ scbus-1 on xpt0 bus 0
59 expected_metadata = {
60 'azure_data': {
61 'configurationsettype': 'LinuxProvisioningConfiguration'},
62- 'imds': {'network': {'interface': [{
63- 'ipv4': {'ipAddress': [
64- {'privateIpAddress': '10.0.0.4',
65- 'publicIpAddress': '104.46.124.81'}],
66- 'subnet': [{'address': '10.0.0.0', 'prefix': '24'}]},
67- 'ipv6': {'ipAddress': []},
68- 'macAddress': '000D3A047598'}]}},
69+ 'imds': NETWORK_METADATA,
70 'instance-id': 'test-instance-id',
71 'local-hostname': u'myhost',
72 'random_seed': 'wild'}
73@@ -612,6 +625,26 @@ scbus-1 on xpt0 bus 0
74 dsrc.get_data()
75 self.assertEqual(expected_network_config, dsrc.network_config)
76
77+ def test_availability_zone_set_from_imds(self):
78+ """Datasource.availability returns IMDS platformFaultDomain."""
79+ sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}}
80+ odata = {}
81+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
82+ 'sys_cfg': sys_cfg}
83+ dsrc = self._get_ds(data)
84+ dsrc.get_data()
85+ self.assertEqual('0', dsrc.availability_zone)
86+
87+ def test_region_set_from_imds(self):
88+ """Datasource.region returns IMDS region location."""
89+ sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}}
90+ odata = {}
91+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
92+ 'sys_cfg': sys_cfg}
93+ dsrc = self._get_ds(data)
94+ dsrc.get_data()
95+ self.assertEqual('eastus2', dsrc.region)
96+
97 def test_user_cfg_set_agent_command(self):
98 # set dscfg in via base64 encoded yaml
99 cfg = {'agent_command': "my_command"}

Subscribers

People subscribed via source and target branches