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
diff --git a/tempest/cmd/init.py b/tempest/cmd/init.py
index af8f270..a4ed064 100644
--- a/tempest/cmd/init.py
+++ b/tempest/cmd/init.py
@@ -116,9 +116,9 @@
         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')
diff --git a/tempest/tests/cmd/test_tempest_init.py b/tempest/tests/cmd/test_tempest_init.py
index 1d60c67..1048a52 100644
--- a/tempest/tests/cmd/test_tempest_init.py
+++ b/tempest/tests/cmd/test_tempest_init.py
@@ -58,9 +58,11 @@
         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,