forked from ungleich-public/cdist
update a lot of tests for new exec.local
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
af24165367
commit
528901bdee
7 changed files with 57 additions and 15 deletions
|
@ -24,7 +24,6 @@ import os
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
|
|
||||||
|
|
||||||
class NoSuchTypeError(cdist.Error):
|
class NoSuchTypeError(cdist.Error):
|
||||||
def __init__(self, type_path, type_absolute_path):
|
def __init__(self, type_path, type_absolute_path):
|
||||||
self.type_path = type_path
|
self.type_path = type_path
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Local(object):
|
||||||
if 'HOME' in os.environ:
|
if 'HOME' in os.environ:
|
||||||
return os.path.join(os.environ['HOME'], ".cdist")
|
return os.path.join(os.environ['HOME'], ".cdist")
|
||||||
else:
|
else:
|
||||||
return = None
|
return None
|
||||||
|
|
||||||
def _init_log(self):
|
def _init_log(self):
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.log = logging.getLogger(self.target_host)
|
||||||
|
|
|
@ -34,7 +34,7 @@ import cdist.context
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
add_conf_dir = op.join(fixtures, 'conf')
|
||||||
|
|
||||||
|
|
||||||
class AutorequireTestCase(test.CdistTestCase):
|
class AutorequireTestCase(test.CdistTestCase):
|
||||||
|
@ -48,7 +48,9 @@ class AutorequireTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
self.context = cdist.context.Context(
|
self.context = cdist.context.Context(
|
||||||
target_host=self.target_host,
|
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,
|
exec_path=test.cdist_exec_path,
|
||||||
debug=False)
|
debug=False)
|
||||||
self.config = config.Config(self.context)
|
self.config = config.Config(self.context)
|
||||||
|
|
|
@ -44,7 +44,7 @@ class CodeTestCase(test.CdistTestCase):
|
||||||
self.local_base_path = local_base_path
|
self.local_base_path = local_base_path
|
||||||
self.out_path = self.mkdtemp()
|
self.out_path = self.mkdtemp()
|
||||||
self.local = local.Local(self.target_host, self.local_base_path, self.out_path)
|
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.remote_base_path = self.mkdtemp()
|
||||||
self.user = getpass.getuser()
|
self.user = getpass.getuser()
|
||||||
|
|
|
@ -33,8 +33,6 @@ from cdist import core
|
||||||
from cdist import config
|
from cdist import config
|
||||||
import cdist.context
|
import cdist.context
|
||||||
|
|
||||||
local_base_path = test.cdist_base_path
|
|
||||||
|
|
||||||
class EmulatorTestCase(test.CdistTestCase):
|
class EmulatorTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -45,7 +43,10 @@ class EmulatorTestCase(test.CdistTestCase):
|
||||||
os.close(handle)
|
os.close(handle)
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
out_path = self.temp_dir
|
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.local.create_files_dirs()
|
||||||
self.env = {
|
self.env = {
|
||||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
||||||
|
@ -112,8 +113,10 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase):
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
out_path = self.temp_dir
|
out_path = self.temp_dir
|
||||||
_local_base_path = fixtures
|
self.local = local.Local(
|
||||||
self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path)
|
target_host=self.target_host,
|
||||||
|
out_path=out_path,
|
||||||
|
exec_path=test.cdist_exec_path)
|
||||||
self.local.create_files_dirs()
|
self.local.create_files_dirs()
|
||||||
self.manifest = core.Manifest(self.target_host, self.local)
|
self.manifest = core.Manifest(self.target_host, self.local)
|
||||||
|
|
||||||
|
@ -138,9 +141,13 @@ class ArgumentsTestCase(test.CdistTestCase):
|
||||||
out_path = self.temp_dir
|
out_path = self.temp_dir
|
||||||
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
||||||
os.close(handle)
|
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.local.create_files_dirs()
|
||||||
|
|
||||||
self.env = {
|
self.env = {
|
||||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
||||||
'__target_host': self.target_host,
|
'__target_host': self.target_host,
|
||||||
|
@ -228,13 +235,11 @@ class StdinTestCase(test.CdistTestCase):
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
os.environ['__cdist_out_dir'] = self.temp_dir
|
os.environ['__cdist_out_dir'] = self.temp_dir
|
||||||
local_base_path = fixtures
|
|
||||||
|
|
||||||
self.context = cdist.context.Context(
|
self.context = cdist.context.Context(
|
||||||
target_host=self.target_host,
|
target_host=self.target_host,
|
||||||
remote_copy='scp -o User=root -q',
|
remote_copy='scp -o User=root -q',
|
||||||
remote_exec='ssh -o User=root -q',
|
remote_exec='ssh -o User=root -q',
|
||||||
base_path=local_base_path,
|
|
||||||
exec_path=test.cdist_exec_path,
|
exec_path=test.cdist_exec_path,
|
||||||
debug=False)
|
debug=False)
|
||||||
self.config = config.Config(self.context)
|
self.config = config.Config(self.context)
|
||||||
|
|
|
@ -33,6 +33,7 @@ from cdist.exec import local
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
|
conf_dir = op.join(fixtures, "conf")
|
||||||
|
|
||||||
class LocalTestCase(test.CdistTestCase):
|
class LocalTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
|
@ -86,6 +87,41 @@ class LocalTestCase(test.CdistTestCase):
|
||||||
def test_type_path(self):
|
def test_type_path(self):
|
||||||
self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type"))
|
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
|
### other tests
|
||||||
|
|
||||||
def test_run_success(self):
|
def test_run_success(self):
|
||||||
|
|
|
@ -45,7 +45,7 @@ class ExplorerClassTestCase(test.CdistTestCase):
|
||||||
self.local_base_path = local_base_path
|
self.local_base_path = local_base_path
|
||||||
self.out_path = self.mkdtemp()
|
self.out_path = self.mkdtemp()
|
||||||
self.local = local.Local(self.target_host, self.local_base_path, self.out_path)
|
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.remote_base_path = self.mkdtemp()
|
||||||
self.user = getpass.getuser()
|
self.user = getpass.getuser()
|
||||||
|
|
Loading…
Reference in a new issue