This commit is contained in:
Timur Torubarov 2016-06-14 16:53:58 +03:00
parent 1d6b611e80
commit ba4522f7d5

View File

@ -34,37 +34,36 @@ class Plugin(AbstractPlugin):
def configure(self): def configure(self):
self.device_id = self.get_option("device_id", None).strip() self.device_id = self.get_option("device_id", None).strip()
if not self.device_id: if self.device_id:
modify = ''
else:
modify = '-s {device_id}'.format(device_id=self.device_id) modify = '-s {device_id}'.format(device_id=self.device_id)
for key, value in self.cmds.iteritems(): for key, value in self.cmds.iteritems():
self.cmds[key] = value % modify self.cmds[key] = value % modify
self.logfile = self.core.mkstemp(".log", "battery_historian_")
self.logfile = self.core.mkstemp(".log", "battery_historian_") self.core.add_artifact_file(self.logfile)
self.core.add_artifact_file(self.logfile)
def prepare_test(self): def prepare_test(self):
try: if self.device_id:
out = subprocess.check_output(self.cmds['enable_full_log'], shell=True) try:
logger.debug('Enabling full-log: %s', out) out = subprocess.check_output(self.cmds['enable_full_log'], shell=True)
out = subprocess.check_output(self.cmds['reset'], shell=True) logger.debug('Enabling full-log: %s', out)
logger.debug('Reseting battery stats: %s', out) out = subprocess.check_output(self.cmds['reset'], shell=True)
except CalledProcessError: logger.debug('Reseting battery stats: %s', out)
logger.error('Error trying to prepare battery historian plugin', exc_info=True) except CalledProcessError:
logger.error('Error trying to prepare battery historian plugin', exc_info=True)
def end_test(self, retcode): def end_test(self, retcode):
try: if self.device_id:
logger.debug('dumping battery stats') try:
dump = subprocess.Popen(self.cmds['dump'], stdout=subprocess.PIPE, shell=True).communicate()[0] logger.debug('dumping battery stats')
out = subprocess.check_output(self.cmds['disable_full_log'], shell=True) dump = subprocess.Popen(self.cmds['dump'], stdout=subprocess.PIPE, shell=True).communicate()[0]
logger.debug('Disabling fulllog: %s', out) out = subprocess.check_output(self.cmds['disable_full_log'], shell=True)
out = subprocess.check_output(self.cmds['reset'], shell=True) logger.debug('Disabling fulllog: %s', out)
logger.debug('Battery stats reset: %s', out) out = subprocess.check_output(self.cmds['reset'], shell=True)
except CalledProcessError: logger.debug('Battery stats reset: %s', out)
logger.error('Error trying to collect battery historian plugin data', exc_info=True) except CalledProcessError:
with open(self.logfile, 'w') as f: logger.error('Error trying to collect battery historian plugin data', exc_info=True)
f.write(dump) with open(self.logfile, 'w') as f:
f.write(dump)
return retcode return retcode
def is_test_finished(self): def is_test_finished(self):