Merge "Use os.path.join as possible"

This commit is contained in:
Zuul 2020-09-12 14:29:20 +00:00 committed by Gerrit Code Review
commit 4c1cb2ea9a
6 changed files with 16 additions and 13 deletions

View File

@ -44,11 +44,14 @@ def get_tempest_default_config_dir():
:return: default config dir :return: default config dir
""" """
# NOTE: The default directory should be on a Linux box.
global_conf_dir = '/etc/tempest' global_conf_dir = '/etc/tempest'
xdg_config = os.environ.get('XDG_CONFIG_HOME', xdg_config = os.environ.get('XDG_CONFIG_HOME',
os.path.expanduser('~/.config')) os.path.expanduser(os.path.join('~',
'.config')))
user_xdg_global_path = os.path.join(xdg_config, 'tempest') user_xdg_global_path = os.path.join(xdg_config, 'tempest')
user_global_path = os.path.join(os.path.expanduser('~'), '.tempest/etc') user_global_path = os.path.join(os.path.expanduser('~'),
'.tempest', 'etc')
if os.path.isdir(global_conf_dir): if os.path.isdir(global_conf_dir):
return global_conf_dir return global_conf_dir
elif os.path.isdir(user_xdg_global_path): elif os.path.isdir(user_xdg_global_path):
@ -121,7 +124,7 @@ class TempestInit(command.Command):
def generate_sample_config(self, local_dir): def generate_sample_config(self, local_dir):
conf_generator = os.path.join(os.path.dirname(__file__), conf_generator = os.path.join(os.path.dirname(__file__),
'config-generator.tempest.conf') 'config-generator.tempest.conf')
output_file = os.path.join(local_dir, 'etc/tempest.conf.sample') output_file = os.path.join(local_dir, 'etc', 'tempest.conf.sample')
if os.path.isfile(conf_generator): if os.path.isfile(conf_generator):
generator.main(['--config-file', conf_generator, '--output-file', generator.main(['--config-file', conf_generator, '--output-file',
output_file]) output_file])

View File

@ -31,10 +31,11 @@ try:
except ImportError: except ImportError:
launchpad = None launchpad = None
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache') LPCACHEDIR = os.path.expanduser(os.path.join('~', '.launchpadlib', 'cache'))
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')) BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..'))
TESTDIR = os.path.join(BASEDIR, 'tempest') TESTDIR = os.path.join(BASEDIR, 'tempest')

View File

@ -172,7 +172,7 @@ class PreProvisionedCredentialProvider(cred_provider.CredentialProvider):
return self.is_multi_user() return self.is_multi_user()
def _create_hash_file(self, hash_string): def _create_hash_file(self, hash_string):
path = os.path.join(os.path.join(self.accounts_dir, hash_string)) path = os.path.join(self.accounts_dir, hash_string)
if not os.path.isfile(path): if not os.path.isfile(path):
with open(path, 'w') as fd: with open(path, 'w') as fd:
fd.write(self.name) fd.write(self.name)
@ -194,8 +194,7 @@ class PreProvisionedCredentialProvider(cred_provider.CredentialProvider):
if res: if res:
return _hash return _hash
else: else:
path = os.path.join(os.path.join(self.accounts_dir, path = os.path.join(self.accounts_dir, _hash)
_hash))
with open(path, 'r') as fd: with open(path, 'r') as fd:
names.append(fd.read()) names.append(fd.read())
msg = ('Insufficient number of users provided. %s have allocated all ' msg = ('Insufficient number of users provided. %s have allocated all '

View File

@ -30,8 +30,8 @@ def load_tests(loader, tests, pattern):
base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0] base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
base_path = os.path.split(base_path)[0] base_path = os.path.split(base_path)[0]
# Load local tempest tests # Load local tempest tests
for test_dir in ['tempest/api', 'tempest/scenario']: for test_dir in ['api', 'scenario']:
full_test_dir = os.path.join(base_path, test_dir) full_test_dir = os.path.join(base_path, 'tempest', test_dir)
if not pattern: if not pattern:
suite.addTests(loader.discover(full_test_dir, suite.addTests(loader.discover(full_test_dir,
top_level_dir=base_path)) top_level_dir=base_path))

View File

@ -40,7 +40,7 @@ class TestTempestInit(base.TestCase):
def test_generate_sample_config(self): def test_generate_sample_config(self):
local_dir = self.useFixture(fixtures.TempDir()) local_dir = self.useFixture(fixtures.TempDir())
etc_dir_path = os.path.join(local_dir.path, 'etc/') etc_dir_path = os.path.join(local_dir.path, 'etc')
os.mkdir(etc_dir_path) os.mkdir(etc_dir_path)
init_cmd = init.TempestInit(None, None) init_cmd = init.TempestInit(None, None)
local_sample_conf_file = os.path.join(etc_dir_path, local_sample_conf_file = os.path.join(etc_dir_path,
@ -56,7 +56,7 @@ class TestTempestInit(base.TestCase):
def test_update_local_conf(self): def test_update_local_conf(self):
local_dir = self.useFixture(fixtures.TempDir()) local_dir = self.useFixture(fixtures.TempDir())
etc_dir_path = os.path.join(local_dir.path, 'etc/') etc_dir_path = os.path.join(local_dir.path, 'etc')
os.mkdir(etc_dir_path) os.mkdir(etc_dir_path)
lock_dir = os.path.join(local_dir.path, 'tempest_lock') lock_dir = os.path.join(local_dir.path, 'tempest_lock')
config_path = os.path.join(etc_dir_path, 'tempest.conf') config_path = os.path.join(etc_dir_path, 'tempest.conf')

View File

@ -579,7 +579,7 @@ class TestDiscovery(base.TestCase):
os, 'fakeservice') os, 'fakeservice')
def test_get_config_file(self): def test_get_config_file(self):
conf_dir = os.path.join(os.getcwd(), 'etc/') conf_dir = os.path.join(os.getcwd(), 'etc')
conf_file = "tempest.conf.sample" conf_file = "tempest.conf.sample"
local_sample_conf_file = os.path.join(conf_dir, conf_file) local_sample_conf_file = os.path.join(conf_dir, conf_file)