diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | cloudinit/helpers.py | 5 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceCloudStack.py | 3 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceConfigDrive.py | 2 | ||||
-rw-r--r-- | tests/unittests/helpers.py | 9 | ||||
-rw-r--r-- | tests/unittests/test_helpers.py | 33 |
6 files changed, 47 insertions, 9 deletions
@@ -105,6 +105,10 @@ - centos: Ensure that resolve conf object is written as a str (LP: #1479988) - chef: straighten out validation_cert and validation_key (LP: #1568940) - phone_home: allow usage of fqdn (LP: #1566824) [Ollie Armstrong] + - cloudstack: Only use DHCPv4 lease files as a datasource (LP: #1576273) + [Wido den Hollander] + - Paths: fix instance path if datasource's id has a '/'. (LP: #1575938) + [Robert Jennings] 0.7.6: - open 0.7.6 diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index e9fec628..7f00bf1f 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -375,10 +375,11 @@ class Paths(object): def _get_ipath(self, name=None): if not self.datasource: return None - iid = self.datasource.get_instance_id().replace(os.sep, '_') + iid = self.datasource.get_instance_id() if iid is None: return None - ipath = os.path.join(self.cloud_dir, 'instances', str(iid)) + path_safe_iid = str(iid).replace(os.sep, '_') + ipath = os.path.join(self.cloud_dir, 'instances', path_safe_iid) add_on = self.lookups.get(name) if add_on: ipath = os.path.join(ipath, add_on) diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py index 455a4652..4ba019df 100644 --- a/cloudinit/sources/DataSourceCloudStack.py +++ b/cloudinit/sources/DataSourceCloudStack.py @@ -206,7 +206,8 @@ def get_latest_lease(): latest_mtime = -1 latest_file = None for file_name in lease_files: - if file_name.endswith(".lease") or file_name.endswith(".leases"): + if file_name.startswith("dhclient.") and \ + (file_name.endswith(".lease") or file_name.endswith(".leases")): abs_path = os.path.join(lease_d, file_name) mtime = os.path.getmtime(abs_path) if mtime > latest_mtime: diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py index 3fa62ef3..52a9f543 100644 --- a/cloudinit/sources/DataSourceConfigDrive.py +++ b/cloudinit/sources/DataSourceConfigDrive.py @@ -155,7 +155,7 @@ class DataSourceConfigDrive(openstack.SourceMixin, sources.DataSource): return True - def check_instance_id(self): + def check_instance_id(self, sys_cfg): # quickly (local check only) if self.instance_id is still valid return sources.instance_id_matches_system_uuid(self.get_instance_id()) diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py index 7f4b8784..fb9c83a7 100644 --- a/tests/unittests/helpers.py +++ b/tests/unittests/helpers.py @@ -180,13 +180,12 @@ class ResourceUsingTestCase(TestCase): with open(where, 'r') as fh: return fh.read() - def getCloudPaths(self): + def getCloudPaths(self, ds=None): tmpdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmpdir) - cp = ch.Paths({ - 'cloud_dir': tmpdir, - 'templates_dir': self.resourceLocation(), - }) + cp = ch.Paths({'cloud_dir': tmpdir, + 'templates_dir': self.resourceLocation()}, + ds=ds) return cp diff --git a/tests/unittests/test_helpers.py b/tests/unittests/test_helpers.py new file mode 100644 index 00000000..943a5723 --- /dev/null +++ b/tests/unittests/test_helpers.py @@ -0,0 +1,33 @@ +"""Tests of the built-in user data handlers.""" + +import os + +from . import helpers as test_helpers + +from cloudinit import sources + + +class MyDataSource(sources.DataSource): + _instance_id = None + + def get_instance_id(self): + return self._instance_id + + +class TestPaths(test_helpers.ResourceUsingTestCase): + def test_get_ipath_and_instance_id_with_slashes(self): + myds = MyDataSource(sys_cfg={}, distro=None, paths={}) + myds._instance_id = "/foo/bar" + safe_iid = "_foo_bar" + mypaths = self.getCloudPaths(myds) + + self.assertEqual( + os.path.join(mypaths.cloud_dir, 'instances', safe_iid), + mypaths.get_ipath()) + + def test_get_ipath_and_empty_instance_id_returns_none(self): + myds = MyDataSource(sys_cfg={}, distro=None, paths={}) + myds._instance_id = None + mypaths = self.getCloudPaths(myds) + + self.assertEqual(None, mypaths.get_ipath()) |