Merge "General cleanup of opencafe"

This commit is contained in:
Jenkins
2013-04-09 14:51:39 +00:00
committed by Gerrit Code Review
11 changed files with 62 additions and 48 deletions

View File

@@ -24,7 +24,7 @@ class SecDataGeneratorString(BaseDataGenerator):
@type filename: string
@return: None
@note: ints are stored in twos compliment so negative numbers return
positive numbers with unexpected results (-1,0) reutrns 255
positive numbers with unexpected results (-1,0) returns 255
'''
#Tests to ensure inputs are correct
try:

View File

@@ -31,7 +31,7 @@ def get_object_namespace(obj):
they originate from.
So that logging doesn't cause exceptions, if the namespace cannot be
extracted from the object's mro atribute, the actual name returned is set
extracted from the object's mro attribute, the actual name returned is set
to a probably-unique string, the id() of the object passed,
and is then further improved by a series of functions until
one of them fails.

View File

@@ -127,13 +127,13 @@ class PBStatisticsLog(object):
if not os.path.exists(log_dir):
os.makedirs(log_dir)
self.File = os.path.normpath(os.path.join(log_dir, fileName))
if startClean == True and os.path.exists(self.File) == True:
if startClean is True and os.path.exists(self.File) == True:
''' Force the file to be overwritten before any writing '''
os.remove(self.File)
else:
self.File = None
if(os.path.exists(self.File) == False):
if os.path.exists(self.File) is False:
''' Write out the header to the stats log '''
self.__write("Elapsed Time,Start Time,Stop Time,Result,Errors,Warnings")

View File

@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
def tags(*tags, **attrs):
def _decorator(func):
setattr(func, '__test_tags__', [])

View File

@@ -30,6 +30,7 @@ from cafe.common.reporting.metrics import PBStatisticsLog
engine_config = EngineConfig()
class BaseTestFixture(unittest.TestCase):
'''
@summary: Foundation for TestRepo Test Fixture.
@@ -59,11 +60,11 @@ class BaseTestFixture(unittest.TestCase):
'''
@summary: Returns a one-line description of the test
'''
if(self._testMethodDoc != None):
if(self._testMethodDoc.startswith("\n") == True):
self._testMethodDoc = " ".join(self._testMethodDoc.
splitlines()).strip()
return (unittest.TestCase.shortDescription(self))
if self._testMethodDoc is not None:
if self._testMethodDoc.startswith("\n") is True:
self._testMethodDoc = " ".join(
self._testMethodDoc.splitlines()).strip()
return unittest.TestCase.shortDescription(self)
@classmethod
def setUpClass(cls):
@@ -146,7 +147,7 @@ class BaseTestFixture(unittest.TestCase):
self.fixture_log.info("Test Case.: {0}".format(self._testMethodName))
self.fixture_log.info("Created.At: {0}".format(self.test_metrics.timer.
start_time))
if (self.shortDescription()):
if self.shortDescription():
self.fixture_log.info("{0}".format(self.shortDescription()))
self.fixture_log.info("{0}".format('=' * 56))
@@ -167,7 +168,7 @@ class BaseTestFixture(unittest.TestCase):
This is related to the todo in L{TestRunMetrics}
'''
# Build metrics
if(self._resultForDoCleanups.wasSuccessful()):
if self._resultForDoCleanups.wasSuccessful():
self.fixture_metrics.total_passed += 1
self.test_metrics.result = TestResultTypes.PASSED
else:
@@ -232,5 +233,5 @@ class BaseBurnInTestFixture(BaseTestFixture):
super(BaseBurnInTestFixture, self).setUp()
def tearDown(self):
# Let the base handle whatever goodoo it needs
# Let the base handle whatever hoodoo it needs
super(BaseBurnInTestFixture, self).tearDown()

View File

@@ -20,7 +20,8 @@ import xml.etree.ElementTree as ET
class ParseResult(object):
def __init__(self, result_dict, master_testsuite, xml_path, execution_time):
def __init__(self, result_dict, master_testsuite,
xml_path, execution_time):
for keys, values in result_dict.items():
setattr(self, keys, values)
self.master_testsuite = master_testsuite
@@ -46,7 +47,8 @@ class ParseResult(object):
if errored_test[0].__class__.__name__ != '_ErrorHolder':
errored_tests.append(errored_test[0])
else:
setup_errored_classes.append(str(errored_test[0]).split(".")[-1].rstrip(')'))
setup_errored_classes.append(
str(errored_test[0]).split(".")[-1].rstrip(')'))
if len(setup_errored_classes) != 0:
for item_1 in all_tests:
for item_2 in setup_errored_classes:
@@ -71,7 +73,7 @@ class ParseResult(object):
def get_errored_tests(self):
errored_obj_list = []
for item in self.errors:
if (item[0].__class__.__name__ is not '_ErrorHolder'):
if item[0].__class__.__name__ is not '_ErrorHolder':
errored_obj = Result(item[0].__class__.__name__, vars(item[0]).get('_testMethodName'), error_trace=item[1])
else:
errored_obj = Result(str(item[0]).split(" ")[0], str(item[0]).split(".")[-1].rstrip(')'), error_trace=item[1])
@@ -88,7 +90,10 @@ class ParseResult(object):
def summary_result(self):
summary_res = {}
summary_res = {'tests': str(self.testsRun), 'errors': str(len(self.errors)), 'failures': str(len(self.failures)), 'skipped': str(len(self.skipped))}
summary_res = {'tests': str(self.testsRun),
'errors': str(len(self.errors)),
'failures': str(len(self.failures)),
'skipped': str(len(self.skipped))}
return summary_res
def generate_xml_report(self):

View File

@@ -50,6 +50,7 @@ RED = '\033[0;31m'
HIGHLIGHTED_RED = '\033[1;41m'
END = '\033[1;m'
class _WritelnDecorator:
"""Used to decorate file-like objects with a handy 'writeln' method"""
@@ -60,7 +61,8 @@ class _WritelnDecorator:
return getattr(self.stream,attr)
def writeln(self, arg=None):
if arg: self.write(arg)
if arg:
self.write(arg)
self.write('\n')
@@ -72,7 +74,7 @@ class CCParallelTextTestRunner(unittest.TextTestRunner):
self.verbosity = verbosity
def run(self, test):
"Run the given test case or test suite."
"""Run the given test case or test suite."""
result = self._makeResult()
startTime = time.time()
test(result)
@@ -344,7 +346,7 @@ class CCRunner(object):
def set_env(self, config_path, log_path, data_dir):
'''
sets an environment var so the tests can find thier respective
sets an environment var so the tests can find their respective
product config path
'''
os.environ['CCTNG_CONFIG_FILE'] = "{0}{1}configs{1}engine.config".format(BASE_DIR, DIR_SEPR)
@@ -367,7 +369,7 @@ class CCRunner(object):
@return: The safely formatted datetime string
@rtype: C{str}
'''
return(str(datetime.now()).replace(' ', '_').replace(':', '_'))
return str(datetime.now()).replace(' ', '_').replace(':', '_')
def get_repo_path(self, product):
'''
@@ -406,8 +408,8 @@ class CCRunner(object):
'''
try:
position = len(path.split(split_token)) - 1
temp_path = "{0}{1}".format(split_token, path.
split(split_token)[position])
temp_path = "{0}{1}".format(split_token,
path.split(split_token)[position])
split_path = temp_path.split(DIR_SEPR)
dotted_path = '.'.join(split_path)
@@ -529,7 +531,7 @@ class CCRunner(object):
for _, obj in inspect.getmembers(loaded_module, inspect.isclass):
temp_obj = obj
try:
while(temp_obj.__base__ != object):
while temp_obj.__base__ != object:
if temp_obj.__base__ == unittest.TestCase \
or temp_obj.__base__ == BaseTestFixture \
and temp_obj != obj.__base__:
@@ -643,7 +645,6 @@ class CCRunner(object):
module_path = os.path.dirname(loaded_module.__file__)
module_name = loaded_module.__name__.split('.')[1]
# base_dotted_path = self.get_dotted_path(module_path, test_repo.__path__[0])
base_dotted_path = self.get_dotted_path(module_path, test_repo.__name__)
if cl_tags is not None:
@@ -704,7 +705,7 @@ class CCRunner(object):
test_class_name,
method_name])
suite.addTest(loader.loadTestsFromName(
dotted_path))
dotted_path))
except ImportError:
raise
except AttributeError:
@@ -738,7 +739,7 @@ class CCRunner(object):
cl_args = self.get_cl_args()
module_regex = None
if(os.path.exists(BASE_DIR) == False):
if os.path.exists(BASE_DIR) is False:
err_msg = self.error_msg("{0} does not exist - Exiting".
format(BASE_DIR))
print self.colorize(err_msg, HIGHLIGHTED_RED)
@@ -770,8 +771,8 @@ class CCRunner(object):
if os.path.exists(repo_path) is False:
err_msg = self.error_msg('Repo', ' '.join([cl_args.product,
repo_path,
'does not exist - Exiting']))
repo_path,
'does not exist - Exiting']))
print self.colorize(err_msg, HIGHLIGHTED_RED)
exit(1)
@@ -910,7 +911,6 @@ class CCRunner(object):
self.print_traceback()
continue
if cl_args.parallel:
unittest.installHandler()
threads = []

