Print useful error on rootwrap daemon failure

If the rootwrap daemon fails to execute a command, it
generates a cryptic message:

Unserializable message: ('#ERROR', ValueError('I/O operation on closed file',))

We should at least log the command that we were trying
to run, which will help users figure out why it failed.

Change-Id: I2c94e5a226630432028351f8287868f4fe5d2fa1
Closes-bug: #1677742
This commit is contained in:
Brian Haley 2017-04-04 13:54:42 -04:00
parent 7c22311b61
commit 0476ad641d
2 changed files with 16 additions and 1 deletions

View File

@ -107,7 +107,11 @@ def execute_rootwrap_daemon(cmd, process_input, addl_env):
# just logging the execution error.
LOG.debug("Running command (rootwrap daemon): %s", cmd)
client = RootwrapDaemonHelper.get_client()
return client.execute(cmd, process_input)
try:
return client.execute(cmd, process_input)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Rootwrap error running command: %s"), cmd)
def execute(cmd, process_input=None, addl_env=None,

View File

@ -58,6 +58,17 @@ class AgentUtilsExecuteTest(base.BaseTestCase):
result = utils.execute(["ls", self.test_file], run_as_root=True)
self.assertEqual(result, expected)
@mock.patch.object(utils.RootwrapDaemonHelper, 'get_client')
def test_with_helper_exception(self, get_client):
client_inst = mock.Mock()
client_inst.execute.side_effect = RuntimeError
get_client.return_value = client_inst
self.config(group='AGENT', root_helper_daemon='echo')
with mock.patch.object(utils, 'LOG') as log:
self.assertRaises(RuntimeError, utils.execute,
['ls'], run_as_root=True)
self.assertTrue(log.error.called)
def test_stderr_true(self):
expected = "%s\n" % self.test_file
self.mock_popen.return_value = [expected, ""]