예제 #1
0
 def active(self, **session_properties):
     """
     used to regist test session on report server
     @type session_properties: dict
     @param session_properties: the dictionary of session properties
     @rtype: boolean
     @return: True if active success, else return False    
     """
     self._session_id = str(uuid1())
     self._session_info = {
         "subc": "create",
         "data": {
             "planname": "test.plan",
             "starttime": reporttime(),
             "deviceinfo": {
                 "product": session_properties["product"],
                 "revision": session_properties["revision"],
                 "deviceid": session_properties["deviceid"],
             },
         },
     }
     print "\r\t"
     print "test session properties:"
     print self._session_info
     print "\nregisting on stability server..."
     self._token = Authentication.getToken(session_properties["username"], session_properties["password"])
     self._is_regist = Authentication.regist(self._session_id, self._token, self._session_info)
     print "success\nsession id: %s \ntoken: %s\n\n" % (self._session_id, self._token)
     return self._is_regist
예제 #2
0
 def active(self, **session_properties):
     '''
     used to regist test session on report server
     @type session_properties: dict
     @param session_properties: the dictionary of session properties
     @rtype: boolean
     @return: True if active success, else return False    
     '''
     self._session_id = str(uuid1())
     self._session_info = {'subc':'create', \
                           'data':{'planname':'test.plan', \
                                   'starttime':reporttime(), \
                                   'deviceinfo':{'product':session_properties['product'], \
                                                 'revision':session_properties['revision'], \
                                                 'deviceid':session_properties['deviceid'] \
                                                }
                                  }
                           }
     print '\r\t'
     print 'test session properties:'
     print self._session_info
     print '\nregisting on stability server...'
     self._token = Authentication.getToken(session_properties['username'],
                                           session_properties['password'])
     self._is_regist = Authentication.regist(self._session_id, self._token,
                                             self._session_info)
     print 'success\nsession id: %s \ntoken: %s\n\n' % (self._session_id,
                                                        self._token)
     return self._is_regist
예제 #3
0
 def run(self):
     """
     thread work method.
     """
     try:
         logger.debug(">>>enter run...")
         logger.debug("uploading thread %s" % threading.current_thread().name)
         assert exists(self._path)
         xmlfile = join(self._path, "result.xml")
         url = get_url_from_file("session_update") % self._session_id
         values = {"token": self._token, "endtime": reporttime()}
         files = {"file": open(xmlfile, "rb")}
         logger.debug("begin to upload whole result file")
         ret = request(method="post", url=url, files=files, data=values, timeout=60)
         logger.debug("end to upload whole result file")
         if (not ret) or (not ret["result"] == "ok") or (not "failures" in ret["data"]):  # error
             logger.debug("server no return failures list")
             return
         if not ret["data"]["failures"]:
             logger.debug("server return failures is none")
             return
         failures = [
             {failure["tid"]: join(join(self._path, "output"), failure["caseid"])}
             for failure in ret["data"]["failures"]
         ]
         file_upload_url = get_url_from_file("file_upload")
         for f in failures:
             tid, path = f.popitem()
             _file_upload_url = file_upload_url % (self._session_id, str(tid))
             if not exists(path):
                 return
             # mock igas output
             # import shutil
             # os.mkdir(path)
             # shutil.copyfile('/home/test/Desktop/x_failure_a.png', join(path,'x_failure_a.png'))
             # shutil.copyfile('/home/test/Desktop/b_ori_dd.png', join(path,'b_ori_dd.png'))
             # shutil.copyfile('/home/test/Desktop/log.zip', join(path,'log.zip'))
             snapshots_list = [
                 s for s in glob.glob(join(path, "*.png")) if s.find("fail") != -1 or s.find("ori") != -1
             ]
             expect_snapshot = [join(path, e) for e in snapshots_list if e.find("ori") != -1]
             current_snapshot = [join(path, c) for c in snapshots_list if c.find("fail") != -1]
             logger.debug("expect snapshot:")
             logger.debug(str(expect_snapshot))
             logger.debug("current snapshot:")
             logger.debug(str(current_snapshot))
             for c in current_snapshot:
                 ###img = thumbnail(c)
                 ###files = {'file': img}
                 files = {"file": open(c, "rb")}
                 # dirs, name =  split(c)
                 headers = {"Content-Type": "image/png", "Ext-Type": "%s%s%s" % ("current", ":", "step")}
                 ret = request(method="put", url=_file_upload_url, headers=headers, data=files["file"])
                 logger.debug("uploading expected snapshots done")
             for s in expect_snapshot:
                 ###img = thumbnail(s)
                 ###files = {'file': img}
                 # orig
                 files = {"file": open(s, "rb")}
                 # dirs, name =  split(s)
                 headers = {"Content-Type": "image/png", "Ext-Type": "%s%s%s" % ("expect", ":", "step")}
                 ret = request(method="put", url=_file_upload_url, headers=headers, data=files["file"])
                 logger.debug("uploading current snapshots done")
             log = join(path, "log.zip")
             if not exists(log):
                 return
             files = {"file": open(log, "rb")}
             headers = {"Content-Type": "application/zip"}
             ret = request(method="put", url=_file_upload_url, headers=headers, data=files["file"])
             logger.debug("uploading log file done")
     except Exception, e:
         logger.debug(str(e))
         self.stop()
