Port existing code to utils.ensure_tree
Now that we have ensure_tree in utils, port most users of os.makedirs() to use it. Change-Id: I3256cbb76bd889f99f1e6f3367bd620645f828a1
This commit is contained in:
parent
0d1e9ef251
commit
a73334b47a
|
@ -65,8 +65,7 @@ class CloudpipeController(object):
|
||||||
# NOTE(vish): One of the drawbacks of doing this in the api is
|
# 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 keys will only be on the api node that launched
|
||||||
# the cloudpipe.
|
# the cloudpipe.
|
||||||
if not os.path.exists(FLAGS.keys_path):
|
utils.ensure_tree(FLAGS.keys_path)
|
||||||
os.makedirs(FLAGS.keys_path)
|
|
||||||
|
|
||||||
def _get_all_cloudpipes(self, context):
|
def _get_all_cloudpipes(self, context):
|
||||||
"""Get all cloudpipes"""
|
"""Get all cloudpipes"""
|
||||||
|
|
|
@ -150,8 +150,7 @@ class CloudPipe(object):
|
||||||
key_name)
|
key_name)
|
||||||
private_key = result['private_key']
|
private_key = result['private_key']
|
||||||
key_dir = os.path.join(FLAGS.keys_path, context.user_id)
|
key_dir = os.path.join(FLAGS.keys_path, context.user_id)
|
||||||
if not os.path.exists(key_dir):
|
utils.ensure_tree(key_dir)
|
||||||
os.makedirs(key_dir)
|
|
||||||
key_path = os.path.join(key_dir, '%s.pem' % key_name)
|
key_path = os.path.join(key_dir, '%s.pem' % key_name)
|
||||||
with open(key_path, 'w') as f:
|
with open(key_path, 'w') as f:
|
||||||
f.write(private_key)
|
f.write(private_key)
|
||||||
|
|
|
@ -109,8 +109,7 @@ def ensure_ca_filesystem():
|
||||||
'genrootca.sh')
|
'genrootca.sh')
|
||||||
|
|
||||||
start = os.getcwd()
|
start = os.getcwd()
|
||||||
if not os.path.exists(ca_dir):
|
utils.ensure_tree(ca_dir)
|
||||||
os.makedirs(ca_dir)
|
|
||||||
os.chdir(ca_dir)
|
os.chdir(ca_dir)
|
||||||
utils.execute("sh", genrootca_sh_path)
|
utils.execute("sh", genrootca_sh_path)
|
||||||
os.chdir(start)
|
os.chdir(start)
|
||||||
|
@ -291,9 +290,7 @@ def _sign_csr(csr_text, ca_folder):
|
||||||
start = os.getcwd()
|
start = os.getcwd()
|
||||||
|
|
||||||
# Change working dir to CA
|
# Change working dir to CA
|
||||||
if not os.path.exists(ca_folder):
|
utils.ensure_tree(ca_folder)
|
||||||
os.makedirs(ca_folder)
|
|
||||||
|
|
||||||
os.chdir(ca_folder)
|
os.chdir(ca_folder)
|
||||||
utils.execute('openssl', 'ca', '-batch', '-out', outbound, '-config',
|
utils.execute('openssl', 'ca', '-batch', '-out', outbound, '-config',
|
||||||
'./openssl.cnf', '-infiles', inbound)
|
'./openssl.cnf', '-infiles', inbound)
|
||||||
|
|
|
@ -500,11 +500,6 @@ def write_to_file(file, data, mode='w'):
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
def ensure_path(path):
|
|
||||||
if not os.path.exists(path):
|
|
||||||
os.makedirs(path)
|
|
||||||
|
|
||||||
|
|
||||||
def metadata_forward():
|
def metadata_forward():
|
||||||
"""Create forwarding rule for metadata."""
|
"""Create forwarding rule for metadata."""
|
||||||
if FLAGS.metadata_host != '127.0.0.1':
|
if FLAGS.metadata_host != '127.0.0.1':
|
||||||
|
@ -947,7 +942,7 @@ def _device_exists(device):
|
||||||
|
|
||||||
def _dhcp_file(dev, kind):
|
def _dhcp_file(dev, kind):
|
||||||
"""Return path to a pid, leases or conf file for a bridge/device."""
|
"""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,
|
return os.path.abspath('%s/nova-%s.%s' % (FLAGS.networks_path,
|
||||||
dev,
|
dev,
|
||||||
kind))
|
kind))
|
||||||
|
@ -955,7 +950,7 @@ def _dhcp_file(dev, kind):
|
||||||
|
|
||||||
def _ra_file(dev, kind):
|
def _ra_file(dev, kind):
|
||||||
"""Return path to a pid or conf file for a bridge/device."""
|
"""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,
|
return os.path.abspath('%s/nova-ra-%s.%s' % (FLAGS.networks_path,
|
||||||
dev,
|
dev,
|
||||||
kind))
|
kind))
|
||||||
|
|
|
@ -93,8 +93,7 @@ class S3Application(wsgi.Router):
|
||||||
mapper.connect('/{bucket_name}/',
|
mapper.connect('/{bucket_name}/',
|
||||||
controller=lambda *a, **kw: BucketHandler(self)(*a, **kw))
|
controller=lambda *a, **kw: BucketHandler(self)(*a, **kw))
|
||||||
self.directory = os.path.abspath(root_directory)
|
self.directory = os.path.abspath(root_directory)
|
||||||
if not os.path.exists(self.directory):
|
utils.ensure_tree(self.directory)
|
||||||
os.makedirs(self.directory)
|
|
||||||
self.bucket_depth = bucket_depth
|
self.bucket_depth = bucket_depth
|
||||||
super(S3Application, self).__init__(mapper)
|
super(S3Application, self).__init__(mapper)
|
||||||
|
|
||||||
|
@ -286,7 +285,7 @@ class BucketHandler(BaseRequestHandler):
|
||||||
os.path.exists(path)):
|
os.path.exists(path)):
|
||||||
self.set_status(403)
|
self.set_status(403)
|
||||||
return
|
return
|
||||||
os.makedirs(path)
|
utils.ensure_tree(path)
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
def delete(self, bucket_name):
|
def delete(self, bucket_name):
|
||||||
|
@ -335,8 +334,7 @@ class ObjectHandler(BaseRequestHandler):
|
||||||
self.set_status(403)
|
self.set_status(403)
|
||||||
return
|
return
|
||||||
directory = os.path.dirname(path)
|
directory = os.path.dirname(path)
|
||||||
if not os.path.exists(directory):
|
utils.ensure_tree(directory)
|
||||||
os.makedirs(directory)
|
|
||||||
object_file = open(path, "w")
|
object_file = open(path, "w")
|
||||||
object_file.write(self.request.body)
|
object_file.write(self.request.body)
|
||||||
object_file.close()
|
object_file.close()
|
||||||
|
|
|
@ -236,18 +236,18 @@ class LinuxNetworkTestCase(test.TestCase):
|
||||||
self.flags(use_single_default_gateway=True)
|
self.flags(use_single_default_gateway=True)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(self.driver, 'write_to_file')
|
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.mox.StubOutWithMock(os, 'chmod')
|
||||||
|
|
||||||
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
|
os.chmod(mox.IgnoreArg(), 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.flags(use_single_default_gateway=True)
|
||||||
|
|
||||||
self.mox.StubOutWithMock(self.driver, 'write_to_file')
|
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.mox.StubOutWithMock(os, 'chmod')
|
||||||
|
|
||||||
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
self.driver.ensure_path(mox.IgnoreArg())
|
utils.ensure_tree(mox.IgnoreArg())
|
||||||
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
|
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
|
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,7 @@ class TgtAdm(TargetAdmin):
|
||||||
|
|
||||||
def create_iscsi_target(self, name, tid, lun, path, **kwargs):
|
def create_iscsi_target(self, name, tid, lun, path, **kwargs):
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(FLAGS.volumes_dir):
|
utils.ensure_tree(FLAGS.volumes_dir)
|
||||||
os.makedirs(FLAGS.volumes_dir)
|
|
||||||
|
|
||||||
# grab the volume id
|
# grab the volume id
|
||||||
vol_id = name.split(':')[1]
|
vol_id = name.split(':')[1]
|
||||||
|
|
Loading…
Reference in New Issue