From 519eb606645a56fa984abb0833b6412ba175d34f Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sun, 10 Sep 2017 22:05:05 +0200 Subject: [PATCH] Fix exec/{local,remote} tests. Add exec/local test to make test. --- cdist/test/exec/__init__.py | 7 +++++++ cdist/test/exec/local.py | 11 ++++++++++- cdist/test/exec/remote.py | 9 +++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cdist/test/exec/__init__.py b/cdist/test/exec/__init__.py index e69de29b..b55cffa9 100644 --- a/cdist/test/exec/__init__.py +++ b/cdist/test/exec/__init__.py @@ -0,0 +1,7 @@ +from .local import * + + +if __name__ == "__main__": + import unittest + + unittest.main() diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index 1b298143..0e0cc755 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -61,6 +61,7 @@ class LocalTestCase(test.CdistTestCase): self.local = local.Local( target_host=target_host, + target_host_tags=None, base_root_path=self.host_base_path, host_dir_name=self.hostdir, exec_path=test.cdist_exec_path @@ -124,6 +125,7 @@ class LocalTestCase(test.CdistTestCase): 'localhost', 'localhost', ), + target_host_tags=None, base_root_path=self.host_base_path, host_dir_name=self.hostdir, exec_path=test.cdist_exec_path, @@ -147,6 +149,7 @@ class LocalTestCase(test.CdistTestCase): 'localhost', 'localhost', ), + target_host_tags=None, base_root_path=self.host_base_path, host_dir_name=self.hostdir, exec_path=test.cdist_exec_path, @@ -176,10 +179,11 @@ class LocalTestCase(test.CdistTestCase): 'localhost', 'localhost', ), + target_host_tags=None, base_root_path=self.host_base_path, host_dir_name=self.hostdir, exec_path=test.cdist_exec_path, - configuration=configuration + configuration=configuration.get_config(section='GLOBAL') ) link_test_local._create_conf_path_and_link_conf_dirs() @@ -191,24 +195,29 @@ class LocalTestCase(test.CdistTestCase): # other tests def test_run_success(self): + self.local.create_files_dirs() self.local.run([bin_true]) def test_run_fail(self): + self.local.create_files_dirs() self.assertRaises(cdist.Error, self.local.run, [bin_false]) def test_run_script_success(self): + self.local.create_files_dirs() handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", bin_true]) self.local.run_script(script) def test_run_script_fail(self): + self.local.create_files_dirs() handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", bin_false]) self.assertRaises(cdist.Error, self.local.run_script, script) def test_run_script_get_output(self): + self.local.create_files_dirs() handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", "echo foobar"]) diff --git a/cdist/test/exec/remote.py b/cdist/test/exec/remote.py index 371d17e3..723d6ddd 100644 --- a/cdist/test/exec/remote.py +++ b/cdist/test/exec/remote.py @@ -22,8 +22,6 @@ import os import getpass import shutil -import string -import random import multiprocessing import cdist @@ -40,7 +38,8 @@ class RemoteTestCase(test.CdistTestCase): 'localhost', 'localhost', ) - self.base_path = self.temp_dir + # another temp dir for remote base path + self.base_path = self.mkdtemp() user = getpass.getuser() remote_exec = "ssh -o User=%s -q" % user remote_copy = "scp -o User=%s -q" % user @@ -113,7 +112,8 @@ class RemoteTestCase(test.CdistTestCase): os.close(handle) target = self.mkdtemp(dir=self.temp_dir) self.remote.transfer(source, target) - self.assertTrue(os.path.isfile(target)) + self.assertTrue(os.path.isfile( + os.path.join(target, os.path.basename(source)))) def test_transfer_dir(self): source = self.mkdtemp(dir=self.temp_dir) @@ -206,6 +206,7 @@ class RemoteTestCase(test.CdistTestCase): output = r.run_script(script, env=env, return_output=True) self.assertEqual(output, "test_object\n") + if __name__ == '__main__': import unittest