View File

@@ -30,20 +30,25 @@ class BasePersistentLinuxClient(object):
def format_disk_device(self, device, fstype):
'''Formats entire device, does not create partitions'''
return self.ssh_client.exec_command("mkfs.%s %s\n" % (str(fstype).lower(), str(device)))
return self.ssh_client.exec_command(
"mkfs.%s %s\n" % (str(fstype).lower(), str(device)))
def mount_disk_device(self, device, mountpoint, fstype, create_mountpoint=True):
'''
Mounts a disk at a specified mountpoint. performs 'touch mountpoint' before executing
Mounts a disk at a specified mountpoint.
Performs 'touch mountpoint' before executing
'''
self.ssh_client.exec_command("mkdir %s" % str(mountpoint))
return self.ssh_client.exec_command("mount -t %s %s %s\n" % (str(fstype).lower(), str(device), str(mountpoint)))
return self.ssh_client.exec_command(
"mount -t %s %s %s\n" % (str(fstype).lower(),
str(device), str(mountpoint)))
def unmount_disk_device(self, mountpoint):
'''
Forces unmounts (umount -f) a disk at a specified mountpoint.
Forces unmounts (umount -f) a disk at a specified mountpoint.
'''
return self.ssh_client.exec_command("umount -f %s\n" % (str(mountpoint)))
return self.ssh_client.exec_command(
"umount -f %s\n" % (str(mountpoint)))
def write_random_data_to_disk(self, dir_path, filename, blocksize=1024,
count=1024):
@@ -62,7 +67,8 @@ class BasePersistentLinuxClient(object):
"dd if=/dev/urandom of=%s bs=%s count=%s\n" %
(str(dd_of), str(blocksize), str(count)))
def write_zeroes_data_to_disk(self, disk_mountpoint, filename, blocksize=1024, count=1024):
def write_zeroes_data_to_disk(self, disk_mountpoint, filename,
blocksize=1024, count=1024):
'''By default writes one mebibyte (2^20 bytes)'''
of = '%s/%s' % (disk_mountpoint, str(filename))

