ganesha: cleanup of tmp config files
Currently in ganesha driver, while writing ganesha config files some times the tmp config files are not cleaned up. It is because moving the config file from tmp location to the correct ganesha config location sometimes goes wrong. This patch adds operation of cleaning up the tmp config files. Change-Id: Id93a5062c48e99afc26594f05cbf29cffce1499e Closes-Bug: #1717135
This commit is contained in:
parent
3e49465e80
commit
728632866a
@ -259,7 +259,12 @@ class GaneshaManager(object):
|
||||
'sh', '-c',
|
||||
'echo %s > %s' % (pipes.quote(data), pipes.quote(tmpf)),
|
||||
message='writing ' + tmpf)
|
||||
self.execute('mv', tmpf, path)
|
||||
try:
|
||||
self.execute('mv', tmpf, path)
|
||||
except exception.ProcessExecutionError:
|
||||
LOG.error('mv temp file ({0}) to {1} failed.'.format(tmpf, path))
|
||||
self.execute('rm', tmpf)
|
||||
raise
|
||||
|
||||
def _write_conf_file(self, name, data):
|
||||
"""Write data to config file for name atomically."""
|
||||
|
@ -265,6 +265,45 @@ class GaneshaManagerTestCase(test.TestCase):
|
||||
mock.call('fakedata'),
|
||||
mock.call('fakefile.conf.RANDOM')])
|
||||
|
||||
def test_write_file_with_mv_error(self):
|
||||
test_data = 'fakedata'
|
||||
self.mock_object(manager.pipes, 'quote',
|
||||
mock.Mock(side_effect=['fakedata',
|
||||
'fakefile.conf.RANDOM']))
|
||||
test_args = [
|
||||
('mktemp', '-p', '/fakedir0/export.d', '-t',
|
||||
'fakefile.conf.XXXXXX'),
|
||||
('sh', '-c', 'echo fakedata > fakefile.conf.RANDOM'),
|
||||
('mv', 'fakefile.conf.RANDOM', test_path),
|
||||
('rm', 'fakefile.conf.RANDOM')]
|
||||
test_kwargs = {
|
||||
'message': 'writing fakefile.conf.RANDOM'
|
||||
}
|
||||
|
||||
def mock_return(*args, **kwargs):
|
||||
if args == test_args[0]:
|
||||
return ('fakefile.conf.RANDOM\n', '')
|
||||
if args == test_args[2]:
|
||||
raise exception.ProcessExecutionError()
|
||||
|
||||
self.mock_object(self._manager, 'execute',
|
||||
mock.Mock(side_effect=mock_return))
|
||||
self.assertRaises(
|
||||
exception.ProcessExecutionError,
|
||||
self._manager._write_file,
|
||||
test_path,
|
||||
test_data
|
||||
)
|
||||
self._manager.execute.assert_has_calls([
|
||||
mock.call(*test_args[0]),
|
||||
mock.call(*test_args[1], **test_kwargs),
|
||||
mock.call(*test_args[2])],
|
||||
mock.call(*test_args[3])
|
||||
)
|
||||
manager.pipes.quote.assert_has_calls([
|
||||
mock.call('fakedata'),
|
||||
mock.call('fakefile.conf.RANDOM')])
|
||||
|
||||
def test_write_conf_file(self):
|
||||
test_data = 'fakedata'
|
||||
self.mock_object(self._manager, '_getpath',
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Added operation of cleaning up the temp config files when moving the config
|
||||
file from temp location to the correct ganesha config location goes wrong.
|
Loading…
x
Reference in New Issue
Block a user