From 057f0ad1357273f027b944e046d66e486c2f197f Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 21 Jun 2013 12:44:37 -0400 Subject: [PATCH] ENH: allow_no_files option for jail's convert to allow testing of stock jail.conf --- client/jailreader.py | 13 +++++++++++-- client/jailsreader.py | 13 +++++++++++-- testcases/clientreadertestcase.py | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client/jailreader.py b/client/jailreader.py index ef444125..1a2be432 100644 --- a/client/jailreader.py +++ b/client/jailreader.py @@ -103,7 +103,16 @@ class JailReader(ConfigReader): logSys.warn("No actions were defined for %s" % self.__name) return True - def convert(self): + def convert(self, allow_no_files=False): + """Convert read before __opts to the commands stream + + Parameters + ---------- + allow_missing : bool + Either to allow log files to be missing entirely. Primarily is + used for testing + """ + stream = [] for opt in self.__opts: if opt == "logpath": @@ -115,7 +124,7 @@ class JailReader(ConfigReader): for p in pathList: found_files += 1 stream.append(["set", self.__name, "addlogpath", p]) - if not found_files: + if not (found_files or allow_no_files): raise ValueError( "Have not found any log file for %s jail" % self.__name) elif opt == "backend": diff --git a/client/jailsreader.py b/client/jailsreader.py index 098b525d..408a40bf 100644 --- a/client/jailsreader.py +++ b/client/jailsreader.py @@ -79,14 +79,23 @@ class JailsReader(ConfigReader): return False return True - def convert(self): + def convert(self, allow_no_files=False): + """Convert read before __opts and jails to the commands stream + + Parameters + ---------- + allow_missing : bool + Either to allow log files to be missing entirely. Primarily is + used for testing + """ + stream = list() for opt in self.__opts: if opt == "": stream.append([]) # Convert jails for jail in self.__jails: - stream.extend(jail.convert()) + stream.extend(jail.convert(allow_no_files=allow_no_files)) # Start jails for jail in self.__jails: stream.append(["start", jail.getName()]) diff --git a/testcases/clientreadertestcase.py b/testcases/clientreadertestcase.py index a8c60bf8..948431b3 100644 --- a/testcases/clientreadertestcase.py +++ b/testcases/clientreadertestcase.py @@ -132,7 +132,7 @@ class JailsReaderTest(unittest.TestCase): jails = JailsReader(basedir='config', force_enable=True) # we are running tests from root project dir atm self.assertTrue(jails.read()) # opens fine self.assertTrue(jails.getOptions()) # reads fine - comm_commands = jails.convert() + comm_commands = jails.convert(allow_no_files=True) # by default we have lots of jails ;) self.assertTrue(len(comm_commands))