Allow empty directories for tempest init

tempest init directory parameter is optional. If not
given it uses the cwd as default. Unfortunately this
leads to an error since the existing of the directory
is checked and an error is raised.

Change-Id: I8c6a66df458ae08b29cd921dfa65ef68c76c7a7c
Closes-Bug: #1512994
This commit is contained in:
Marc Koderer 2015-11-04 10:35:48 +01:00
parent d289567c27
commit 090b5dcfb7
2 changed files with 5 additions and 3 deletions

View File

@ -116,9 +116,9 @@ 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:
elif not os.listdir(local_dir) == []:
raise OSError("Directory you are trying to initialize already "
"exists: %s" % local_dir)
"exists and is not empty: %s" % local_dir)
lock_dir = os.path.join(local_dir, 'tempest_lock')
etc_dir = os.path.join(local_dir, 'etc')

View File

@ -58,9 +58,11 @@ class TestTempestInit(base.TestCase):
self.assertTrue(os.path.isfile(local_sample_conf_file))
self.assertGreater(os.path.getsize(local_sample_conf_file), 0)
def test_create_working_dir_with_existing_local_dir(self):
def test_create_working_dir_with_existing_local_dir_non_empty(self):
fake_local_dir = self.useFixture(fixtures.TempDir())
fake_local_conf_dir = self.useFixture(fixtures.TempDir())
open("%s/foo" % fake_local_dir.path, 'w').close()
_init = init.TempestInit(None, None)
self.assertRaises(OSError,
_init.create_working_dir,