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_copy,
remote_exec, remote_exec,
initial_manifest=False, initial_manifest=False,
add_conf_dirs=[], add_conf_dirs=None,
exec_path=sys.argv[0], exec_path=sys.argv[0],
debug=False): debug=False):

View file

@ -23,6 +23,7 @@
import io import io
import os import os
import sys import sys
import re
import subprocess import subprocess
import shutil import shutil
import logging import logging
@ -37,7 +38,7 @@ class Local(object):
Directly accessing the local side from python code is a bug. 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.target_host = target_host
self.out_path = out_path self.out_path = out_path
@ -92,6 +93,12 @@ class Local(object):
if self.home_dir: if self.home_dir:
self.conf_dirs.append(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 # Add user supplied directories
if self._add_conf_dirs: if self._add_conf_dirs:
self.conf_dirs.extend(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)) 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 ### other tests
def test_run_success(self): def test_run_success(self):

View file

@ -14,7 +14,7 @@ cdist [-h] [-V]
cdist banner 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:: -h, --help::
Show the help screen Show the help screen
-c CDIST_HOME, --cdist-home CDIST_HOME:: -c CONF_DIR, --conf-dir CONF_DIR::
Instead of using the parent of the bin directory as cdist home, Add a configuration directory. Can be specified multiple times.
use the specified directory 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:: -d, --debug::
Enable debug output Enable debug output