Merge "Use FHS-compliant default base directory"

This commit is contained in:
Jenkins 2014-05-09 11:24:56 +00:00 committed by Gerrit Code Review
commit c7544b56df
3 changed files with 65 additions and 2 deletions

View File

@ -22,8 +22,33 @@ import subprocess
import sys
import time
BASE_DIR = os.environ.get('OS_REFRESH_CONFIG_BASE_DIR',
'/opt/stack/os-config-refresh')
OLD_BASE_DIR = '/opt/stack/os-config-refresh'
DEFAULT_BASE_DIR = '/usr/libexec/os-refresh-config'
def default_base_dir():
"""Determine the default base directory path
If the OS_REFRESH_CONFIG_BASE_DIR environment variable is set,
use its value.
Otherwise, prefer the new default path, but still allow the old one for
backwards compatibility.
"""
base_dir = os.environ.get('OS_REFRESH_CONFIG_BASE_DIR')
if base_dir is None:
# NOTE(bnemec): Prefer the new location, but still allow the old one.
if os.path.isdir(OLD_BASE_DIR) and not os.path.isdir(DEFAULT_BASE_DIR):
logging.warning('Base directory %s is deprecated. The recommended '
'base directory is %s',
OLD_BASE_DIR, DEFAULT_BASE_DIR)
base_dir = OLD_BASE_DIR
else:
base_dir = DEFAULT_BASE_DIR
return base_dir
BASE_DIR = default_base_dir()
PHASES = ['pre-configure',
'configure',
'post-configure',

View File

@ -0,0 +1,37 @@
# Copyright 2014 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
import testtools
from os_refresh_config import os_refresh_config
class TestRefreshConfig(testtools.TestCase):
def test_default_base_dir(self):
default = '/usr/libexec/os-refresh-config'
with mock.patch('os.path.isdir', lambda x: x == default):
self.assertEqual(default, os_refresh_config.default_base_dir())
def test_default_base_dir_deprecated(self):
default = '/opt/stack/os-config-refresh'
with mock.patch('os.path.isdir', lambda x: x == default):
self.assertEqual(default, os_refresh_config.default_base_dir())
def test_default_base_dir_both(self):
default = '/usr/libexec/os-refresh-config'
deprecated = '/opt/stack/os-config-refresh'
with mock.patch('os.path.isdir', lambda x: (x == default or
x == deprecated)):
self.assertEqual(default, os_refresh_config.default_base_dir())

View File

@ -4,6 +4,7 @@ Babel>=1.3
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