View File

@@ -31,7 +31,7 @@ class FreeBSDClient(LinuxClient):
uptime_string = self.ssh_client.exec_command('uptime')
uptime = uptime_string.replace('\n', '').split(',')[0].split()[2]
uptime_unit = uptime_string.replace('\n', '').split(',')[0].split()[3]
if (uptime_unit == 'mins'):
if uptime_unit == 'mins':
uptime_unit_format = 'M'
else:
uptime_unit_format = 'S'

View File

@@ -90,7 +90,7 @@ def _log_transaction(log, level=cclogging.logging.DEBUG):
log.exception(exception)
logline = ''.join([
'\n{0}\nRESPONSE RECIEVED\n{0}\n'.format('-' * 17),
'\n{0}\nRESPONSE RECEIVED\n{0}\n'.format('-' * 17),
'response status..: {0}\n'.format(response),
'response time....: {0}\n'.format(elapsed),
'response headers.: {0}\n'.format(response.headers),
@@ -142,7 +142,7 @@ class BaseRestClient(BaseClient):
@_inject_exception(_exception_handlers)
@_log_transaction(log=_log)
def request(self, method, url, **kwargs):
""" Performs <method> HTTP request to <url> using the requests lib"""
""" Performs <method> HTTP request to <url> using the requests lib"""
return requests.request(method, url, **kwargs)
def put(self, url, **kwargs):
@@ -197,13 +197,13 @@ class BaseRestClient(BaseClient):
class RestClient(BaseRestClient):
"""
@summary: Allows clients to inherit all requests-defined RESTfull
@summary: Allows clients to inherit all requests-defined RESTful
verbs. Redefines request() so that keyword args are passed
through a named dictionary instead of kwargs.
Client methods can then take paramaters that may overload
request paramaters, which allows client method calls to
override parts of the request with paramters sent directly
to requests, overiding the client method logic either in
Client methods can then take parameters that may overload
request parameters, which allows client method calls to
override parts of the request with parameters sent directly
to requests, overriding the client method logic either in
part or whole on the fly.
@see: http://docs.python-requests.org/en/latest/api/#configurations
@@ -244,8 +244,8 @@ class RestClient(BaseRestClient):
if requestslib_kwargs[key] is None:
del requestslib_kwargs[key]
#Create the final paramaters for the call to the base request()
#Wherever a paramater is provided both by the calling method AND
#Create the final parameters for the call to the base request()
#Wherever a parameter is provided both by the calling method AND
#the requests_lib kwargs dictionary, requestslib_kwargs "wins"
requestslib_kwargs = dict({'headers': headers,
'params': params,
@@ -275,7 +275,7 @@ class AutoMarshallingRestClient(RestClient):
requestslib_kwargs = requestslib_kwargs if (requestslib_kwargs is not
None) else {}
#set the 'data' paramater of the request to either what's already in
#set the 'data' parameter of the request to either what's already in
#requestslib_kwargs, or the deserialized output of the request_entity
if request_entity is not None:
requestslib_kwargs = dict(

View File

@@ -69,7 +69,7 @@ class EngineConfig(object):
print ("Unexpected exception while attempting to access '{0}' "
"environment variable.".format(_ENGINE_CONFIG_FILE_ENV_VAR))
raise exception
return(engine_config_file_path)
return engine_config_file_path
def get(self, item_name, default=None):
@@ -81,7 +81,8 @@ class EngineConfig(object):
return default
def get_raw(self, item_name, default=None):
'''Performs a get() on SafeConfigParser object without interpolation
'''
Performs a get() on SafeConfigParser object without interpolation
'''
try: