# License for the specific language governing permissions and limitations
# under the License.
+import errno
import fcntl
import glob
import grp
def ensure_dir(dir_path):
"""Ensure a directory with 755 permissions mode."""
if not os.path.isdir(dir_path):
- os.makedirs(dir_path, 0o755)
+ try:
+ os.makedirs(dir_path, 0o755)
+ except OSError as e:
+ # Make sure that the error was that the directory was created
+ # by a different (concurrent) worker. If not, raise the error.
+ if e.errno != errno.EEXIST:
+ raise
def _get_conf_base(cfg_root, uuid, ensure_conf_dir):
# under the License.
from distutils import spawn
-import errno
import functools
import os
def start(self):
fmt = self.process_name + "--%Y-%m-%d--%H%M%S.log"
log_dir = os.path.join(DEFAULT_LOG_DIR, self.test_name)
- if not os.path.exists(log_dir):
- try:
- os.makedirs(log_dir)
- except OSError as e:
- # Make sure that the error was that the directory was created
- # by a different (concurrent) worker. If not, raise the error.
- if e.errno != errno.EEXIST:
- raise
+ utils.ensure_dir(log_dir)
cmd = [spawn.find_executable(self.exec_name),
'--log-dir', log_dir,
# License for the specific language governing permissions and limitations
# under the License.
+import errno
import mock
import socket
import testtools
getegid.assert_called_once_with()
getgrgid.assert_called_once_with(self.EGID)
+ @mock.patch('os.makedirs')
+ @mock.patch('os.path.exists', return_value=False)
+ def test_ensure_dir_no_fail_if_exists(self, path_exists, makedirs):
+ error = OSError()
+ error.errno = errno.EEXIST
+ makedirs.side_effect = error
+ utils.ensure_dir("/etc/create/concurrently")
+
class TestUnixDomainHttpConnection(base.BaseTestCase):
def test_connect(self):