implement conf-dir from CDIST_PATH environment variable

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2012-11-30 13:48:34 +01:00
parent de9b38a201
commit 56b6c95ed4
4 changed files with 37 additions and 6 deletions

View file

@ -38,7 +38,7 @@ class Context(object):
remote_copy,
remote_exec,
initial_manifest=False,
add_conf_dirs=[],
add_conf_dirs=None,
exec_path=sys.argv[0],
debug=False):

View file

@ -23,6 +23,7 @@
import io
import os
import sys
import re
import subprocess
import shutil
import logging
@ -37,7 +38,7 @@ class Local(object):
Directly accessing the local side from python code is a bug.
"""
def __init__(self, target_host, out_path, exec_path, add_conf_dirs=[], cache_dir=None):
def __init__(self, target_host, out_path, exec_path, add_conf_dirs=None, cache_dir=None):
self.target_host = target_host
self.out_path = out_path
@ -92,6 +93,12 @@ class Local(object):
if self.home_dir:
self.conf_dirs.append(self.home_dir)
# Add directories defined in the CDIST_PATH environment variable
if 'CDIST_PATH' in os.environ:
cdist_path_dirs = re.split(r'(?<!\\):', os.environ['CDIST_PATH'])
cdist_path_dirs.reverse()
self.conf_dirs.extend(cdist_path_dirs)
# Add user supplied directories
if self._add_conf_dirs:
self.conf_dirs.extend(self._add_conf_dirs)

View file

@ -122,6 +122,25 @@ class LocalTestCase(test.CdistTestCase):
self.assertTrue(os.path.isdir(our_type_dir))
def test_conf_dir_from_path_linking(self):
"""Ensure that links are correctly created for types in conf directories which are defined in CDIST_PATH"""
test_type="__cdist_test_type"
os.environ['CDIST_PATH'] = conf_dir
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))
### other tests
def test_run_success(self):

View file

@ -14,7 +14,7 @@ cdist [-h] [-V]
cdist banner
cdist config [-h] [-d] [-V] [-c CDIST_HOME] [-i MANIFEST] [-p] [-s] host [host ...]
cdist config [-h] [-d] [-V] [-c CONF_DIR] [-i MANIFEST] [-p] [-s] host [host ...]
@ -43,9 +43,14 @@ Configure a system
-h, --help::
Show the help screen
-c CDIST_HOME, --cdist-home CDIST_HOME::
Instead of using the parent of the bin directory as cdist home,
use the specified directory
-c CONF_DIR, --conf-dir CONF_DIR::
Add a configuration directory. Can be specified multiple times.
If configuration directories contain conflicting types, explorers or
manifests, then the last one found is used. Additionally this can also
be configured by setting the CDIST_PATH environment variable to a colon
delimited list of config directories. Directories given with the
--conf-dir argument have higher precedence over those set through the
environment variable.
-d, --debug::
Enable debug output