Use FHS-compliant default template location
/opt/stack is a very OpenStack-specific location to use as a default for a project that is intended to be usable elsewhere. This changes the default template directory to reside in /usr/libexec and deprecates the /opt/stack location, but still allows the use of /opt/stack so existing users won't be adversely affected. Change-Id: I3b7d356985a2c213303d52e36aec34e350f9b553
This commit is contained in:
parent
a8cb935ab0
commit
31b7e64136
@ -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):
|
||||
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'
|
||||
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'
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user