From 528901bdeee3f963d42e30e0408edeb459b56732 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 15:20:10 +0100 Subject: [PATCH] update a lot of tests for new exec.local Signed-off-by: Nico Schottelius --- cdist/core/cdist_type.py | 1 - cdist/exec/local.py | 2 +- cdist/test/autorequire/__init__.py | 6 +++-- cdist/test/code/__init__.py | 2 +- cdist/test/emulator/__init__.py | 23 +++++++++++-------- cdist/test/exec/local.py | 36 ++++++++++++++++++++++++++++++ cdist/test/explorer/__init__.py | 2 +- 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index 86f3ced1..44e192fc 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -24,7 +24,6 @@ import os import cdist - class NoSuchTypeError(cdist.Error): def __init__(self, type_path, type_absolute_path): self.type_path = type_path diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 2f870033..7ef11458 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -60,7 +60,7 @@ class Local(object): if 'HOME' in os.environ: return os.path.join(os.environ['HOME'], ".cdist") else: - return = None + return None def _init_log(self): self.log = logging.getLogger(self.target_host) diff --git a/cdist/test/autorequire/__init__.py b/cdist/test/autorequire/__init__.py index 2263cbf9..bd763fd3 100644 --- a/cdist/test/autorequire/__init__.py +++ b/cdist/test/autorequire/__init__.py @@ -34,7 +34,7 @@ import cdist.context import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +add_conf_dir = op.join(fixtures, 'conf') class AutorequireTestCase(test.CdistTestCase): @@ -48,7 +48,9 @@ class AutorequireTestCase(test.CdistTestCase): self.context = cdist.context.Context( target_host=self.target_host, - base_path=local_base_path, + remote_copy='/bin/true', + remote_exec='/bin/true', + add_conf_dirs=add_conf_dir, exec_path=test.cdist_exec_path, debug=False) self.config = config.Config(self.context) diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index 8a8583d7..8bc937b0 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -44,7 +44,7 @@ class CodeTestCase(test.CdistTestCase): self.local_base_path = local_base_path self.out_path = self.mkdtemp() self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser() diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 679fd149..1b77bdb6 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -33,8 +33,6 @@ from cdist import core from cdist import config import cdist.context -local_base_path = test.cdist_base_path - class EmulatorTestCase(test.CdistTestCase): def setUp(self): @@ -45,7 +43,10 @@ class EmulatorTestCase(test.CdistTestCase): os.close(handle) self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path, test.cdist_exec_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), @@ -112,8 +113,10 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() self.target_host = 'localhost' out_path = self.temp_dir - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() self.manifest = core.Manifest(self.target_host, self.local) @@ -138,9 +141,13 @@ class ArgumentsTestCase(test.CdistTestCase): out_path = self.temp_dir handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() + self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), '__target_host': self.target_host, @@ -228,13 +235,11 @@ class StdinTestCase(test.CdistTestCase): self.target_host = 'localhost' self.temp_dir = self.mkdtemp() os.environ['__cdist_out_dir'] = self.temp_dir - local_base_path = fixtures self.context = cdist.context.Context( target_host=self.target_host, remote_copy='scp -o User=root -q', remote_exec='ssh -o User=root -q', - base_path=local_base_path, exec_path=test.cdist_exec_path, debug=False) self.config = config.Config(self.context) diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index f74302df..687c13a5 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -33,6 +33,7 @@ from cdist.exec import local import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') +conf_dir = op.join(fixtures, "conf") class LocalTestCase(test.CdistTestCase): @@ -86,6 +87,41 @@ class LocalTestCase(test.CdistTestCase): def test_type_path(self): self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type")) + def test_dist_conf_dir_linking(self): + """Ensure that links are correctly created for types included in distribution""" + + test_type="__file" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + + def test_added_conf_dir_linking(self): + """Ensure that links are correctly created for types in added conf directories""" + + test_type="__cdist_test_type" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir] + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + ### other tests def test_run_success(self): diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 257ad8a9..528cb786 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -45,7 +45,7 @@ class ExplorerClassTestCase(test.CdistTestCase): self.local_base_path = local_base_path self.out_path = self.mkdtemp() self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser()