summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-10-24 10:31:21 -0400
committerScott Moser <smoser@brickies.net>2016-10-24 10:36:01 -0400
commit1e55f4127f356b930e2c1ad36dcb6bed24f3beb2 (patch)
tree5ad6c1171159b1daa031bb03ddcd8bdf903c07c8 /tests/unittests/helpers.py
parentf6ae1f9cb1495b14623eed60bef5afbdec85f607 (diff)
downloadvyos-cloud-init-1e55f4127f356b930e2c1ad36dcb6bed24f3beb2.tar.gz
vyos-cloud-init-1e55f4127f356b930e2c1ad36dcb6bed24f3beb2.zip
unittests: do not read system /etc/cloud/cloud.cfg.d
Many of the unit tests in test_data would inadvertantly read the system's /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d. This was first noticed on a system deployed by MAAS, where files in /etc/cloud/cloud.cfg.d/ are root read-only. This changes those tests to actually make use of FilesystemMockingTestCase functionality and adds 'reRoot()' to that class which is easier to use for at least this use case. LP: #1635350
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 1cdc05a1..a2355a79 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -205,6 +205,14 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
self.patched_funcs.enter_context(
mock.patch.object(sys, 'stderr', stderr))
+ def reRoot(self, root=None):
+ if root is None:
+ root = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, root)
+ self.patchUtils(root)
+ self.patchOS(root)
+ return root
+
def import_httpretty():
"""Import HTTPretty and monkey patch Python 3.4 issue.