From a76f5daad99de32bed3a5f901768c24fc869e2a5 Mon Sep 17 00:00:00 2001 From: XianChaobo Date: Thu, 9 Feb 2017 21:14:47 +0800 Subject: [PATCH] Always check cmd which does not exist In daemon mode, if run a cmd which does not exist, it will raise an Exception. But when we install the cmd later and run cmd, it still raise an Exception. The only work around right now is to restart the daemon, with this change, we can avoid restarting the daemon Closes-Bug: #1663216 Change-Id: I6f6ff540ed103f0fec329d6264bdac26493c8fad --- oslo_rootwrap/filters.py | 1 - oslo_rootwrap/tests/test_functional.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/oslo_rootwrap/filters.py b/oslo_rootwrap/filters.py index 1ae2cde..a996ea0 100644 --- a/oslo_rootwrap/filters.py +++ b/oslo_rootwrap/filters.py @@ -39,7 +39,6 @@ class CommandFilter(object): exec_dirs = exec_dirs or [] if self.real_exec is not None: return self.real_exec - self.real_exec = "" if os.path.isabs(self.exec_path): if os.access(self.exec_path, os.X_OK): self.real_exec = self.exec_path diff --git a/oslo_rootwrap/tests/test_functional.py b/oslo_rootwrap/tests/test_functional.py index 83825a5..074ef39 100644 --- a/oslo_rootwrap/tests/test_functional.py +++ b/oslo_rootwrap/tests/test_functional.py @@ -18,6 +18,7 @@ import io import logging import os import pwd +import shutil import signal import sys import threading @@ -44,6 +45,7 @@ class _FunctionalBase(object): super(_FunctionalBase, self).setUp() tmpdir = self.useFixture(fixtures.TempDir()).path self.config_file = os.path.join(tmpdir, 'rootwrap.conf') + self.later_cmd = os.path.join(tmpdir, 'later_install_cmd') filters_dir = os.path.join(tmpdir, 'filters.d') filters_file = os.path.join(tmpdir, 'filters.d', 'test.filters') os.mkdir(filters_dir) @@ -58,7 +60,8 @@ cat: CommandFilter, /bin/cat, root sh: CommandFilter, /bin/sh, root id: CommandFilter, /usr/bin/id, nobody unknown_cmd: CommandFilter, /unknown/unknown_cmd, root -""") +later_install_cmd: CommandFilter, %s, root +""" % self.later_cmd) def _test_run_once(self, expect_byte=True): code, out, err = self.execute(['echo', 'teststr']) @@ -192,6 +195,15 @@ class RootwrapDaemonTest(_FunctionalBase, testtools.TestCase): def test_run_with_stdin(self): self._test_run_with_stdin(expect_byte=False) + def test_run_with_later_install_cmd(self): + code, out, err = self.execute(['later_install_cmd']) + self.assertEqual(cmd.RC_NOEXECFOUND, code) + # Install cmd and try again + shutil.copy('/bin/echo', self.later_cmd) + code, out, err = self.execute(['later_install_cmd']) + # Expect successfully run the cmd + self.assertEqual(0, code) + def test_daemon_ressurection(self): # Let the client start a daemon self.execute(['cat'])