Merge ~oddbloke/cloud-init/+git/cloud-init:bug/lp1538522-azure-builtin-agent into cloud-init:master

Proposed by Dan Watkins
Status: Merged
Merged at revision: 677b85abfb2558207956a199eaaceb91af07c076
Proposed branch: ~oddbloke/cloud-init/+git/cloud-init:bug/lp1538522-azure-builtin-agent
Merge into: cloud-init:master
Diff against target: 166 lines (+30/-15)
2 files modified
cloudinit/sources/DataSourceAzure.py (+3/-2)
tests/unittests/test_datasource/test_azure.py (+27/-13)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+311164@code.launchpad.net
To post a comment you must log in.

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 b802b03..8b9ccd6 100644
3--- a/cloudinit/sources/DataSourceAzure.py
4+++ b/cloudinit/sources/DataSourceAzure.py
5@@ -38,13 +38,14 @@ LOG = logging.getLogger(__name__)
6 DS_NAME = 'Azure'
7 DEFAULT_METADATA = {"instance-id": "iid-AZURE-NODE"}
8 AGENT_START = ['service', 'walinuxagent', 'start']
9+AGENT_START_BUILTIN = "__builtin__"
10 BOUNCE_COMMAND = [
11 'sh', '-xc',
12 "i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x"
13 ]
14
15 BUILTIN_DS_CONFIG = {
16- 'agent_command': AGENT_START,
17+ 'agent_command': AGENT_START_BUILTIN,
18 'data_dir': "/var/lib/waagent",
19 'set_hostname': True,
20 'hostname_bounce': {
21@@ -229,7 +230,7 @@ class DataSourceAzureNet(sources.DataSource):
22 # the directory to be protected.
23 write_files(ddir, files, dirmode=0o700)
24
25- if self.ds_cfg['agent_command'] == '__builtin__':
26+ if self.ds_cfg['agent_command'] == AGENT_START_BUILTIN:
27 metadata_func = partial(get_metadata_from_fabric,
28 fallback_lease_file=self.
29 dhclient_lease_file)
30diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
31index e90e903..d59aad6 100644
32--- a/tests/unittests/test_datasource/test_azure.py
33+++ b/tests/unittests/test_datasource/test_azure.py
34@@ -93,7 +93,7 @@ class TestAzureDataSource(TestCase):
35 for module, name, new in patches:
36 self.patches.enter_context(mock.patch.object(module, name, new))
37
38- def _get_ds(self, data):
39+ def _get_ds(self, data, agent_command=None):
40
41 def dsdevs():
42 return data.get('dsdevs', [])
43@@ -137,6 +137,8 @@ class TestAzureDataSource(TestCase):
44
45 dsrc = mod.DataSourceAzureNet(
46 data.get('sys_cfg', {}), distro=None, paths=self.paths)
47+ if agent_command is not None:
48+ dsrc.ds_cfg['agent_command'] = agent_command
49
50 return dsrc
51
52@@ -299,7 +301,7 @@ class TestAzureDataSource(TestCase):
53 data = {'ovfcontent': construct_valid_ovf_env(data=odata,
54 pubkeys=pubkeys)}
55
56- dsrc = self._get_ds(data)
57+ dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
58 ret = dsrc.get_data()
59 self.assertTrue(ret)
60 for mypk in mypklist:
61@@ -314,7 +316,7 @@ class TestAzureDataSource(TestCase):
62 data = {'ovfcontent': construct_valid_ovf_env(data=odata,
63 pubkeys=pubkeys)}
64
65- dsrc = self._get_ds(data)
66+ dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
67 ret = dsrc.get_data()
68 self.assertTrue(ret)
69
70@@ -330,7 +332,7 @@ class TestAzureDataSource(TestCase):
71 data = {'ovfcontent': construct_valid_ovf_env(data=odata,
72 pubkeys=pubkeys)}
73
74- dsrc = self._get_ds(data)
75+ dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
76 ret = dsrc.get_data()
77 self.assertTrue(ret)
78
79@@ -495,12 +497,15 @@ class TestAzureBounce(TestCase):
80 def tearDown(self):
81 self.patches.close()
82
83- def _get_ds(self, ovfcontent=None):
84+ def _get_ds(self, ovfcontent=None, agent_command=None):
85 if ovfcontent is not None:
86 populate_dir(os.path.join(self.paths.seed_dir, "azure"),
87 {'ovf-env.xml': ovfcontent})
88- return DataSourceAzure.DataSourceAzureNet(
89+ dsrc = DataSourceAzure.DataSourceAzureNet(
90 {}, distro=None, paths=self.paths)
91+ if agent_command is not None:
92+ dsrc.ds_cfg['agent_command'] = agent_command
93+ return dsrc
94
95 def get_ovf_env_with_dscfg(self, hostname, cfg):
96 odata = {
97@@ -545,14 +550,17 @@ class TestAzureBounce(TestCase):
98 host_name = 'unchanged-host-name'
99 self.get_hostname.return_value = host_name
100 cfg = {'hostname_bounce': {'policy': 'force'}}
101- self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg)).get_data()
102+ self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg),
103+ agent_command=['not', '__builtin__']).get_data()
104 self.assertEqual(1, perform_hostname_bounce.call_count)
105
106 def test_different_hostnames_sets_hostname(self):
107 expected_hostname = 'azure-expected-host-name'
108 self.get_hostname.return_value = 'default-host-name'
109 self._get_ds(
110- self.get_ovf_env_with_dscfg(expected_hostname, {})).get_data()
111+ self.get_ovf_env_with_dscfg(expected_hostname, {}),
112+ agent_command=['not', '__builtin__'],
113+ ).get_data()
114 self.assertEqual(expected_hostname,
115 self.set_hostname.call_args_list[0][0][0])
116
117@@ -562,14 +570,18 @@ class TestAzureBounce(TestCase):
118 expected_hostname = 'azure-expected-host-name'
119 self.get_hostname.return_value = 'default-host-name'
120 self._get_ds(
121- self.get_ovf_env_with_dscfg(expected_hostname, {})).get_data()
122+ self.get_ovf_env_with_dscfg(expected_hostname, {}),
123+ agent_command=['not', '__builtin__'],
124+ ).get_data()
125 self.assertEqual(1, perform_hostname_bounce.call_count)
126
127 def test_different_hostnames_sets_hostname_back(self):
128 initial_host_name = 'default-host-name'
129 self.get_hostname.return_value = initial_host_name
130 self._get_ds(
131- self.get_ovf_env_with_dscfg('some-host-name', {})).get_data()
132+ self.get_ovf_env_with_dscfg('some-host-name', {}),
133+ agent_command=['not', '__builtin__'],
134+ ).get_data()
135 self.assertEqual(initial_host_name,
136 self.set_hostname.call_args_list[-1][0][0])
137
138@@ -580,7 +592,9 @@ class TestAzureBounce(TestCase):
139 initial_host_name = 'default-host-name'
140 self.get_hostname.return_value = initial_host_name
141 self._get_ds(
142- self.get_ovf_env_with_dscfg('some-host-name', {})).get_data()
143+ self.get_ovf_env_with_dscfg('some-host-name', {}),
144+ agent_command=['not', '__builtin__'],
145+ ).get_data()
146 self.assertEqual(initial_host_name,
147 self.set_hostname.call_args_list[-1][0][0])
148
149@@ -591,7 +605,7 @@ class TestAzureBounce(TestCase):
150 self.get_hostname.return_value = old_hostname
151 cfg = {'hostname_bounce': {'interface': interface, 'policy': 'force'}}
152 data = self.get_ovf_env_with_dscfg(hostname, cfg)
153- self._get_ds(data).get_data()
154+ self._get_ds(data, agent_command=['not', '__builtin__']).get_data()
155 self.assertEqual(1, self.subp.call_count)
156 bounce_env = self.subp.call_args[1]['env']
157 self.assertEqual(interface, bounce_env['interface'])
158@@ -603,7 +617,7 @@ class TestAzureBounce(TestCase):
159 DataSourceAzure.BUILTIN_DS_CONFIG['hostname_bounce']['command'] = cmd
160 cfg = {'hostname_bounce': {'policy': 'force'}}
161 data = self.get_ovf_env_with_dscfg('some-hostname', cfg)
162- self._get_ds(data).get_data()
163+ self._get_ds(data, agent_command=['not', '__builtin__']).get_data()
164 self.assertEqual(1, self.subp.call_count)
165 bounce_args = self.subp.call_args[1]['args']
166 self.assertEqual(cmd, bounce_args)

Subscribers

People subscribed via source and target branches