Merge "Use FHS-compliant default template location"

This commit is contained in:
Jenkins 2014-05-02 09:35:43 +00:00 committed by Gerrit Code Review
commit 6e9aa57e13
3 changed files with 53 additions and 6 deletions

View File

@ -29,12 +29,35 @@ from os_apply_config import renderers
from os_apply_config import value_types
from os_apply_config import version
TEMPLATES_DIR = os.environ.get('OS_CONFIG_APPLIER_TEMPLATES', None)
if TEMPLATES_DIR is None:
TEMPLATES_DIR = '/opt/stack/os-apply-config/templates'
if not os.path.isdir(TEMPLATES_DIR):
# Backwards compat with the old name.
TEMPLATES_DIR = '/opt/stack/os-config-applier/templates'
DEFAULT_TEMPLATES_DIR = '/usr/libexec/os-apply-config/templates'
def templates_dir():
"""Determine the default templates directory path
If the OS_CONFIG_APPLIER_TEMPLATES environment variable has been set,
use its value.
Otherwise, select a default path based on which directories exist on the
system, preferring the newer paths but still allowing the old ones for
backwards compatibility.
"""
templates_dir = os.environ.get('OS_CONFIG_APPLIER_TEMPLATES', None)
if templates_dir is None:
templates_dir = '/opt/stack/os-apply-config/templates'
if not os.path.isdir(templates_dir):
# Backwards compat with the old name.
templates_dir = '/opt/stack/os-config-applier/templates'
if (os.path.isdir(templates_dir) and
not os.path.isdir(DEFAULT_TEMPLATES_DIR)):
logging.warning('Template directory %s is deprecated. The '
'recommended location for template files is %s',
templates_dir, DEFAULT_TEMPLATES_DIR)
else:
templates_dir = DEFAULT_TEMPLATES_DIR
return templates_dir
TEMPLATES_DIR = templates_dir()
OS_CONFIG_FILES_PATH = os.environ.get(
'OS_CONFIG_FILES_PATH', '/var/lib/os-collect-config/os_config_files.json')
OS_CONFIG_FILES_PATH_OLD = '/var/run/os-collect-config/os_config_files.json'

View File

@ -19,6 +19,7 @@ import os
import tempfile
import fixtures
import mock
import testtools
from os_apply_config import apply_config
@ -283,3 +284,25 @@ class OSConfigApplierTestCase(testtools.TestCase):
err = self.assertRaises(ValueError, load_list, path)
self.assertEqual(
"No list defined in json file: %s" % path, str(err))
def test_default_templates_dir_current(self):
default = '/usr/libexec/os-apply-config/templates'
with mock.patch('os.path.isdir', lambda x: x == default):
self.assertEqual(default, apply_config.templates_dir())
def test_default_templates_dir_deprecated(self):
default = '/opt/stack/os-apply-config/templates'
with mock.patch('os.path.isdir', lambda x: x == default):
self.assertEqual(default, apply_config.templates_dir())
def test_default_templates_dir_old_deprecated(self):
default = '/opt/stack/os-config-applier/templates'
with mock.patch('os.path.isdir', lambda x: x == default):
self.assertEqual(default, apply_config.templates_dir())
def test_default_templates_dir_both(self):
default = '/usr/libexec/os-apply-config/templates'
deprecated = '/opt/stack/os-apply-config/templates'
with mock.patch('os.path.isdir', lambda x: (x == default or
x == deprecated)):
self.assertEqual(default, apply_config.templates_dir())

View File

@ -3,6 +3,7 @@ hacking>=0.8.0,<0.9
coverage>=3.6
discover
fixtures>=0.3.14
mock>=1.0
python-subunit>=0.0.18
sphinx>=1.1.2,<1.2
testrepository>=0.0.18