summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-19 17:58:41 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-19 17:58:41 -0700
commit43eb6d5aace53bef2116dde0796807befef1d8ff (patch)
tree4e19b985cb97fd1293f9617c2b800e5377fc8494 /cloudinit/helpers.py
parentb492cedaa5a4e66f4f4c589fc73f53afade7b904 (diff)
downloadvyos-cloud-init-43eb6d5aace53bef2116dde0796807befef1d8ff.tar.gz
vyos-cloud-init-43eb6d5aace53bef2116dde0796807befef1d8ff.zip
Make most of all the places use the paths join() function so that testing with non-real read/write paths is easier.
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r--cloudinit/helpers.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 3938e7ee..9f55a984 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -208,17 +208,18 @@ class Paths(object):
def __init__(self, path_cfgs, ds=None):
self.cfgs = path_cfgs
# Populate all the initial paths
- self.cloud_dir = self.join_paths(False,
- path_cfgs.get('cloud_dir',
- '/var/lib/cloud'))
+ self.cloud_dir = self.join(False,
+ path_cfgs.get('cloud_dir',
+ '/var/lib/cloud'))
self.instance_link = os.path.join(self.cloud_dir, 'instance')
self.boot_finished = os.path.join(self.instance_link, "boot-finished")
self.upstart_conf_d = path_cfgs.get('upstart_dir')
- template_dir = self.join_paths(True,
- path_cfgs.get('templates_dir',
- '/etc/cloud/templates/'))
- self.template_tpl = os.path.join(template_dir, '%s.tmpl')
+ if self.upstart_conf_d:
+ self.upstart_conf_d = self.join(False, self.upstart_conf_d)
self.seed_dir = os.path.join(self.cloud_dir, 'seed')
+ # This one isn't joined, since it should just be read-only
+ template_dir = path_cfgs.get('templates_dir', '/etc/cloud/templates/')
+ self.template_tpl = os.path.join(template_dir, '%s.tmpl')
self.lookups = {
"handlers": "handlers",
"scripts": "scripts",
@@ -235,16 +236,25 @@ class Paths(object):
# joins the paths but also appends a read
# or write root if available
- def join_paths(self, read_only, *paths):
+ def join(self, read_only, *paths):
if read_only:
- root = self.cfgs.get('read_root', '/')
+ root = self.cfgs.get('read_root')
else:
- root = self.cfgs.get('write_root', '/')
+ root = self.cfgs.get('write_root')
if not paths:
return root
- joined = os.path.join(*paths)
+ if len(paths) > 1:
+ joined = os.path.join(*paths)
+ else:
+ joined = paths[0]
if root:
- joined = os.path.join(root, joined.lstrip("/"))
+ pre_joined = joined
+ # Need to remove any starting '/' since this
+ # will confuse os.path.join
+ joined = joined.lstrip("/")
+ joined = os.path.join(root, joined)
+ LOG.debug("Translated %s to adjusted path %s (%s)",
+ pre_joined, joined, read_only)
return joined
# get_ipath_cur: get the current instance path for an item