← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:bug/lp1538522-azure-builtin-agent into cloud-init:master

 

Dan Watkins has proposed merging ~daniel-thewatkins/cloud-init/+git/cloud-init:bug/lp1538522-azure-builtin-agent into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1538522 in cloud-init: "Calls "service walinuxagent start" in Azure data source"
  https://bugs.launchpad.net/cloud-init/+bug/1538522

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/311164
-- 
Your team cloud init development team is requested to review the proposed merge of ~daniel-thewatkins/cloud-init/+git/cloud-init:bug/lp1538522-azure-builtin-agent into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index b802b03..8b9ccd6 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -38,13 +38,14 @@ LOG = logging.getLogger(__name__)
 DS_NAME = 'Azure'
 DEFAULT_METADATA = {"instance-id": "iid-AZURE-NODE"}
 AGENT_START = ['service', 'walinuxagent', 'start']
+AGENT_START_BUILTIN = "__builtin__"
 BOUNCE_COMMAND = [
     'sh', '-xc',
     "i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x"
 ]
 
 BUILTIN_DS_CONFIG = {
-    'agent_command': AGENT_START,
+    'agent_command': AGENT_START_BUILTIN,
     'data_dir': "/var/lib/waagent",
     'set_hostname': True,
     'hostname_bounce': {
@@ -229,7 +230,7 @@ class DataSourceAzureNet(sources.DataSource):
         # the directory to be protected.
         write_files(ddir, files, dirmode=0o700)
 
-        if self.ds_cfg['agent_command'] == '__builtin__':
+        if self.ds_cfg['agent_command'] == AGENT_START_BUILTIN:
             metadata_func = partial(get_metadata_from_fabric,
                                     fallback_lease_file=self.
                                     dhclient_lease_file)
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index e90e903..d59aad6 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -93,7 +93,7 @@ class TestAzureDataSource(TestCase):
         for module, name, new in patches:
             self.patches.enter_context(mock.patch.object(module, name, new))
 
-    def _get_ds(self, data):
+    def _get_ds(self, data, agent_command=None):
 
         def dsdevs():
             return data.get('dsdevs', [])
@@ -137,6 +137,8 @@ class TestAzureDataSource(TestCase):
 
         dsrc = mod.DataSourceAzureNet(
             data.get('sys_cfg', {}), distro=None, paths=self.paths)
+        if agent_command is not None:
+            dsrc.ds_cfg['agent_command'] = agent_command
 
         return dsrc
 
@@ -299,7 +301,7 @@ class TestAzureDataSource(TestCase):
         data = {'ovfcontent': construct_valid_ovf_env(data=odata,
                                                       pubkeys=pubkeys)}
 
-        dsrc = self._get_ds(data)
+        dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
         ret = dsrc.get_data()
         self.assertTrue(ret)
         for mypk in mypklist:
@@ -314,7 +316,7 @@ class TestAzureDataSource(TestCase):
         data = {'ovfcontent': construct_valid_ovf_env(data=odata,
                                                       pubkeys=pubkeys)}
 
-        dsrc = self._get_ds(data)
+        dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
         ret = dsrc.get_data()
         self.assertTrue(ret)
 
@@ -330,7 +332,7 @@ class TestAzureDataSource(TestCase):
         data = {'ovfcontent': construct_valid_ovf_env(data=odata,
                                                       pubkeys=pubkeys)}
 
-        dsrc = self._get_ds(data)
+        dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
         ret = dsrc.get_data()
         self.assertTrue(ret)
 
@@ -495,12 +497,15 @@ class TestAzureBounce(TestCase):
     def tearDown(self):
         self.patches.close()
 
-    def _get_ds(self, ovfcontent=None):
+    def _get_ds(self, ovfcontent=None, agent_command=None):
         if ovfcontent is not None:
             populate_dir(os.path.join(self.paths.seed_dir, "azure"),
                          {'ovf-env.xml': ovfcontent})
-        return DataSourceAzure.DataSourceAzureNet(
+        dsrc = DataSourceAzure.DataSourceAzureNet(
             {}, distro=None, paths=self.paths)
+        if agent_command is not None:
+            dsrc.ds_cfg['agent_command'] = agent_command
+        return dsrc
 
     def get_ovf_env_with_dscfg(self, hostname, cfg):
         odata = {
@@ -545,14 +550,17 @@ class TestAzureBounce(TestCase):
         host_name = 'unchanged-host-name'
         self.get_hostname.return_value = host_name
         cfg = {'hostname_bounce': {'policy': 'force'}}
-        self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg)).get_data()
+        self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg),
+                     agent_command=['not', '__builtin__']).get_data()
         self.assertEqual(1, perform_hostname_bounce.call_count)
 
     def test_different_hostnames_sets_hostname(self):
         expected_hostname = 'azure-expected-host-name'
         self.get_hostname.return_value = 'default-host-name'
         self._get_ds(
-            self.get_ovf_env_with_dscfg(expected_hostname, {})).get_data()
+            self.get_ovf_env_with_dscfg(expected_hostname, {}),
+            agent_command=['not', '__builtin__'],
+        ).get_data()
         self.assertEqual(expected_hostname,
                          self.set_hostname.call_args_list[0][0][0])
 
