Fix init command

Init command was not working properly as it could not locate the
configuration sample file.
Steps taken:
- Move config-generator.tempest.conf to etc so it will be installed
with pbr.
- Update all files with new path to config-generator-tempest.conf as
needed.
- Refactor init command so if it detects we are not in a virtual
environment, try to find the global config directory /etc/tempest.
If that fails fallback to [sys.prefix]/etc/tempest.

Closes-Bug: #1491058
Closes-Bug: #1490670
Change-Id: I960bc711ff78ac2b0441ef63dff8ec4fb268fd3a
This commit is contained in:
David Paterson 2015-04-13 21:55:58 -04:00
parent c6cc6dba8a
commit 0bf52d497b
6 changed files with 36 additions and 14 deletions

View File

@ -168,7 +168,7 @@ configuration file is to generate a sample in the ``etc/`` directory ::
$> cd $TEMPEST_ROOT_DIR
$> oslo-config-generator --config-file \
tools/config/config-generator.tempest.conf \
etc/config-generator.tempest.conf \
--output-file etc/tempest.conf
After that, open up the ``etc/tempest.conf`` file and edit the

View File

@ -34,7 +34,7 @@ extensions = ['sphinx.ext.autodoc',
'oslo_config.sphinxconfiggen',
]
config_generator_config_file = '../../tools/config/config-generator.tempest.conf'
config_generator_config_file = '../../etc/config-generator.tempest.conf'
sample_config_basename = '_static/tempest'
todo_include_todos = True

View File

@ -52,17 +52,21 @@ def get_tempest_default_config_dir():
real_prefix = getattr(sys, 'real_prefix', None)
base_prefix = getattr(sys, 'base_prefix', None)
prefix = sys.prefix
if real_prefix is None and base_prefix is None:
# Not running in a virtual environnment of any kind
return '/etc/tempest'
elif (real_prefix is None and base_prefix is not None and
base_prefix == prefix):
# Probably not running in a virtual environment
if (real_prefix is None and
(base_prefix is None or base_prefix == prefix)):
# Probably not running in a virtual environment.
# NOTE(andreaf) we cannot distinguish this case from the case of
# a virtual environment created with virtualenv, and running python3.
return '/etc/tempest'
# Also if it appears we are not in virtual env and fail to find
# global config: '/etc/tempest', fall back to
# '[sys.prefix]/etc/tempest'
global_conf_dir = '/etc/tempest'
if os.path.isdir(global_conf_dir):
return global_conf_dir
else:
return os.path.join(prefix, 'etc/tempest')
else:
return os.path.join(sys.prefix, 'etc/tempest')
return os.path.join(prefix, 'etc/tempest')
class TempestInit(command.Command):
@ -99,9 +103,12 @@ class TempestInit(command.Command):
def copy_config(self, etc_dir, config_dir):
shutil.copytree(config_dir, etc_dir)
def generate_sample_config(self, local_dir):
def generate_sample_config(self, local_dir, config_dir):
conf_generator = os.path.join(config_dir,
'config-generator.tempest.conf')
subprocess.call(['oslo-config-generator', '--config-file',
'tools/config/config-generator.tempest.conf'],
conf_generator],
cwd=local_dir)
def create_working_dir(self, local_dir, config_dir):
@ -109,6 +116,10 @@ class TempestInit(command.Command):
if not os.path.isdir(local_dir):
LOG.debug('Creating local working dir: %s' % local_dir)
os.mkdir(local_dir)
else:
raise OSError("Directory you are trying to initialize already "
"exists: %s" % local_dir)
lock_dir = os.path.join(local_dir, 'tempest_lock')
etc_dir = os.path.join(local_dir, 'etc')
config_path = os.path.join(etc_dir, 'tempest.conf')
@ -125,7 +136,7 @@ class TempestInit(command.Command):
# Create and copy local etc dir
self.copy_config(etc_dir, config_dir)
# Generate the sample config file
self.generate_sample_config(local_dir)
self.generate_sample_config(local_dir, config_dir)
# Update local confs to reflect local paths
self.update_local_conf(config_path, lock_dir, log_dir)
# Generate a testr conf file

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
# import mock
import os
import fixtures
@ -39,9 +40,19 @@ class TestTempestInit(base.TestCase):
self.addCleanup(conf_file.close)
self.assertEqual(conf_file.read(), testr_conf_file)
def test_create_working_dir_with_existing_local_dir(self):
fake_local_dir = self.useFixture(fixtures.TempDir())
fake_local_conf_dir = self.useFixture(fixtures.TempDir())
_init = init.TempestInit(None, None)
self.assertRaises(OSError,
_init.create_working_dir,
fake_local_dir.path,
fake_local_conf_dir.path)
def test_create_working_dir(self):
fake_local_dir = self.useFixture(fixtures.TempDir())
fake_local_conf_dir = self.useFixture(fixtures.TempDir())
os.rmdir(fake_local_dir.path)
# Create a fake conf file
fake_file = fake_local_conf_dir.join('conf_file.conf')
open(fake_file, 'w').close()

View File

@ -24,7 +24,7 @@ commands =
bash tools/pretty_tox.sh '{posargs}'
[testenv:genconfig]
commands = oslo-config-generator --config-file tools/config/config-generator.tempest.conf
commands = oslo-config-generator --config-file etc/config-generator.tempest.conf
[testenv:cover]
setenv = OS_TEST_PATH=./tempest/tests