From bdef1c77ab84aed6b10f459895da7ea753166416 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 21 Jun 2016 18:06:49 -0400 Subject: [PATCH] Move oslo config generator config inside package This commit moves the oslo config generator config file from living as a data file, which makes it very difficult to rely on, to just living in the package. By including it in the package we have a guaranteed relative path we can rely on for building utilities on it, like the tempest init command. Change-Id: I5b9deae733f42fe3ed39418103304f71b43dccb3 Partially-implements: bp tempest-run-cmd --- doc/source/conf.py | 2 +- .../cmd}/config-generator.tempest.conf | 0 tempest/cmd/init.py | 20 +++++++++---------- tempest/tests/cmd/test_tempest_init.py | 6 +----- tox.ini | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) rename {etc => tempest/cmd}/config-generator.tempest.conf (100%) diff --git a/doc/source/conf.py b/doc/source/conf.py index c2df0b649c..eef3620a35 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -34,7 +34,7 @@ extensions = ['sphinx.ext.autodoc', 'oslo_config.sphinxconfiggen', ] -config_generator_config_file = '../../etc/config-generator.tempest.conf' +config_generator_config_file = '../../tempest/cmd/config-generator.tempest.conf' sample_config_basename = '_static/tempest' todo_include_todos = True diff --git a/etc/config-generator.tempest.conf b/tempest/cmd/config-generator.tempest.conf similarity index 100% rename from etc/config-generator.tempest.conf rename to tempest/cmd/config-generator.tempest.conf diff --git a/tempest/cmd/init.py b/tempest/cmd/init.py index 77d62d34da..ddd5542552 100644 --- a/tempest/cmd/init.py +++ b/tempest/cmd/init.py @@ -18,6 +18,7 @@ import subprocess import sys from cliff import command +from oslo_config import generator from oslo_log import log as logging from six import moves @@ -125,17 +126,16 @@ class TempestInit(command.Command): else: LOG.warning("Global config dir %s can't be found" % config_dir) - def generate_sample_config(self, local_dir, config_dir): - if os.path.isdir(config_dir): - conf_generator = os.path.join(config_dir, - 'config-generator.tempest.conf') - - subprocess.call(['oslo-config-generator', '--config-file', - conf_generator], - cwd=local_dir) + def generate_sample_config(self, local_dir): + conf_generator = os.path.join(os.path.dirname(__file__), + 'config-generator.tempest.conf') + output_file = os.path.join(local_dir, 'etc/tempest.conf.sample') + if os.path.isfile(conf_generator): + generator.main(['--config-file', conf_generator, '--output-file', + output_file]) else: LOG.warning("Skipping sample config generation because global " - "config dir %s can't be found" % config_dir) + "config file %s can't be found" % conf_generator) def create_working_dir(self, local_dir, config_dir): # Create local dir if missing @@ -162,7 +162,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, config_dir) + self.generate_sample_config(local_dir) # Update local confs to reflect local paths self.update_local_conf(config_path, lock_dir, log_dir) # Generate a testr conf file diff --git a/tempest/tests/cmd/test_tempest_init.py b/tempest/tests/cmd/test_tempest_init.py index 685a0b3e18..031bf4d41a 100644 --- a/tempest/tests/cmd/test_tempest_init.py +++ b/tempest/tests/cmd/test_tempest_init.py @@ -13,7 +13,6 @@ # under the License. import os -import shutil import fixtures @@ -43,15 +42,12 @@ class TestTempestInit(base.TestCase): local_dir = self.useFixture(fixtures.TempDir()) etc_dir_path = os.path.join(local_dir.path, 'etc/') os.mkdir(etc_dir_path) - tmp_dir = self.useFixture(fixtures.TempDir()) - config_dir = os.path.join(tmp_dir.path, 'config/') - shutil.copytree('etc/', config_dir) init_cmd = init.TempestInit(None, None) local_sample_conf_file = os.path.join(etc_dir_path, 'tempest.conf.sample') # Verify no sample config file exist self.assertFalse(os.path.isfile(local_sample_conf_file)) - init_cmd.generate_sample_config(local_dir.path, config_dir) + init_cmd.generate_sample_config(local_dir.path) # Verify sample config file exist with some content self.assertTrue(os.path.isfile(local_sample_conf_file)) diff --git a/tox.ini b/tox.ini index 44162fdfea..cff222d569 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ commands = bash tools/pretty_tox.sh '{posargs}' [testenv:genconfig] -commands = oslo-config-generator --config-file etc/config-generator.tempest.conf +commands = oslo-config-generator --config-file tempest/cmd/config-generator.tempest.conf [testenv:cover] setenv = OS_TEST_PATH=./tempest/tests