Skip to content

Commit

Permalink
change config name
Browse files Browse the repository at this point in the history
  • Loading branch information
hongbinbao committed Jun 27, 2014
1 parent 6fabb3e commit f0d20d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 98 deletions.
6 changes: 0 additions & 6 deletions device.config

This file was deleted.

16 changes: 0 additions & 16 deletions livereport.config

This file was deleted.

116 changes: 49 additions & 67 deletions reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-

# -*- coding:utf-8 -*-

import os
import sys
Expand All @@ -11,28 +10,22 @@
import nose
import atexit
import Queue
import signal
import string
import shutil
import zipfile
import logging
import datetime
import traceback
import subprocess
import threading
from tools import AdbCommand, logger, logdeco
from tools import AdbCommand, logger
from ConfigParser import ConfigParser
from commands import getoutput as shell
from os.path import join, exists, dirname
from client import ReportClient

log = logging.getLogger(__name__)
'''global log instance'''

LOCATION_NOT_FOUND_EXCEPTION = '%s not found.'
'''error msg if adb not found'''

TAG='%s%s%s' % ('-' * 18, 'live report plugin', '-' * 18)
TAG = '%s%s%s' % ('-' * 18, 'live report plugin', '-' * 18)
'''global log output tag'''

TIME_STAMP_FORMAT = '%Y-%m-%d %H:%M:%S'
Expand Down Expand Up @@ -67,18 +60,17 @@ def _uniqueID():
'''
return str(uuid.uuid1())


def _getServerConfiguration(config):
ret = {}
cf = ConfigParser()
cf.read(config)
ret.update({'username': cf.get('account', 'username'),\
'password': cf.get('account', 'password'),\
'auth': cf.get('server', 'auth'),\
'session_create': cf.get('server', 'session_create'),\
'session_update': cf.get('server', 'session_update'),\
'case_update': cf.get('server', 'case_update'),\
'file_upload': cf.get('server', 'file_upload')
ret.update({'username': cf.get('account', 'username'),
'password': cf.get('account', 'password'),
'auth': cf.get('server', 'auth'),
'session_create': cf.get('server', 'session_create'),
'session_update': cf.get('server', 'session_update'),
'case_update': cf.get('server', 'case_update'),
'file_upload': cf.get('server', 'file_upload')
})
return ret

Expand All @@ -90,7 +82,7 @@ def _getDeviceConfiguration(config):
'revision': cf.get('device', 'revision'),
'deviceid': cf.get('device', 'deviceid'),
'screen_width': cf.get('device', 'screen_width'),
'screen_height': cf.get('device', 'screen_height')
'screen_height': cf.get('device', 'screen_height')
})
return ret

Expand Down Expand Up @@ -140,19 +132,16 @@ def _zipFolder(folder_name, file_name, includeEmptyDIr=False):
create a zip file for folder
'''
empty_dirs = []
try:
ziper = zipfile.ZipFile(file_name, 'w', zipfile.ZIP_DEFLATED)
try:
ziper = zipfile.ZipFile(file_name, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(folder_name):
empty_dirs.extend([d for d in dirs if os.listdir(os.path.join(root, d)) == []])
empty_dirs.extend([d for d in dirs if os.listdir(os.path.join(root, d)) == []])
for name in files:
ziper.write(os.path.join(root ,name), name)
#fix same name error
#full zip with parent dir
#ziper.write(os.path.join(root ,name), os.path.join(os.path.splitext(filename)[0],name))
if includeEmptyDIr:
for d in empty_dirs:
zif = zipfile.ZipInfo(os.path.join(root, d) + "/")
ziper.writestr(zif, "")
ziper.write(os.path.join(root , name), name)
if includeEmptyDIr:
for d in empty_dirs:
zif = zipfile.ZipInfo(os.path.join(root, d) + os.sep)
ziper.writestr(zif, '')
empty_dirs = []
return True
except Exception, e:
Expand Down Expand Up @@ -369,13 +358,11 @@ def pass_log(self):
self.__log = join(self.pass_case_report_dir_path, 'log.zip')
return self.__log


@property
def fail_log(self):
self.__log = join(self.fail_case_report_dir_path, 'log.zip')
return self.__log


@property
def error_log(self):
self.__log = join(self.error_case_report_dir_path, 'log.zip')
Expand Down Expand Up @@ -421,10 +408,10 @@ def start(self):
cmd = ANDROID_LOG_SHELL % (exe, '-s', self.__serial)
else:
cmd = ANDROID_LOG_SHELL % (exe, '', '')
self.__logger_proc = subprocess.Popen(shlex.split(cmd),\
stderr=subprocess.STDOUT,\
stdout=subprocess.PIPE,\
close_fds=True,\
self.__logger_proc = subprocess.Popen(shlex.split(cmd),
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
close_fds=True,
preexec_fn=self.check)
self.__cache_thread = LogCacheWrapper(self.__logger_proc.stdout, self.__cache_queue)
self.__cache_thread.setDaemon(True)
Expand Down Expand Up @@ -465,14 +452,13 @@ def save(self, path):
# break
# continue
for i in range(self.__cache_queue.qsize()):
line = self.__cache_queue.get(block=True)
f.write(line)
line = self.__cache_queue.get(block=True)
f.write(line)
return True
except Exception, e:
logger.debug('error: save logcat\n%s' % str(e))
return False


def drop(self):
self.__cache_queue.queue.clear()

Expand All @@ -493,10 +479,10 @@ def start(self):
cmd = ANDROID_KMSGLOG_SHELL % (exe, '-s', self.__serial)
else:
cmd = ANDROID_KMSGLOG_SHELL % (exe, '', '')
self.__logger_proc = subprocess.Popen(shlex.split(cmd),\
stderr=subprocess.STDOUT,\
stdout=subprocess.PIPE,\
close_fds=True,\
self.__logger_proc = subprocess.Popen(shlex.split(cmd),
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
close_fds=True,
preexec_fn=self.check)
self.__cache_thread = LogCacheWrapper(self.__logger_proc.stdout, self.__cache_queue)
self.__cache_thread.setDaemon(True)
Expand Down Expand Up @@ -537,16 +523,15 @@ def save(self, path):
# break
# continue
for i in range(self.__cache_queue.qsize()):
line = self.__cache_queue.get(block=True)
f.write(line)
line = self.__cache_queue.get(block=True)
f.write(line)
return True
except Exception, e:
logger.debug('error: save dmesg\n%s' % str(e))
return False


def drop(self):
self.__cache_queue.queue.clear()
self.__cache_queue.queue.clear()

class LogCacheWrapper(threading.Thread):
def __init__(self, fd, queue):
Expand Down Expand Up @@ -596,30 +581,31 @@ def options(self, parser, env):
dest='directory', default=self.__getDefault(),
help="save output file to this directory. default is current nose worspace")

parser.add_option('--icycle', action='store', type='string',metavar="STRING",
parser.add_option('--icycle', action='store', type='string', metavar="STRING",
dest='icycle', default=None, help="total cycle flag")

###report server config###
parser.add_option('--livereport', action='store_true',
dest='livereport', default=False,
help="switcher of uploading result to live report server. default is enable the feature")

parser.add_option('--livereport-config', action='store', metavar="FILE",
dest='livereport_config', default='livereport.config',
parser.add_option('--server-config', action='store', metavar="FILE",
dest='livereport_config', default='server.config',
help="specify the live report server configuration file path")

parser.add_option('--device-config', action='store', metavar="FILE",
dest='device_config', default='device.config',
parser.add_option('--client-config', action='store', metavar="FILE",
dest='device_config', default='client.config',
help="specify the device config file path")

parser.add_option('--duration', dest='duration', type='string',metavar="STRING",
parser.add_option('--duration', dest='duration', type='string', metavar="STRING",
action='callback', callback=self.__validate_duration,
help='The minumum test duration before ending the test.\
Here format must follow next format: xxDxxHxxMxxS.\
e.g. --duration=2D09H30M12S, which means 2 days, 09 hours, 30 minutes and 12 seconds')

def __validate_duration(self, option, opt, value, parser):
'''
verify date time format
'''
value = string.lower(value)
begin = 0
Expand All @@ -638,8 +624,8 @@ def __validate_duration(self, option, opt, value, parser):
seconds = int(value[begin:i])
begin = i + 1
if begin == 0:
parser.error('%s: duration format error' % value)
times = datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
parser.error('%s: duration format error' % value)
times = datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
setattr(parser.values, option.dest, times)

def __getDefault(self):
Expand Down Expand Up @@ -680,8 +666,8 @@ def configure(self, options, conf):
self.result_properties = {'payload': None, 'extras': None}
#if disable report server
if self.opt.livereport and not self.__report_client:
server_need = {'username':None, 'password':None, 'auth':None, 'session_create':None,
'session_update':None, 'case_create':None, 'case_update':None, 'file_upload':None}
#server_need = {'username':None, 'password':None, 'auth':None, 'session_create':None,
# 'session_update':None, 'case_create':None, 'case_update':None, 'file_upload':None}
self.__report_client = ReportClient(**self.__configuration)
self.token = self.__report_client.regist()
if not self.token:
Expand Down Expand Up @@ -709,7 +695,6 @@ def describeTest(self, test):
module_name, class_name, method_name = test.id().split('.')[-3:]
return method_name


def __pingXDB(self):
output = AdbCommand('%s -s %s shell echo ping' % ('adb', self.__configuration['deviceid'])).run()
return output
Expand Down Expand Up @@ -739,9 +724,8 @@ def prepareTest(self, test):
if not self.__dmsglog_handler.available():
self.__dmsglog_handler.start()


def begin(self):
self.session_id = self.__counter.sid
self.session_id = self.__counter.sid
self.test_start_time = getattr(self, 'test_start_time', None)
if not self.test_start_time:
self.test_start_time = _reportTime()
Expand All @@ -751,12 +735,10 @@ def begin(self):
self._fail_report_path = _mkdir(join(self._report_path, 'fail'))
self._error_report_path = _mkdir(join(self._report_path, 'error'))
self._timeout_report_path = _mkdir(join(self._report_path, 'timeout'))
session_properties = {'sid': self.session_id,
'starttime': self.test_start_time
}
session_properties = {'sid': self.session_id, 'starttime': self.test_start_time}
self.cid = self.__counter.next_cid()
if self.write_hashes:
sys.stderr.write('begin cycle: %s \n' % (self.cid))
sys.stderr.write('begin cycle: %s \n' % (self.cid))
if self.opt.livereport and not self.__report_client.created:
self.__report_client.createSession(**session_properties)

Expand Down Expand Up @@ -807,7 +789,7 @@ def handleFailure(self, test, err):
dmesg_log_file = join(ctx.user_log_dir, DMESGLOG_FILE_NAME)
self.__dmsglog_handler.save(dmesg_log_file)
except Exception, e:
logger.debug('error: save dmsg log failure\n%s' % str(e))
logger.debug('error: save dmsg log failure\n%s' % str(e))

self.result_properties.update({'extras': {'screenshot_at_last': ctx.fail_screenshot_at_failure,
'log': ctx.fail_log,
Expand Down Expand Up @@ -980,12 +962,12 @@ def report(self, stream):
elif self.opt.icycle and self.__counter:
session_properties.update({'status': self.__counter.progress()})
if self.opt.livereport:
self.__report_client.updateSession(**session_properties)
self.__report_client.updateSession(**session_properties)
return None

def finalize(self, result):
if self.write_hashes:
self.__write('end cycle: %s \n' % (self.cid))
self.__write('end cycle: %s \n' % (self.cid))
session_properties = {'sid': self.session_id}
if self.opt.icycle and not self.__counter.alive() and self.opt.livereport:
session_properties.update({'endtime': _reportTime()})
Expand Down
11 changes: 2 additions & 9 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def showUsage():
print 'usage:'
print '\tpython runtests.py [-h|--help] [--cycle CYCLE] [--duration DURATION_TIME] [--timeout TIMEOUT_VALUE_SECONDS] [--livereport] [--livereport-config REPORT_CONFIG] [--device-config DEVICE_CONFIG] [,[argv]]\n\n'
print 'Process the paramters of runtests'

print 'optional arguments:'
print '\t-h, --help Show this help message and exit\n'
print '\t--cycle CYCLE Set the number(int) of cycle. Execute test with a specified number of cycle. Default is 1\n'
Expand All @@ -25,40 +24,34 @@ def showUsage():
print '\t\t\t\t\te.g. --duration=2D09H30M12S, which means 2 days, 09 hours, 30 minutes and 12 seconds\n'
print '\t--timeout SECONDS The timeout specified in seconds to limit the maximum period of test case method execution. Default is 180 seconds\n'
print '\t--livereport Enable the report server feature. Default is disable\n'
print '\t--livereport-config Specify the path of live report server configuration file. If not provide this option. The "server.config" file in current directory will be used as default\n'
print '\t--device-config Specify the path of device configuration file. If not provide this option. The "device.config" file in current directory will be used as default\n'
print '\t--server-config Specify the path of live report server configuration file. If not provide this option. The "server.config" file in current directory will be used as default\n'
print '\t--client-config Specify the path of device configuration file. If not provide this option. The "client.config" file in current directory will be used as default\n'
print '\t--verbosity Set the level(1~5) of verbosity to get the help string of every test and the result. Default is 2\n'
print '\targv Additional arguments accepted by nose\n'
exit(1)

DEFAULT_VERBOSITY = '2'
if __name__ == '__main__':
if '-h' in sys.argv or '--help' in sys.argv: showUsage()

cycle = None
arg_copy = sys.argv[:]
if len(arg_copy) >= 2:
if '--duration' not in arg_copy and '--cycle' not in arg_copy:
print '\nmiss --duration or --cycle!\n'
showUsage()

prog_name = arg_copy.pop(0)
arg_copy.insert(0, '')
arg_copy.insert(1, '--with-plan-loader')
arg_copy.insert(2, '--with-live-reporter')

if '--cycle' in arg_copy:
index = arg_copy.index('--cycle')
cycle = int(arg_copy[index+1])
arg_copy[index] = '--icycle'

if '--verbosity' not in arg_copy:
arg_copy.append('--verbosity')
arg_copy.append(DEFAULT_VERBOSITY)

else:
showUsage()

try:
planloader = PlanLoaderPlugin()
reporter = ReporterPlugin()
Expand Down

0 comments on commit f0d20d3

Please sign in to comment.