Add helper methods to nova.paths

We only ever do one of two things with the global path options:

  1) Reference the option in the default of another option so that the
     value can be interpolated it

  2) Use the value of the option to build a path

Add helper methods for both these cases - e.g. basedir_def() for the
former case and basedir_rel() for the latter case. This makes it much
more obvious how and where these options are used.

Change-Id: I7fd94a329fe911761d02d94e5381e950c6668d56
This commit is contained in:
Mark McLoughlin
2013-01-04 17:36:29 +00:00
parent 6cb480ce33
commit 172b88d721
2 changed files with 35 additions and 7 deletions

View File

@@ -36,3 +36,33 @@ path_opts = [
CONF = cfg.CONF
CONF.register_opts(path_opts)
def basedir_def(*args):
"""Return an uninterpolated path relative to $pybasedir."""
return os.path.join('$pybasedir', *args)
def bindir_def(*args):
"""Return an uninterpolated path relative to $bindir."""
return os.path.join('$bindir', *args)
def state_path_def(*args):
"""Return an uninterpolated path relative to $state_path."""
return os.path.join('$state_path', *args)
def basedir_rel(*args):
"""Return a path relative to $pybasedir."""
return os.path.join(CONF.pybasedir, *args)
def bindir_rel(*args):
"""Return a path relative to $bindir."""
return os.path.join(CONF.bindir, *args)
def state_path_rel(*args):
"""Return a path relative to $state_path."""
return os.path.join(CONF.state_path, *args)

View File

@@ -42,6 +42,7 @@ from nova.network import manager as network_manager
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova import paths
from nova import service
from nova.tests import conf_fixture
from nova.tests import policy_fixture
@@ -57,7 +58,6 @@ CONF = cfg.CONF
CONF.register_opts(test_opts)
CONF.import_opt('sql_connection', 'nova.db.sqlalchemy.session')
CONF.import_opt('sqlite_db', 'nova.db.sqlalchemy.session')
CONF.import_opt('state_path', 'nova.paths')
CONF.set_override('use_stderr', False)
logging.setup('nova')
@@ -83,7 +83,7 @@ class Database(fixtures.Fixture):
if db_migrate.db_version() > db_migrate.INIT_VERSION:
return
else:
testdb = os.path.join(CONF.state_path, sqlite_db)
testdb = paths.state_path_rel(sqlite_db)
if os.path.exists(testdb):
return
db_migrate.db_sync()
@@ -93,7 +93,7 @@ class Database(fixtures.Fixture):
self._DB = "".join(line for line in conn.connection.iterdump())
self.engine.dispose()
else:
cleandb = os.path.join(CONF.state_path, sqlite_clean_db)
cleandb = paths.state_path_rel(sqlite_clean_db)
shutil.copyfile(testdb, cleandb)
def setUp(self):
@@ -104,10 +104,8 @@ class Database(fixtures.Fixture):
conn.connection.executescript(self._DB)
self.addCleanup(self.engine.dispose)
else:
shutil.copyfile(os.path.join(CONF.state_path,
self.sqlite_clean_db),
os.path.join(CONF.state_path,
self.sqlite_db))
shutil.copyfile(paths.state_path_rel(self.sqlite_clean_db),
paths.state_path_rel(self.sqlite_db))
def post_migrations(self):
"""Any addition steps that are needed outside of the migrations."""