@@ -562,14 +570,18 @@ class TestAzureBounce(TestCase):
         expected_hostname = 'azure-expected-host-name'
         self.get_hostname.return_value = 'default-host-name'
         self._get_ds(
-            self.get_ovf_env_with_dscfg(expected_hostname, {})).get_data()
+            self.get_ovf_env_with_dscfg(expected_hostname, {}),
+            agent_command=['not', '__builtin__'],
+        ).get_data()
         self.assertEqual(1, perform_hostname_bounce.call_count)
 
     def test_different_hostnames_sets_hostname_back(self):
         initial_host_name = 'default-host-name'
         self.get_hostname.return_value = initial_host_name
         self._get_ds(
-            self.get_ovf_env_with_dscfg('some-host-name', {})).get_data()
+            self.get_ovf_env_with_dscfg('some-host-name', {}),
+            agent_command=['not', '__builtin__'],
+        ).get_data()
         self.assertEqual(initial_host_name,
                          self.set_hostname.call_args_list[-1][0][0])
 
@@ -580,7 +592,9 @@ class TestAzureBounce(TestCase):
         initial_host_name = 'default-host-name'
         self.get_hostname.return_value = initial_host_name
         self._get_ds(
-            self.get_ovf_env_with_dscfg('some-host-name', {})).get_data()
+            self.get_ovf_env_with_dscfg('some-host-name', {}),
+            agent_command=['not', '__builtin__'],
+        ).get_data()
         self.assertEqual(initial_host_name,
                          self.set_hostname.call_args_list[-1][0][0])
 
@@ -591,7 +605,7 @@ class TestAzureBounce(TestCase):
         self.get_hostname.return_value = old_hostname
         cfg = {'hostname_bounce': {'interface': interface, 'policy': 'force'}}
         data = self.get_ovf_env_with_dscfg(hostname, cfg)
-        self._get_ds(data).get_data()
+        self._get_ds(data, agent_command=['not', '__builtin__']).get_data()
         self.assertEqual(1, self.subp.call_count)
         bounce_env = self.subp.call_args[1]['env']
         self.assertEqual(interface, bounce_env['interface'])
@@ -603,7 +617,7 @@ class TestAzureBounce(TestCase):
         DataSourceAzure.BUILTIN_DS_CONFIG['hostname_bounce']['command'] = cmd
         cfg = {'hostname_bounce': {'policy': 'force'}}
         data = self.get_ovf_env_with_dscfg('some-hostname', cfg)
-        self._get_ds(data).get_data()
+        self._get_ds(data, agent_command=['not', '__builtin__']).get_data()
         self.assertEqual(1, self.subp.call_count)
         bounce_args = self.subp.call_args[1]['args']
         self.assertEqual(cmd, bounce_args)

Follow ups