summaryrefslogtreecommitdiff
path: root/cloudinit/tests/helpers.py
diff options
context:
space:
mode:
authorFrancis Ginther <francis.ginther@canonical.com>2018-09-01 17:59:18 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-09-01 17:59:18 +0000
commit3f6d0972d83c8bfd6a5e666d73cb84a8cfe9c8b6 (patch)
tree8aab0df61afa66a0c2122e85fed9fd838aca357e /cloudinit/tests/helpers.py
parent2d0ca72cde42f72babbce5823ea3bbf30a61021c (diff)
downloadvyos-cloud-init-3f6d0972d83c8bfd6a5e666d73cb84a8cfe9c8b6.tar.gz
vyos-cloud-init-3f6d0972d83c8bfd6a5e666d73cb84a8cfe9c8b6.zip
Add unit tests for config/cc_ssh.py
These tests focus on the apply_credentials method and the ssh setup for root and a distro default user.
Diffstat (limited to 'cloudinit/tests/helpers.py')
-rw-r--r--cloudinit/tests/helpers.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py
index a022a7a0..de24e25d 100644
--- a/cloudinit/tests/helpers.py
+++ b/cloudinit/tests/helpers.py
@@ -27,7 +27,10 @@ except ImportError:
from cloudinit.config.schema import (
SchemaValidationError, validate_cloudconfig_schema)
+from cloudinit import cloud
+from cloudinit import distros
from cloudinit import helpers as ch
+from cloudinit.sources import DataSourceNone
from cloudinit import util
# Used for skipping tests
@@ -187,6 +190,29 @@ class CiTestCase(TestCase):
"""
raise SystemExit(code)
+ def tmp_cloud(self, distro, sys_cfg=None, metadata=None):
+ """Create a cloud with tmp working directory paths.
+
+ @param distro: Name of the distro to attach to the cloud.
+ @param metadata: Optional metadata to set on the datasource.
+
+ @return: The built cloud instance.
+ """
+ self.new_root = self.tmp_dir()
+ if not sys_cfg:
+ sys_cfg = {}
+ tmp_paths = {}
+ for var in ['templates_dir', 'run_dir', 'cloud_dir']:
+ tmp_paths[var] = self.tmp_path(var, dir=self.new_root)
+ util.ensure_dir(tmp_paths[var])
+ self.paths = ch.Paths(tmp_paths)
+ cls = distros.fetch(distro)
+ mydist = cls(distro, sys_cfg, self.paths)
+ myds = DataSourceNone.DataSourceNone(sys_cfg, mydist, self.paths)
+ if metadata:
+ myds.metadata.update(metadata)
+ return cloud.Cloud(myds, self.paths, sys_cfg, mydist, None)
+
class ResourceUsingTestCase(CiTestCase):