예제 #4
0
 def run(self):
     '''
     thread work method.
     '''
     try:
         logger.debug('>>>enter run...')
         logger.debug('uploading thread %s' %
                      threading.current_thread().name)
         assert exists(self._path)
         xmlfile = join(self._path, 'result.xml')
         url = get_url_from_file('session_update') % self._session_id
         values = {'token': self._token, 'endtime': reporttime()}
         files = {'file': open(xmlfile, 'rb')}
         logger.debug('begin to upload whole result file')
         ret = request(method='post',
                       url=url,
                       files=files,
                       data=values,
                       timeout=60)
         logger.debug('end to upload whole result file')
         if (not ret) or (not ret['result'] == 'ok') or (
                 not 'failures' in ret['data']):  #error
             logger.debug('server no return failures list')
             return
         if not ret['data']['failures']:
             logger.debug('server return failures is none')
             return
         failures = [{
             failure['tid']:
             join(join(self._path, 'output'), failure['caseid'])
         } for failure in ret['data']['failures']]
         file_upload_url = get_url_from_file('file_upload')
         for f in failures:
             tid, path = f.popitem()
             _file_upload_url = file_upload_url % (self._session_id,
                                                   str(tid))
             if not exists(path): return
             #mock igas output
             #import shutil
             #os.mkdir(path)
             #shutil.copyfile('/home/test/Desktop/x_failure_a.png', join(path,'x_failure_a.png'))
             #shutil.copyfile('/home/test/Desktop/b_ori_dd.png', join(path,'b_ori_dd.png'))
             #shutil.copyfile('/home/test/Desktop/log.zip', join(path,'log.zip'))
             snapshots_list = [
                 s for s in glob.glob(join(path, '*.png'))
                 if s.find('fail') != -1 or s.find('ori') != -1
             ]
             expect_snapshot = [
                 join(path, e) for e in snapshots_list
                 if e.find('ori') != -1
             ]
             current_snapshot = [
                 join(path, c) for c in snapshots_list
                 if c.find('fail') != -1
             ]
             logger.debug('expect snapshot:')
             logger.debug(str(expect_snapshot))
             logger.debug('current snapshot:')
             logger.debug(str(current_snapshot))
             for c in current_snapshot:
                 ###img = thumbnail(c)
                 ###files = {'file': img}
                 files = {'file': open(c, 'rb')}
                 #dirs, name =  split(c)
                 headers = {
                     'Content-Type': 'image/png',
                     'Ext-Type': '%s%s%s' % ('current', ':', 'step')
                 }
                 ret = request(method='put',
                               url=_file_upload_url,
                               headers=headers,
                               data=files['file'])
                 logger.debug('uploading expected snapshots done')
             for s in expect_snapshot:
                 ###img = thumbnail(s)
                 ###files = {'file': img}
                 #orig
                 files = {'file': open(s, 'rb')}
                 #dirs, name =  split(s)
                 headers = {
                     'Content-Type': 'image/png',
                     'Ext-Type': '%s%s%s' % ('expect', ':', 'step')
                 }
                 ret = request(method='put',
                               url=_file_upload_url,
                               headers=headers,
                               data=files['file'])
                 logger.debug('uploading current snapshots done')
             log = join(path, 'log.zip')
             if not exists(log): return
             files = {'file': open(log, 'rb')}
             headers = {'Content-Type': 'application/zip'}
             ret = request(method='put',
                           url=_file_upload_url,
                           headers=headers,
                           data=files['file'])
             logger.debug('uploading log file done')
     except Exception, e:
         logger.debug(str(e))
         self.stop()