
If we had this ahead of time, we could have avoided the errors that were encountered leading to the fix-account-mapping fix (see http://review.gluster.org/4222). This represents 100% coverage of the DiskFile module, but the coverage report says otherwise, unfortunately. That is because the put() method invokes eventlets during the test run, and coverage is not able to accurately track the coverage lines properly. If one comments out the "tpool.execute()" line in DiskFile.put() the coverage report then reports 100% for the DiskFile module. Additionally, we changed DiskFile.put() in four ways that should not change its behavior: 1. Comments were added to explain various code paths and mark potential issues / fixes 2. It no longer returns a boolean value, matching the behavior of swift.obj.server.DiskFile.put() 3. It no longer logs a message when it detects a directory that already exists, instead is raises an exception We believe this is okay because we cannot find a code path that would lead to his condition. As a result, it makes it easier to test all the code paths in that routine. 4. It no longer logs a message when create_dir_object() fails, since create_dir_object() raises an exception on failure only We also modified create_dir_object() to not return a boolean as a result of the above behavior. Note that by implementing these tests up to this point we found three code paths that would have failed if encountered due to missing imports. We also made changes to the DiskFile module to make it a bit easier to test, also eliminating an extra stat system call when deleting directory objects. Change-Id: I3286de83c1ec7c5e8d6cab9354e1c4397cee7497 BUG: 870589 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4284 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Mohammed Junaid <junaid@redhat.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
|
# The code below enables nosetests to work with i18n _() blocks
|
|
|
|
import __builtin__
|
|
import sys
|
|
import os
|
|
from ConfigParser import MissingSectionHeaderError
|
|
from StringIO import StringIO
|
|
|
|
from swift.common.utils import readconf
|
|
|
|
setattr(__builtin__, '_', lambda x: x)
|
|
|
|
|
|
# Work around what seems to be a Python bug.
|
|
# c.f. https://bugs.launchpad.net/swift/+bug/820185.
|
|
import logging
|
|
logging.raiseExceptions = False
|
|
|
|
|
|
def get_config(section_name=None, defaults=None):
|
|
"""
|
|
Attempt to get a test config dictionary.
|
|
|
|
:param section_name: the section to read (all sections if not defined)
|
|
:param defaults: an optional dictionary namespace of defaults
|
|
"""
|
|
config_file = os.environ.get('SWIFT_TEST_CONFIG_FILE',
|
|
'/etc/swift/test.conf')
|
|
config = {}
|
|
if defaults is not None:
|
|
config.update(defaults)
|
|
|
|
try:
|
|
config = readconf(config_file, section_name)
|
|
except SystemExit:
|
|
if not os.path.exists(config_file):
|
|
print >>sys.stderr, \
|
|
'Unable to read test config %s - file not found' \
|
|
% config_file
|
|
elif not os.access(config_file, os.R_OK):
|
|
print >>sys.stderr, \
|
|
'Unable to read test config %s - permission denied' \
|
|
% config_file
|
|
else:
|
|
print >>sys.stderr, \
|
|
'Unable to read test config %s - section %s not found' \
|
|
% (config_file, section_name)
|
|
return config
|