Remove touch command from volume.filters

Move touch to privsep and remove it from volume.filters.

Change-Id: I169b45f1176537448871cf23b6362c7ffbb16fff
Signed-off-by: Chuck Short <chucks@redhat.com>
This commit is contained in:
Chuck Short 2018-10-15 09:16:38 -04:00
parent 7b5d4d03fc
commit d02aebf2ab
4 changed files with 17 additions and 11 deletions

View File

@ -15,7 +15,7 @@
# under the License.
"""
Helpers for cgroup related routines.
Helpers for path related routines.
"""
import os
@ -37,3 +37,11 @@ def removefile(path):
if not os.path.exists(path):
raise exception.FileNotFound(file_path=path)
os.unlink(path)
@cinder.privsep.sys_admin_pctxt.entrypoint
def touch(path):
if os.path.exists(path):
os.utime(path, None)
else:
open(path, 'a').close()

View File

@ -875,8 +875,10 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
@mock.patch.object(image_utils, 'convert_image')
@mock.patch.object(image_utils, 'qemu_img_info')
@mock.patch('os.path.exists')
@mock.patch('cinder.privsep.path')
def test_copy_from_img_service_qcow2_copyoffload_workflow_success(
self, mock_exists, mock_qemu_img_info, mock_cvrt_image):
self, mock_touch, mock_exists, mock_qemu_img_info,
mock_cvrt_image):
drv = self.driver
cinder_mount_point_base = '/opt/stack/data/cinder/mnt/'
# To get the cinder mount point directory, we use:
@ -933,11 +935,10 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
'203.0.113.122', '/openstack/glance-flexvol1',
destination_copied_file, run_as_root=False,
check_exit_code=0
),
mock.call('touch', cinder_mount_point, run_as_root=False)
)
]
)
self.assertEqual(2, drv._execute.call_count)
self.assertEqual(1, drv._execute.call_count)
self.assertEqual(2, drv._delete_file_at_path.call_count)
self.assertEqual(1, drv._clone_file_dst_exists.call_count)

View File

@ -39,6 +39,7 @@ from six.moves import urllib
from cinder import exception
from cinder.i18n import _
from cinder.image import image_utils
import cinder.privsep.path
from cinder import utils
from cinder.volume import driver
from cinder.volume.drivers.netapp.dataontap.utils import loopingcalls
@ -671,11 +672,8 @@ class NetAppNfsDriver(driver.ManageableVD,
return False
def _touch_path_to_refresh(self, path):
try:
# Touching parent directory forces NFS client to flush its cache.
self._execute('touch', path, run_as_root=self._execute_as_root)
except processutils.ProcessExecutionError:
LOG.exception("Failed to touch path %s.", path)
# Touching parent directory forces NFS client to flush its cache.
cinder.privsep.path.touch(path)
def _discover_file_till_timeout(self, path, timeout=75):
"""Checks if file size at path is equal to size."""

View File

@ -114,7 +114,6 @@ rm: CommandFilter, rm, root
# cinder/volume/drivers/netapp/dataontap/nfs_base.py:
netapp_nfs_find: RegExpFilter, find, root, find, ^[/]*([^/\0]+(/+)?)*$, -maxdepth, \d+, -name, img-cache.*, -amin, \+\d+
netapp_nfs_touch: CommandFilter, touch, root
# cinder/volume/drivers/glusterfs.py
chgrp: CommandFilter, chgrp, root