Fix exec/{local,remote} tests. Add exec/local test to make test.

This commit is contained in:
Darko Poljak 2017-09-10 22:05:05 +02:00
parent 3f6a300567
commit 519eb60664
3 changed files with 22 additions and 5 deletions

View file

@ -0,0 +1,7 @@
from .local import *
if __name__ == "__main__":
import unittest
unittest.main()

View file

@ -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"])

View file

@ -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