summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-01 20:00:34 -0400
committerScott Moser <smoser@ubuntu.com>2012-09-01 20:00:34 -0400
commit3a35daa68ca7e6214be3f9c1e33a1cdde5f60eb4 (patch)
tree6ffb19dd525035cba407bdd8354a6832b78718e2 /tests/unittests/helpers.py
parent47a643296f6656bfda1ea13b5bc98dd4b60d7852 (diff)
parenta7bd5c448a6eda8b3d841f2dd5c73ed3956fe3c3 (diff)
downloadvyos-cloud-init-3a35daa68ca7e6214be3f9c1e33a1cdde5f60eb4.tar.gz
vyos-cloud-init-3a35daa68ca7e6214be3f9c1e33a1cdde5f60eb4.zip
improvements for launch index, one fix for cloud-archive
1. Docs for launch-index + examples 2. Tests for launch-index + data files 3. Fixing a bug with cloud-archive yaml types allowed (likes a tuple not a list for some reason) (LP: #1044594) 4. Setting the 'part' content-type if what we actually use is different. LP: #1044594
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
new file mode 100644
index 00000000..d0f09e70
--- /dev/null
+++ b/tests/unittests/helpers.py
@@ -0,0 +1,42 @@
+import os
+
+from mocker import MockerTestCase
+
+from cloudinit import helpers as ch
+
+
+class ResourceUsingTestCase(MockerTestCase):
+ def __init__(self, methodName="runTest"):
+ MockerTestCase.__init__(self, methodName)
+ self.resource_path = None
+
+ def resourceLocation(self, subname=None):
+ if self.resource_path is None:
+ paths = [
+ os.path.join('tests', 'data'),
+ os.path.join('data'),
+ os.path.join(os.pardir, 'tests', 'data'),
+ os.path.join(os.pardir, 'data'),
+ ]
+ for p in paths:
+ if os.path.isdir(p):
+ self.resource_path = p
+ break
+ self.assertTrue((self.resource_path and
+ os.path.isdir(self.resource_path)),
+ msg="Unable to locate test resource data path!")
+ if not subname:
+ return self.resource_path
+ return os.path.join(self.resource_path, subname)
+
+ def readResource(self, name):
+ where = self.resourceLocation(name)
+ with open(where, 'r') as fh:
+ return fh.read()
+
+ def getCloudPaths(self):
+ cp = ch.Paths({
+ 'cloud_dir': self.makeDir(),
+ 'templates_dir': self.resourceLocation(),
+ })
+ return cp