From a0097bfe15bcbe71f87bd6e9f7fdc67110a6d378 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Sun, 15 Feb 2015 14:48:55 +0000 Subject: [PATCH] ganesha: fix execute call using invalid argument An execute call in the ganesha manager module that writes ganesha export config files is made with 'process_input' argument. This argument is invalid for processutils's ssh_execute() method which is used by the execute call to write config files to a remote ganesha server node. Fix this by not using the 'process_input' argument instead use other arguments that would still enable the execute call to write ganesha config files. Change-Id: I58369468ac7be1de38364a1c1bf6cbf8695b9a1d Closes-Bug: #1422235 --- etc/manila/rootwrap.d/share.filters | 2 +- manila/share/drivers/ganesha/manager.py | 6 ++++-- manila/tests/share/drivers/ganesha/test_manager.py | 10 ++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/etc/manila/rootwrap.d/share.filters b/etc/manila/rootwrap.d/share.filters index 2453eaf772..04ac6eb2a5 100644 --- a/etc/manila/rootwrap.d/share.filters +++ b/etc/manila/rootwrap.d/share.filters @@ -81,7 +81,7 @@ service: CommandFilter, service, root mktemp: CommandFilter, mktemp, root # manila/share/drivers/ganesha/manager.py: -shcat: RegExpFilter, sh, root, sh, -c, cat > /.* +shcat: RegExpFilter, sh, root, sh, -c, echo '((.|\n)*)' > /.* # manila/share/drivers/ganesha/manager.py: dbus-addexport: RegExpFilter, dbus-send, root, dbus-send, --print-reply, --system, --dest=org\.ganesha\.nfsd, /org/ganesha/nfsd/ExportMgr, org\.ganesha\.nfsd\.exportmgr\.(Add|Remove)Export, .*, .* diff --git a/manila/share/drivers/ganesha/manager.py b/manila/share/drivers/ganesha/manager.py index 53c59afe67..66aceea35e 100644 --- a/manila/share/drivers/ganesha/manager.py +++ b/manila/share/drivers/ganesha/manager.py @@ -226,8 +226,10 @@ class GaneshaManager(object): ("dir", "base")) tmpf = self.execute('mktemp', '-p', dirpath, "-t", fname + ".XXXXXX")[0][:-1] - self.execute('sh', '-c', 'cat > ' + pipes.quote(tmpf), - process_input=data, message='writing ' + tmpf) + self.execute( + 'sh', '-c', + 'echo %s > %s' % (pipes.quote(data), pipes.quote(tmpf)), + message='writing ' + tmpf) self.execute('mv', tmpf, path) def _write_conf_file(self, name, data): diff --git a/manila/tests/share/drivers/ganesha/test_manager.py b/manila/tests/share/drivers/ganesha/test_manager.py index 5651e2513b..ef5dc25e22 100644 --- a/manila/tests/share/drivers/ganesha/test_manager.py +++ b/manila/tests/share/drivers/ganesha/test_manager.py @@ -227,14 +227,14 @@ class GaneshaManagerTestCase(test.TestCase): def test_write_file(self): test_data = 'fakedata' self.mock_object(manager.pipes, 'quote', - mock.Mock(return_value='fakefile.conf.RANDOM')) + mock.Mock(side_effect=['fakedata', + 'fakefile.conf.RANDOM'])) test_args = [ ('mktemp', '-p', '/fakedir0/export.d', '-t', 'fakefile.conf.XXXXXX'), - ('sh', '-c', 'cat > fakefile.conf.RANDOM'), + ('sh', '-c', 'echo fakedata > fakefile.conf.RANDOM'), ('mv', 'fakefile.conf.RANDOM', test_path)] test_kwargs = { - 'process_input': test_data, 'message': 'writing fakefile.conf.RANDOM' } @@ -249,7 +249,9 @@ class GaneshaManagerTestCase(test.TestCase): mock.call(*test_args[0]), mock.call(*test_args[1], **test_kwargs), mock.call(*test_args[2])]) - manager.pipes.quote.assert_called_once_with('fakefile.conf.RANDOM') + manager.pipes.quote.assert_has_calls([ + mock.call('fakedata'), + mock.call('fakefile.conf.RANDOM')]) def test_write_conf_file(self): test_data = 'fakedata'