Merge "Port existing code to utils.ensure_tree"

This commit is contained in:
Jenkins 2012-08-28 16:22:22 +00:00 committed by Gerrit Code Review
commit 7ed7a46dc3
7 changed files with 26 additions and 39 deletions

View File

@ -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"""

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -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()

View File

@ -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())

View File

@ -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]