From dc48d3d14978ebb9afe6d1371b2af988107b7f5d Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 15 May 2013 17:24:13 -0400 Subject: Remove path_exists from NFS/GlusterFS drivers mkdir -p will not throw an error if the path already exists, so this method is unneeded in these classes. Change-Id: I65a67cb75f83f65a6f80c7a90f77c2c5133bd41b --- nova/tests/virt/libvirt/test_libvirt_volume.py | 4 ++-- nova/virt/libvirt/volume.py | 22 ++-------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/nova/tests/virt/libvirt/test_libvirt_volume.py b/nova/tests/virt/libvirt/test_libvirt_volume.py index 86773dd10..59e7d7fea 100644 --- a/nova/tests/virt/libvirt/test_libvirt_volume.py +++ b/nova/tests/virt/libvirt/test_libvirt_volume.py @@ -444,7 +444,7 @@ class LibvirtVolumeTestCase(test.TestCase): libvirt_driver.disconnect_volume(connection_info, "vde") expected_commands = [ - ('stat', export_mnt_base), + ('mkdir', '-p', export_mnt_base), ('mount', '-t', 'nfs', export_string, export_mnt_base)] self.assertEqual(self.executes, expected_commands) @@ -500,7 +500,7 @@ class LibvirtVolumeTestCase(test.TestCase): libvirt_driver.disconnect_volume(connection_info, "vde") expected_commands = [ - ('stat', export_mnt_base), + ('mkdir', '-p', export_mnt_base), ('mount', '-t', 'glusterfs', export_string, export_mnt_base)] self.assertEqual(self.executes, expected_commands) diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py index ef8818743..10eb979dc 100644 --- a/nova/virt/libvirt/volume.py +++ b/nova/virt/libvirt/volume.py @@ -491,8 +491,7 @@ class LibvirtNFSVolumeDriver(LibvirtBaseVolumeDriver): def _mount_nfs(self, mount_path, nfs_share, ensure=False): """Mount nfs export to mount path.""" - if not self._path_exists(mount_path): - utils.execute('mkdir', '-p', mount_path) + utils.execute('mkdir', '-p', mount_path) # Construct the NFS mount command. nfs_cmd = ['mount', '-t', 'nfs'] @@ -513,14 +512,6 @@ class LibvirtNFSVolumeDriver(LibvirtBaseVolumeDriver): """returns string that represents hash of base_str (in hex format).""" return hashlib.md5(base_str).hexdigest() - @staticmethod - def _path_exists(path): - """Check path.""" - try: - return utils.execute('stat', path, run_as_root=True) - except processutils.ProcessExecutionError: - return False - class LibvirtAOEVolumeDriver(LibvirtBaseVolumeDriver): """Driver to attach AoE volumes to libvirt.""" @@ -616,8 +607,7 @@ class LibvirtGlusterfsVolumeDriver(LibvirtBaseVolumeDriver): def _mount_glusterfs(self, mount_path, glusterfs_share, ensure=False): """Mount glusterfs export to mount path.""" - if not self._path_exists(mount_path): - utils.execute('mkdir', '-p', mount_path) + utils.execute('mkdir', '-p', mount_path) try: utils.execute('mount', '-t', 'glusterfs', glusterfs_share, @@ -634,14 +624,6 @@ class LibvirtGlusterfsVolumeDriver(LibvirtBaseVolumeDriver): """returns string that represents hash of base_str (in hex format).""" return hashlib.md5(base_str).hexdigest() - @staticmethod - def _path_exists(path): - """Check path.""" - try: - return utils.execute('stat', path, run_as_root=True) - except processutils.ProcessExecutionError: - return False - class LibvirtFibreChannelVolumeDriver(LibvirtBaseVolumeDriver): """Driver to attach Fibre Channel Network volumes to libvirt.""" -- cgit