diff --git a/nova/api/openstack/compute/contrib/cloudpipe.py b/nova/api/openstack/compute/contrib/cloudpipe.py index 9b2bb3e61332..42721c1a68ba 100644 --- a/nova/api/openstack/compute/contrib/cloudpipe.py +++ b/nova/api/openstack/compute/contrib/cloudpipe.py @@ -65,8 +65,7 @@ class CloudpipeController(object): # NOTE(vish): One of the drawbacks of doing this in the api is # the keys will only be on the api node that launched # the cloudpipe. - if not os.path.exists(FLAGS.keys_path): - os.makedirs(FLAGS.keys_path) + utils.ensure_tree(FLAGS.keys_path) def _get_all_cloudpipes(self, context): """Get all cloudpipes""" diff --git a/nova/cloudpipe/pipelib.py b/nova/cloudpipe/pipelib.py index 6a772eb635ab..4e498e2c91d2 100644 --- a/nova/cloudpipe/pipelib.py +++ b/nova/cloudpipe/pipelib.py @@ -150,8 +150,7 @@ class CloudPipe(object): key_name) private_key = result['private_key'] key_dir = os.path.join(FLAGS.keys_path, context.user_id) - if not os.path.exists(key_dir): - os.makedirs(key_dir) + utils.ensure_tree(key_dir) key_path = os.path.join(key_dir, '%s.pem' % key_name) with open(key_path, 'w') as f: f.write(private_key) diff --git a/nova/crypto.py b/nova/crypto.py index d1c9919e2e9c..11f04dea40d8 100644 --- a/nova/crypto.py +++ b/nova/crypto.py @@ -109,8 +109,7 @@ def ensure_ca_filesystem(): 'genrootca.sh') start = os.getcwd() - if not os.path.exists(ca_dir): - os.makedirs(ca_dir) + utils.ensure_tree(ca_dir) os.chdir(ca_dir) utils.execute("sh", genrootca_sh_path) os.chdir(start) @@ -291,9 +290,7 @@ def _sign_csr(csr_text, ca_folder): start = os.getcwd() # Change working dir to CA - if not os.path.exists(ca_folder): - os.makedirs(ca_folder) - + utils.ensure_tree(ca_folder) os.chdir(ca_folder) utils.execute('openssl', 'ca', '-batch', '-out', outbound, '-config', './openssl.cnf', '-infiles', inbound) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index b08eb0a62b65..40f75f2ffd92 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -500,11 +500,6 @@ def write_to_file(file, data, mode='w'): f.write(data) -def ensure_path(path): - if not os.path.exists(path): - os.makedirs(path) - - def metadata_forward(): """Create forwarding rule for metadata.""" if FLAGS.metadata_host != '127.0.0.1': @@ -947,7 +942,7 @@ def _device_exists(device): def _dhcp_file(dev, kind): """Return path to a pid, leases or conf file for a bridge/device.""" - ensure_path(FLAGS.networks_path) + utils.ensure_tree(FLAGS.networks_path) return os.path.abspath('%s/nova-%s.%s' % (FLAGS.networks_path, dev, kind)) @@ -955,7 +950,7 @@ def _dhcp_file(dev, kind): def _ra_file(dev, kind): """Return path to a pid or conf file for a bridge/device.""" - ensure_path(FLAGS.networks_path) + utils.ensure_tree(FLAGS.networks_path) return os.path.abspath('%s/nova-ra-%s.%s' % (FLAGS.networks_path, dev, kind)) diff --git a/nova/objectstore/s3server.py b/nova/objectstore/s3server.py index e2590a4af28c..b98a2024f0f3 100644 --- a/nova/objectstore/s3server.py +++ b/nova/objectstore/s3server.py @@ -93,8 +93,7 @@ class S3Application(wsgi.Router): mapper.connect('/{bucket_name}/', controller=lambda *a, **kw: BucketHandler(self)(*a, **kw)) self.directory = os.path.abspath(root_directory) - if not os.path.exists(self.directory): - os.makedirs(self.directory) + utils.ensure_tree(self.directory) self.bucket_depth = bucket_depth super(S3Application, self).__init__(mapper) @@ -286,7 +285,7 @@ class BucketHandler(BaseRequestHandler): os.path.exists(path)): self.set_status(403) return - os.makedirs(path) + utils.ensure_tree(path) self.finish() def delete(self, bucket_name): @@ -335,8 +334,7 @@ class ObjectHandler(BaseRequestHandler): self.set_status(403) return directory = os.path.dirname(path) - if not os.path.exists(directory): - os.makedirs(directory) + utils.ensure_tree(directory) object_file = open(path, "w") object_file.write(self.request.body) object_file.close() diff --git a/nova/tests/network/test_linux_net.py b/nova/tests/network/test_linux_net.py index 47b853a8a014..fd67083439a0 100644 --- a/nova/tests/network/test_linux_net.py +++ b/nova/tests/network/test_linux_net.py @@ -236,18 +236,18 @@ class LinuxNetworkTestCase(test.TestCase): self.flags(use_single_default_gateway=True) self.mox.StubOutWithMock(self.driver, 'write_to_file') - self.mox.StubOutWithMock(self.driver, 'ensure_path') + self.mox.StubOutWithMock(utils, 'ensure_tree') self.mox.StubOutWithMock(os, 'chmod') self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) os.chmod(mox.IgnoreArg(), mox.IgnoreArg()) os.chmod(mox.IgnoreArg(), mox.IgnoreArg()) @@ -259,18 +259,18 @@ class LinuxNetworkTestCase(test.TestCase): self.flags(use_single_default_gateway=True) self.mox.StubOutWithMock(self.driver, 'write_to_file') - self.mox.StubOutWithMock(self.driver, 'ensure_path') + self.mox.StubOutWithMock(utils, 'ensure_tree') self.mox.StubOutWithMock(os, 'chmod') self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) - self.driver.ensure_path(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) + utils.ensure_tree(mox.IgnoreArg()) os.chmod(mox.IgnoreArg(), mox.IgnoreArg()) os.chmod(mox.IgnoreArg(), mox.IgnoreArg()) diff --git a/nova/volume/iscsi.py b/nova/volume/iscsi.py index 69b14faf1b40..b08a8032b407 100644 --- a/nova/volume/iscsi.py +++ b/nova/volume/iscsi.py @@ -96,8 +96,7 @@ class TgtAdm(TargetAdmin): def create_iscsi_target(self, name, tid, lun, path, **kwargs): try: - if not os.path.exists(FLAGS.volumes_dir): - os.makedirs(FLAGS.volumes_dir) + utils.ensure_tree(FLAGS.volumes_dir) # grab the volume id vol_id = name.split(':')[1]