summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Howard <ben.howard@canonical.com>2014-02-07 13:49:03 +0200
committerBen Howard <ben.howard@canonical.com>2014-02-07 13:49:03 +0200
commitceffb35a2ddfb5f309417aaa68e7ff70199690fa (patch)
treea0810797bd45c06ce913d788b507021e747e0a49
parent3087da32ec5cf84c51e0ebdd80a71a84b174a392 (diff)
downloadvyos-cloud-init-ceffb35a2ddfb5f309417aaa68e7ff70199690fa.tar.gz
vyos-cloud-init-ceffb35a2ddfb5f309417aaa68e7ff70199690fa.zip
Made new ovf-env.xml handling more robust. Test cases included
-rw-r--r--cloudinit/sources/DataSourceAzure.py16
-rw-r--r--tests/unittests/test_datasource/test_azure.py38
2 files changed, 48 insertions, 6 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 448915d7..eee36d22 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -84,21 +84,20 @@ class DataSourceAzureNet(sources.DataSource):
candidates = [self.seed_dir]
candidates.extend(list_possible_azure_ds_devs())
+ previous_ovf_cfg = None
if ddir:
candidates.append(ddir)
+ previous_ovf_cfg = None
+ if os.path.exists("%s/ovf-env.xml" % ddir):
+ previous_ovf_cfg = load_azure_ds_dir(ddir)
+
found = None
for cdev in candidates:
try:
if cdev.startswith("/dev/"):
ret = util.mount_cb(cdev, load_azure_ds_dir)
-
- # If we load the OVF from a device, it means that a
- # new ovf-env.xml has been found. (LP: #1269626)
- if os.path.exists(ddir):
- LOG.info("removing old agent directory %s" % ddir)
- util.del_dir(ddir)
else:
ret = load_azure_ds_dir(cdev)
@@ -110,6 +109,11 @@ class DataSourceAzureNet(sources.DataSource):
LOG.warn("%s was not mountable" % cdev)
continue
+ if ret != previous_ovf_cfg:
+ LOG.info(("instance configuration has changed, "
+ "removing old agent directory"))
+ util.del_dir(ddir)
+
(md, self.userdata_raw, cfg, files) = ret
self.seed = cdev
self.metadata = util.mergemanydict([md, DEFAULT_METADATA])
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index aad84206..aa541a18 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -119,6 +119,10 @@ class TestAzureDataSource(MockerTestCase):
{'ovf-env.xml': data['ovfcontent']})
mod = DataSourceAzure
+ ddir = "%s/var/lib/waagent" % self.tmp
+ mod.BUILTIN_DS_CONFIG['data_dir'] = ddir
+ if not os.path.isdir(ddir):
+ os.makedirs(ddir)
self.apply_patches([(mod, 'list_possible_azure_ds_devs', dsdevs)])
@@ -338,6 +342,40 @@ class TestAzureDataSource(MockerTestCase):
self.assertEqual(userdata, dsrc.userdata_raw)
+ def test_existing_ovf_same(self):
+ mydata = "FOOBAR"
+ odata = {'UserData': base64.b64encode(mydata)}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
+
+ with open("%s/ovf-env.xml" % self.tmp, 'w') as fp:
+ fp.write(construct_valid_ovf_env(data=odata))
+ with open("%s/sem" % self.tmp, 'w') as fp:
+ fp.write("test")
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertEqual(dsrc.userdata_raw, mydata)
+ self.assertTrue(os.path.exists("%s/sem" % self.tmp))
+
+ def test_existing_ovf_diff(self):
+ mydata = "FOOBAR"
+ odata = {'UserData': base64.b64encode(mydata)}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
+
+ data_dir = "%s/var/lib/waagent" % self.tmp
+ os.makedirs(data_dir)
+ with open("%s/ovf-env.xml" % data_dir, 'w') as fp:
+ fp.write(construct_valid_ovf_env())
+ with open("%s/sem" % data_dir, 'w') as fp:
+ fp.write("test")
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertEqual(dsrc.userdata_raw, mydata)
+ self.assertFalse(os.path.exists("%s/sem" % data_dir))
+
class TestReadAzureOvf(MockerTestCase):
def test_invalid_xml_raises_non_azure_ds(self):