Browse Source

ENH: allow_no_files option for jail's convert to allow testing of stock jail.conf

pull/265/head
Yaroslav Halchenko 12 years ago
parent
commit
057f0ad135
  1. 13
      client/jailreader.py
  2. 13
      client/jailsreader.py
  3. 2
      testcases/clientreadertestcase.py

13
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":

13
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()])

2
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))

Loading…
Cancel
Save