Browse Source

Fixed inconsistency in logging-related code; fixed size of unit test partitions to equal 50M each

master
frisco 13 years ago
parent
commit
7032d06020
  1. 2
      src/cryptobox/core/blockdevice.py
  2. 10
      src/cryptobox/core/settings.py
  3. 1
      src/cryptobox/tests/base.py
  4. 2
      src/cryptobox/tests/test.cryptobox.py
  5. 4
      src/cryptobox/tests/tools.py

2
src/cryptobox/core/blockdevice.py

@ -41,7 +41,7 @@ OPTIONAL_PROGS = { "lvm": True }
change default values from "True" to "False" to disable the respective program
"""
LOGGER = logging.getLogger("CryptoBox")
LOGGER = logging.getLogger("CryptoNAS")
DEFAULT_SYSBLOCK_DIR = '/sys/block'
DEFAULT_DEVNODE_DIR = '/dev'

10
src/cryptobox/core/settings.py

@ -60,7 +60,7 @@ class CryptoBoxSettings:
def __init__(self, config_file=None):
self.__is_initialized = False
self.log = logging.getLogger("CryptoBox")
self.log = logging.getLogger("CryptoNAS")
config_file = self.__get_config_filename(config_file)
self.log.info("loading config file: %s" % config_file)
self.prefs = self.__get_preferences(config_file)
@ -542,16 +542,16 @@ class CryptoBoxSettings:
"invalid log details for 'syslog': only %s are allowed" % \
str(log_facil_avail))
## retrive the log priority from the syslog module
log_handler = LocalSysLogHandler("CryptoBox",
log_handler = LocalSysLogHandler("CryptoNAS",
getattr(syslog, 'LOG_%s' % log_facility))
log_handler.setFormatter(
logging.Formatter('%(asctime)s CryptoBox %(levelname)s: %(message)s'))
logging.Formatter('%(asctime)s CryptoNAS %(levelname)s: %(message)s'))
else:
## this should never happen - we just have it in case someone forgets
## to update the spec, the 'log_dest_avail' or the above branches
raise CBConfigInvalidValueError("Log", "Destination", log_destination,
"invalid log destination: only %s are allowed" % str(log_dest_avail))
cbox_log = logging.getLogger("CryptoBox")
cbox_log = logging.getLogger("CryptoNAS")
## remove previous handlers (from 'basicConfig')
cbox_log.handlers = []
## add new one
@ -560,7 +560,7 @@ class CryptoBoxSettings:
cbox_log.propagate = False
## 'log_level' is a string -> use 'getattr'
cbox_log.setLevel(getattr(logging, log_level))
## the logger named "CryptoBox" is configured now
## the logger named "CryptoNAS" is configured now
# We can't use real default values for the "directory_exists" tests below.

1
src/cryptobox/tests/base.py

@ -76,7 +76,6 @@ class CommonTestClass(unittest.TestCase):
testtools.umount("%s%d" % (self.blockdevice, num))
## format device and partition block device if necessary
testtools.prepare_partition(self.blockdevice)
self.blockdevice = testtools.find_test_device(self.DRIVE_TO_CLOBBER)
self.device = self.blockdevice + "1"
self.blockdevice_html = self.blockdevice.replace("/", "%2F")
## the assumption is not always valid - but usually it is ok

2
src/cryptobox/tests/test.cryptobox.py

@ -45,7 +45,7 @@ class CryptoBoxDeviceTests(CommonTestClass):
'''is_device_allowed should accept permitted devices'''
# check if one of the common devices exists and is allowed
blockdevice_found = False
for dev_node in (COMMON_ALLOWED_DEVICES + [ self.blockdevice ]):
for dev_node in (COMMON_ALLOWED_DEVICES):
if os.path.exists(dev_node):
self.assertTrue(self.cb.is_device_allowed(dev_node))
blockdevice_found = True

4
src/cryptobox/tests/tools.py

@ -94,8 +94,8 @@ def prepare_partition(blockdevice):
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
args = [ '/sbin/sfdisk', blockdevice ])
# create two partitions (20MB fat, 20MB ext)
proc.stdin.write(",10,0xC\n,10,L\n")
# create two partitions (50MB fat, 50MB ext)
proc.stdin.write(",50,0xC\n,50,L\n")
(output, error) = proc.communicate()
if proc.returncode != 0:
raise Exception, "could not partition the device (%s): %s" \

Loading…
Cancel
Save