Commit 0780b3ab authored by Scott Moser's avatar Scott Moser

Paths: fix instance path if datasource's id has a '/'.

If the datasource's instance id contained a '/' then the instance_id path
would not be as expected under /var/lib/cloud/instances/instance_id.


LP: #1575938
parents c92f0203 89fe4242
......@@ -107,6 +107,8 @@
- 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
......
......@@ -378,7 +378,8 @@ class Paths(object):
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)
......
......@@ -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
......
"""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())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment