Exemple #1
0
    def connect_to_peer(self, peer_id):
        if self.agent_is_banned(peer_id):
            g_logger.info("Agent %s is banned." % peer_id)

        if peer_id == theApp.peer_info.ID:
            g_logger.error("Can't connect to self.")
        if peer_id not in self.sessions:
            peer_entry = None
            if peer_id in self.super_peers:
                peer_entry = self.super_peers[peer_id]
            elif peer_id in self.normal_peers:
                peer_entry = self.normal_peers[peer_id]
            elif peer_id in self.mobile_peers:
                peer_entry = self.mobile_peers[peer_id]
            else:
                g_logger.error(
                    "Peer id '%s' doesn't exist in all peer lists." % peer_id)
                return

            if self.network_is_banned(peer_entry.IP):
                g_logger.info("Agent %s is banned in network grounds (%s)." % \
                                 (peer_id, peer_entry.IP))
                return

            reactor.connectTCP(peer_entry.IP, peer_entry.Port, theApp.factory)
            g_logger.debug("Connecting to %s:%d..." %
                           (peer_entry.IP, peer_entry.Port))
Exemple #2
0
def update_test_mod(result, *args, **kw):
    g_logger.info("Updating Test Module...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'test_' + version + '.py'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Test mod %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error(
                "Test mod %s is corrupt. Try to download it again." % filename)
            return

    # Rename the original test.py to test.py.bak,
    # and replace test.py with new one
    origin = os.path.join(ROOT_DIR, 'umit', 'icm', 'agent', 'test.py')
    shutil.copy(origin, origin + '.bak')
    shutil.copy(path, origin)
    if 'umit.icm.agent.test' in sys.modules:
        reload(sys.modules['umit.icm.agent.test'])
    g_logger.info("Test Module updated.")
    def _handle_response(self, response):
        """Result Handler (generate report)"""
        time_end = default_timer()
        self.status_code = response.code
        self.response_time = time_end - self.time_start

        g_logger.debug(self.url)
        g_logger.debug((str(self.status_code) + ' ' + response.phrase))
        g_logger.debug("Response time: %f" % (self.response_time))
        #g_logger.debug(response.headers)

        result = {'status_code': 0, 'time_end': time_end}

        self.report = self._generate_report(result)

        HTTP_SUCCESS_CODE = (200, 302)
        if int(response.code) in HTTP_SUCCESS_CODE:

            g_logger.debug('task done %s' % response.code)
            task_done(self.__class__.__name__, TEST_WEB_TYPE, self)
            #if self.pattern is not None:
            #response.deliverBody(ContentExaminer(self.url,self.pattern))

            #Here we can test the HTTP throttled
            self._throttled_http_test()
        else:
            task_failed(self.__class__.__name__, TEST_WEB_TYPE, self)
            g_logger.error("task failed!")

        return self.report
    def connect_to_peer(self, peer_id):
        if self.agent_is_banned(peer_id):
            g_logger.info("Agent %s is banned." % peer_id)

        if peer_id == theApp.peer_info.ID:
            g_logger.error("Can't connect to self.")
        if peer_id not in self.sessions:
            peer_entry = None
            if peer_id in self.super_peers:
                peer_entry = self.super_peers[peer_id]
            elif peer_id in self.normal_peers:
                peer_entry = self.normal_peers[peer_id]
            elif peer_id in self.mobile_peers:
                peer_entry = self.mobile_peers[peer_id]
            else:
                g_logger.error("Peer id '%s' doesn't exist in all peer lists." %
                               peer_id)
                return

            if self.network_is_banned(peer_entry.IP):
                g_logger.info("Agent %s is banned in network grounds (%s)." % \
                                 (peer_id, peer_entry.IP))
                return

            reactor.connectTCP(peer_entry.IP, peer_entry.Port,
                               theApp.factory)
            g_logger.debug("Connecting to %s:%d..." %
                           (peer_entry.IP, peer_entry.Port))
 def _on_activated(self,widget,row,col):
     """"""
     self.install_btn.set_sensitive(True)
     #choice
     selection = self.treeview.get_selection()
     (model,iter) = selection.get_selected()
     if iter == None:
         return
     else:
         cur_version = self.store.get_value(iter,1)
         #fill self.current_record
         rs = g_db_helper.select("select * from updates where version = '%s'" % cur_version)
         if len(rs) != 1:
             g_logger.error("Record is ERROR in DB!!!! The window will be closed!!!")
             self.destroy()
         self.current_record = {}
         
         self.current_record["version"] = rs[0][0]
         self.current_record["news_date"] = rs[0][1]
         self.current_record["software_name"] = rs[0][2]
         self.current_record["description"] = rs[0][3]
         self.current_record["download_url"] = rs[0][4] 
         self.current_record["is_update"] = rs[0][5]
         self.current_record["check_code"] = rs[0][6]            
           
         
         self.statusbar.push(0,_("You have selected the %s version" % \
                             self.current_record["version"])) 
        
         self.details_textview.set_buffer(self._set_details_content(_(self.current_record["description"] + "\n" + 
                                     "download:"+self.current_record["download_url"] + "\n" +
                                     "Designed by Umit!" 
                                     ))) 
         self.details_textview.show_all()
         g_logger.debug("Selected the item %s" % (self.current_record))              
Exemple #6
0
 def login_failed_autologin(self, message):
     """
     """
     g_logger.error(
         "[Login Failed]Wrong username or password,will login again")
     g_logger.error("[Login Failed]More information:%s" % (message))
     self._alter_network_informaiton(message)
 def _handle_response(self, response):
     """Result Handler (generate report)"""
     time_end = default_timer()
     self.status_code = response.code
     self.response_time = time_end - self.time_start
     
     g_logger.debug(self.url)
     g_logger.debug((str(self.status_code) + ' ' + response.phrase))
     g_logger.debug("Response time: %f" % (self.response_time))
     #g_logger.debug(response.headers)
     
     result = {'status_code': 0, 'time_end': time_end}
     
     self.report = self._generate_report(result)
     
     HTTP_SUCCESS_CODE = (200,302)
     if int(response.code) in HTTP_SUCCESS_CODE:
         
         g_logger.debug('task done %s'%response.code)
         task_done(self.__class__.__name__,TEST_WEB_TYPE,self)
         #if self.pattern is not None:
             #response.deliverBody(ContentExaminer(self.url,self.pattern))
         
         #Here we can test the HTTP throttled 
         self._throttled_http_test()
     else:
         task_failed(self.__class__.__name__,TEST_WEB_TYPE,self)
         g_logger.error("task failed!")
         
     return self.report
def update_test_mod(result, *args, **kw):
    g_logger.info("Updating Test Module...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'test_' + version + '.py'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Test mod %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error("Test mod %s is corrupt. Try to download it again." %
                           filename)
            return

    # Rename the original test.py to test.py.bak,
    # and replace test.py with new one
    origin = os.path.join(ROOT_DIR, 'umit', 'icm', 'agent', 'test.py')
    shutil.copy(origin, origin + '.bak')
    shutil.copy(path, origin)
    if 'umit.icm.agent.test' in sys.modules:
        reload(sys.modules['umit.icm.agent.test'])
    g_logger.info("Test Module updated.")
Exemple #9
0
 def _handle_forward_message_response(self, message):
     if message.identifier not in self.forwarding_defers:
         g_logger.error("message id '%s' not in the forwarding list" % \
                        message.identifier)
     defer_ = self.forwarding_defers[message.identifier]
     response_msg = MessageFactory.decode(\
         base64.b64decode(message.encodedMessage))
     defer_.callback(response_msg)
 def _handle_forward_message_response(self, message):
     if message.identifier not in self.forwarding_defers:
         g_logger.error("message id '%s' not in the forwarding list" % \
                        message.identifier)
     defer_ = self.forwarding_defers[message.identifier]
     response_msg = MessageFactory.decode(\
         base64.b64decode(message.encodedMessage))
     defer_.callback(response_msg)
 def _linux_clear(self):
     file = self.auto_sys_path + self.desktop_name
     if os.path.exists(file):
         try:
             os.remove(file)
             g_logger.info("Cancel Auto StartUP icm-agent in Linux (%s)" % (file))
         except Exception, e:
             g_logger.error("[Failed] Cancel Auto StartUP icm-agent in Linux  (%s)" % (file))
Exemple #12
0
    def _handle_register_response(self, message):
        if message is None:
            g_logger.error("Empty response while trying to register.")
            return

        g_logger.info("RegisterAgent response: (%s, %s)" %
                      (message.agentID, message.publicKeyHash))

        return {'id': message.agentID, 'hash': message.publicKeyHash}
    def _handle_register_response(self, message):
        if message is None:
            g_logger.error("Empty response while trying to register.")
            return

        g_logger.info("RegisterAgent response: (%s, %s)" %
                      (message.agentID, message.publicKeyHash))

        return {'id': message.agentID, 'hash': message.publicKeyHash}
 def _get_value_from_db (self,key):
     """
     get value from the config in DB
     """
     rs = g_db_helper.select("select * from config where key = '%s'" % key)
     if rs == None or len(rs) != 1:
         g_logger.error("Wrong get the value from key:%s in config DB " % (key))   
         return 
     return str(rs[0][1])
Exemple #15
0
 def _get_value_from_db(self, key):
     """
     get value from the config in DB
     """
     rs = g_db_helper.select("select * from config where key = '%s'" % key)
     if rs == None or len(rs) != 1:
         g_logger.error("Wrong get the value from key:%s in config DB " %
                        (key))
         return
     return str(rs[0][1])
Exemple #16
0
 def fetch_task(self):
     """
     fetch task from Aggregator by using Aggregator AssignTask API
     """
     if theApp.aggregator.available:
         g_logger.info("Fetching assigned task from aggregator")
     # defer_ = theApp.aggregator.get_task()
     # defer_.addCallback(self.task_append)
     # defer_.addErrback(self._handler_error(failure))
     else:
         g_logger.error("Cannot connect to Aggregator")
 def set_run_time(self, cron_time):
     time_ = cron_time.split()
     try:
         self.RunTime.minute = self.parser.parse_minute(time_[0])
         self.RunTime.hour = self.parser.parse_hour(time_[1])
         self.RunTime.day = self.parser.parse_day(time_[2])
         self.RunTime.month = self.parser.parse_month(time_[3])
         self.RunTime.weekday = self.parser.parse_weekday(time_[4])
     except:
         g_logger.error("Error in parsing cron time: %s" % cron_time)
     self.CronTimeStr = cron_time
 def set_run_time(self, cron_time):
     time_ = cron_time.split()
     try:
         self.RunTime.minute = self.parser.parse_minute(time_[0])
         self.RunTime.hour = self.parser.parse_hour(time_[1])
         self.RunTime.day = self.parser.parse_day(time_[2])
         self.RunTime.month = self.parser.parse_month(time_[3])
         self.RunTime.weekday = self.parser.parse_weekday(time_[4])
     except:
         g_logger.error("Error in parsing cron time: %s" % cron_time)
     self.CronTimeStr = cron_time
Exemple #19
0
 def _linux_clear(self):
     file = self.auto_sys_path + self.desktop_name
     if os.path.exists(file):
         try:
             os.remove(file)
             g_logger.info("Cancel Auto StartUP icm-agent in Linux (%s)" %
                           (file))
         except Exception, e:
             g_logger.error(
                 "[Failed] Cancel Auto StartUP icm-agent in Linux  (%s)" %
                 (file))
    def _connectionFailed(self, failure):
        
        g_logger.error("[WebsiteTest]connection failed:%s"%failure)
        
        task_failed(self.__class__.__name__, TEST_WEB_TYPE, self)

        result = {'status_code': 1, 'time_end': default_timer()}
        
        self.status_code = 1
        
        return self._generate_report(result)
 def fetch_task(self):
     """
     fetch task from Aggregator by using Aggregator AssignTask API
     """
     if theApp.aggregator.available:
         g_logger.info("Fetching assigned task from aggregator")
        # defer_ = theApp.aggregator.get_task()
        # defer_.addCallback(self.task_append)
        # defer_.addErrback(self._handler_error(failure))
     else:
         g_logger.error("Cannot connect to Aggregator")
    def _connectionFailed(self, failure):

        g_logger.error("[WebsiteTest]connection failed:%s" % failure)

        task_failed(self.__class__.__name__, TEST_WEB_TYPE, self)

        result = {'status_code': 1, 'time_end': default_timer()}

        self.status_code = 1

        return self._generate_report(result)
    def _linux_set(self):
        import shutil

        if not os.path.exists(self.auto_sys_path):
            os.mkdir(self.auto_sys_path)
        try:
            shutil.copy(self.auto_desktop_file, self.auto_sys_path + self.desktop_name)
            g_logger.info("Auto StartUP icm-agent in Linux (%s,%s)" % (self.auto_desktop_file, self.auto_sys_path))
        except Exception, e:
            g_logger.error(
                "[Failed]Auto StartUP icm-agent in Linux (%s,%s,%s)" % (self.auto_desktop_file, self.auto_sys_path, e)
            )
Exemple #24
0
 def _linux_set(self):
     import shutil
     if not os.path.exists(self.auto_sys_path):
         os.mkdir(self.auto_sys_path)
     try:
         shutil.copy(self.auto_desktop_file,
                     self.auto_sys_path + self.desktop_name)
         g_logger.info("Auto StartUP icm-agent in Linux (%s,%s)" %
                       (self.auto_desktop_file, self.auto_sys_path))
     except Exception, e:
         g_logger.error(
             "[Failed]Auto StartUP icm-agent in Linux (%s,%s,%s)" %
             (self.auto_desktop_file, self.auto_sys_path, e))
 def store_bandwidth(self,result,key):
     
     g_logger.debug('finish %s'%benchmark_url_dict[key])
     
     start_time = self.benchmark_bandwidth[key]['start_time']
     end_time = self.benchmark_bandwidth[key]['end_time']
     size = self.benchmark_bandwidth[key]['size']
     if size == 0 or size == None:
         g_logger.error("Error in filesize!!!")
         size = 1
     
     self.benchmark_bandwidth[key]['bandwidth'] =(float)((end_time - start_time) / size)
     
     g_logger.debug(str(key)+':'+str(self.benchmark_bandwidth[key]))
    def store_bandwidth(self, result, key):

        g_logger.debug("finish %s" % benchmark_url_dict[key])

        start_time = self.benchmark_bandwidth[key]["start_time"]
        end_time = self.benchmark_bandwidth[key]["end_time"]
        size = self.benchmark_bandwidth[key]["size"]
        if size == 0 or size == None:
            g_logger.error("Error in filesize!!!")
            size = 1

        self.benchmark_bandwidth[key]["bandwidth"] = (float)((end_time - start_time) / size)

        g_logger.debug(str(key) + ":" + str(self.benchmark_bandwidth[key]))
Exemple #27
0
 def get_task_sets(self,task_type = None):
     """
     Tasks (All, done, wait)for Dashboard Window
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import TASK_ALL,TASK_SUCCESSED,TASK_FAILED
     from umit.icm.agent.test import TASK_STATUS_DONE,TASK_STATUS_FAILED
     if task_type == TASK_ALL:
         return self.db_conn.select("SELECT * from tasks")
     elif task_type == TASK_SUCCESSED:
         return self.db_conn.select("SELECT * from tasks where done_status = '%s' "%(TASK_STATUS_DONE))
     elif task_type == TASK_FAILED:
         return self.db_conn.select("SELECT * from tasks where done_status = '%s' "%(TASK_STATUS_FAILED))
     else:
         g_logger.error("Didn't input any legal task type for query :%s"%(task_type))
         return None
    def store_bandwidth(self, result, key):

        g_logger.debug('finish %s' % benchmark_url_dict[key])

        start_time = self.benchmark_bandwidth[key]['start_time']
        end_time = self.benchmark_bandwidth[key]['end_time']
        size = self.benchmark_bandwidth[key]['size']
        if size == 0 or size == None:
            g_logger.error("Error in filesize!!!")
            size = 1

        self.benchmark_bandwidth[key]['bandwidth'] = (float)(
            (end_time - start_time) / size)

        g_logger.debug(str(key) + ':' + str(self.benchmark_bandwidth[key]))
Exemple #29
0
 def get_report_sets(self,report_type = None):
     """
     Reports for Dashboar Window (sent, unsent, maybe received)
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import REPORT,REPORT_SENT,REPORT_UNSENT,REPORT_RECEIVED
     if report_type == REPORT:
         return None
     elif report_type == REPORT_SENT:
         return self.db_conn.select("SELECT * from reports")
     elif report_type == REPORT_UNSENT:
         return self.db_conn.select("SELECT * from unsent_reports")
     elif report_type == REPORT_RECEIVED:
         return self.db_conn.select("SELECT * from received_reports")
     else:
         g_logger.error("Didn't input any legal report type for query :%s"%(report_type))
         return None
 def changes_by_category_in_range(self, args,choice_tab=None):
     """
     Generic function for changes_anything 
     (choice_tab can provide report, task tab choice)
     (This method also received the range )
     """
     
     if len(args) == 1: # yearly
         return self.changes_in_year(args[0], choice_tab)
     elif len(args) == 2: # monthly
         return self.changes_in_month(args[0], args[1], choice_tab)
     elif len(args) == 3: # daily
         return self.changes_in_day(args[0], args[1], args[2], choice_tab)
     elif len(args) == 4: # hourly
         return self.changes_in_hour(args[0], args[1], args[2], args[3],choice_tab)
     else:
         g_logger.error("Invalid number of parameters specified")
 def get_report_sets(self, report_type=None):
     """
     Reports for Dashboar Window (sent, unsent, maybe received)
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import REPORT, REPORT_SENT, REPORT_UNSENT, REPORT_RECEIVED
     if report_type == REPORT:
         return None
     elif report_type == REPORT_SENT:
         return self.db_conn.select("SELECT * from reports")
     elif report_type == REPORT_UNSENT:
         return self.db_conn.select("SELECT * from unsent_reports")
     elif report_type == REPORT_RECEIVED:
         return self.db_conn.select("SELECT * from received_reports")
     else:
         g_logger.error("Didn't input any legal report type for query :%s" %
                        (report_type))
         return None
 def timerange_changes_count_generic(self,start,end,choice_tab):
     """
     Selects what method to use to grab changes count.
     """
     
     #start and end should always 
     if not start or not end:
         g_logger.error("You should specify range start and range end")
         return
     
     #check choice_tab
     if not choice_tab:
         g_logger.error("You should specify choice_tab")
         return
     
     #Call DB 
     return g_db_helper.timerange_changes_count_generic(start,end,choice_tab)
def task_done(name,task_type=None,task_detail=None):
    """
    Task Done
    """
    #######################
    #Statistics Information 
    theApp.statistics.tasks_done = theApp.statistics.tasks_done + 1
    theApp.statistics.tasks_done_by_type[name] = \
        theApp.statistics.tasks_done_by_type.get(name, 0) + 1
        
    #################################
    #Write task details into database
    now = (str(datetime.datetime.fromtimestamp(time.time()))).split('.')[0]
    print "--------------------------------------------"
    
    if task_type == TEST_WEB_TYPE:
        
        task_web_info = {
                         'test_id': str(theApp.test_sets.current_test_version),
                         'website_url' :  task_detail.url,
                         'test_type' : TEST_WEB_TYPE,
                         'done_status' : TASK_STATUS_DONE,
                         'done_result' : TASK_STATUS_DONE,
                         'execute_time' : now,
                         'unique_id':task_detail.unitied_test_id,
                         }
        
        g_db_helper.task_web(task_web_info)
        
    elif task_type == TEST_SERVICE_TYPE:
        
        task_service_info = {
                         'test_id': str(theApp.test_sets.current_test_version),
                         'service_name' :  task_detail.service_name,
                         'service_ip':task_detail.host,
                         'service_port':task_detail.port,
                         'test_type' : TEST_SERVICE_TYPE,
                         'done_status' : TASK_STATUS_DONE,
                         'done_result' : TASK_STATUS_DONE,
                         'execute_time' : now,
                         'unique_id':task_detail.unitied_test_id,
                         }        
        g_db_helper.task_service(task_service_info)   
        
    else:
        g_logger.error("New Test Type, cannot recognize" ) 
def task_done(name, task_type=None, task_detail=None):
    """
    Task Done
    """
    #######################
    #Statistics Information
    theApp.statistics.tasks_done = theApp.statistics.tasks_done + 1
    theApp.statistics.tasks_done_by_type[name] = \
        theApp.statistics.tasks_done_by_type.get(name, 0) + 1

    #################################
    #Write task details into database
    now = (str(datetime.datetime.fromtimestamp(time.time()))).split('.')[0]
    print "--------------------------------------------"

    if task_type == TEST_WEB_TYPE:

        task_web_info = {
            'test_id': str(theApp.test_sets.current_test_version),
            'website_url': task_detail.url,
            'test_type': TEST_WEB_TYPE,
            'done_status': TASK_STATUS_DONE,
            'done_result': TASK_STATUS_DONE,
            'execute_time': now,
            'unique_id': task_detail.unitied_test_id,
        }

        g_db_helper.task_web(task_web_info)

    elif task_type == TEST_SERVICE_TYPE:

        task_service_info = {
            'test_id': str(theApp.test_sets.current_test_version),
            'service_name': task_detail.service_name,
            'service_ip': task_detail.host,
            'service_port': task_detail.port,
            'test_type': TEST_SERVICE_TYPE,
            'done_status': TASK_STATUS_DONE,
            'done_result': TASK_STATUS_DONE,
            'execute_time': now,
            'unique_id': task_detail.unitied_test_id,
        }
        g_db_helper.task_service(task_service_info)

    else:
        g_logger.error("New Test Type, cannot recognize")
    def timerange_changes_count_generic(self, start, end, choice_tab):
        """
        Selects what method to use to grab changes count.
        """

        #start and end should always
        if not start or not end:
            g_logger.error("You should specify range start and range end")
            return

        #check choice_tab
        if not choice_tab:
            g_logger.error("You should specify choice_tab")
            return

        #Call DB
        return g_db_helper.timerange_changes_count_generic(
            start, end, choice_tab)
    def changes_by_category_in_range(self, args, choice_tab=None):
        """
        Generic function for changes_anything 
        (choice_tab can provide report, task tab choice)
        (This method also received the range )
        """

        if len(args) == 1:  # yearly
            return self.changes_in_year(args[0], choice_tab)
        elif len(args) == 2:  # monthly
            return self.changes_in_month(args[0], args[1], choice_tab)
        elif len(args) == 3:  # daily
            return self.changes_in_day(args[0], args[1], args[2], choice_tab)
        elif len(args) == 4:  # hourly
            return self.changes_in_hour(args[0], args[1], args[2], args[3],
                                        choice_tab)
        else:
            g_logger.error("Invalid number of parameters specified")
 def _handler_error(self,failure):
     
     g_logger.error("fetch task error %s"%str(failure))
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
Exemple #38
0
 def get_test_sets(self,test_type = None):
     """
     Test sets for Dashboard Window(successful or failed)
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import CAPA_THROTTLED,CAPACITY,CAPA_SERVICE
     from umit.icm.agent.test import TASK_STATUS_DONE,TASK_STATUS_FAILED
     if test_type == CAPA_THROTTLED:
         return self.db_conn.select("SELECT \
                                 sequence,test_id,website_url,test_type,done_status,done_result,execute_time \
                                   from tasks where test_type = 'WEB' ")
     elif test_type == CAPACITY:
         return None
     elif test_type == CAPA_SERVICE:
         return self.db_conn.select("SELECT \
                                 sequence,test_id,service_name,service_port,service_ip,test_type,done_status,done_result,execute_time \
                                   from tasks where test_type = 'Service' ")
     else:
         g_logger.error("Didn't input any legal test sets type for query :%s"%(test_type))
         return None   
def task_failed(name, task_type=None, task_detail=None):
    """
    Task Failed
    """
    #######################
    # Statistics Information
    theApp.statistics.tasks_failed = theApp.statistics.tasks_failed + 1
    theApp.statistics.tasks_failed_by_type[name] = theApp.statistics.tasks_failed_by_type.get(name, 0) + 1

    #################################
    # Write task details into database
    now = (str(datetime.datetime.fromtimestamp(time.time()))).split(".")[0]
    if task_type == TEST_WEB_TYPE:

        task_web_info = {
            "test_id": str(theApp.test_sets.current_test_version),
            "website_url": task_detail.url,
            "test_type": TEST_WEB_TYPE,
            "done_status": TASK_STATUS_FAILED,
            "done_result": TASK_STATUS_FAILED,
            "execute_time": now,
            "unique_id": task_detail.unitied_test_id,
        }

        g_db_helper.task_web(task_web_info)

    elif task_type == TEST_SERVICE_TYPE:

        task_service_info = {
            "test_id": str(theApp.test_sets.current_test_version),
            "service_name": task_detail.service_name,
            "service_ip": task_detail.host,
            "service_port": task_detail.port,
            "test_type": TEST_SERVICE_TYPE,
            "done_status": TASK_STATUS_FAILED,
            "done_result": TASK_STATUS_FAILED,
            "execute_time": now,
            "unique_id": task_detail.unitied_test_id,
        }
        g_db_helper.task_service(task_service_info)

    else:
        g_logger.error("New Test Type, cannot recognize")
    def _win_clear(self):
        import _winreg as Regedit

        regedit = Regedit.ConnectRegistry(None, Regedit.HKEY_LOCAL_MACHINE)
        try:
            tag = self.regedit_path
            key = Regedit.OpenKey(regedit, tag, 0, Regedit.KEY_WRITE)
            try:
                try:
                    Regedit.SetValueEx(key, self.key_name, 0, Regedit.REG_SZ, self.exe_path)
                    Regedit.DeleteValue(key, self.key_name)
                    g_logger.info("Cancel Auto StartUP")
                except EnvironmentError:
                    g_logger.error("Cancel Auto StartUP Error in Windows (%s,%s)" % (tag, self.key_name))
                    raise
            finally:
                Regedit.CloseKey(key)
        finally:
            Regedit.CloseKey(regedit)
    def _win_set(self):
        import _winreg as Regedit

        regedit = Regedit.ConnectRegistry(None, Regedit.HKEY_LOCAL_MACHINE)
        try:
            tag = self.regedit_path
            key = Regedit.OpenKey(regedit, tag, 0, Regedit.KEY_WRITE)
            try:
                try:
                    Regedit.SetValueEx(key, self.key_name, 0, Regedit.REG_SZ, self.exe_path)
                    g_logger.info("Auto StartUP icm-agent in Windows (%s,%s,%s)" % (tag, self.key_name, self.exe_path))
                except EnvironmentError:
                    g_logger.error(
                        "Write Regedit key Error in Windows (%s,%s,%s)" % (tag, self.key_name, self.exe_path)
                    )
                    raise
            finally:
                Regedit.CloseKey(key)
        finally:
            Regedit.CloseKey(regedit)
 def get_task_sets(self, task_type=None):
     """
     Tasks (All, done, wait)for Dashboard Window
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import TASK_ALL, TASK_SUCCESSED, TASK_FAILED
     from umit.icm.agent.test import TASK_STATUS_DONE, TASK_STATUS_FAILED
     if task_type == TASK_ALL:
         return self.db_conn.select("SELECT * from tasks")
     elif task_type == TASK_SUCCESSED:
         return self.db_conn.select(
             "SELECT * from tasks where done_status = '%s' " %
             (TASK_STATUS_DONE))
     elif task_type == TASK_FAILED:
         return self.db_conn.select(
             "SELECT * from tasks where done_status = '%s' " %
             (TASK_STATUS_FAILED))
     else:
         g_logger.error("Didn't input any legal task type for query :%s" %
                        (task_type))
         return None
Exemple #43
0
 def _win_clear(self):
     import _winreg as Regedit
     regedit = Regedit.ConnectRegistry(None, Regedit.HKEY_LOCAL_MACHINE)
     try:
         tag = self.regedit_path
         key = Regedit.OpenKey(regedit, tag, 0, Regedit.KEY_WRITE)
         try:
             try:
                 Regedit.SetValueEx(key, self.key_name, 0, Regedit.REG_SZ,
                                    self.exe_path)
                 Regedit.DeleteValue(key, self.key_name)
                 g_logger.info("Cancel Auto StartUP")
             except EnvironmentError:
                 g_logger.error(
                     "Cancel Auto StartUP Error in Windows (%s,%s)" %
                     (tag, self.key_name))
                 raise
         finally:
             Regedit.CloseKey(key)
     finally:
         Regedit.CloseKey(regedit)
 def get_test_sets(self, test_type=None):
     """
     Test sets for Dashboard Window(successful or failed)
     """
     from umit.icm.agent.gui.dashboard.DashboardListBase import CAPA_THROTTLED, CAPACITY, CAPA_SERVICE
     from umit.icm.agent.test import TASK_STATUS_DONE, TASK_STATUS_FAILED
     if test_type == CAPA_THROTTLED:
         return self.db_conn.select("SELECT \
                                 sequence,test_id,website_url,test_type,done_status,done_result,execute_time \
                                   from tasks where test_type = 'WEB' ")
     elif test_type == CAPACITY:
         return None
     elif test_type == CAPA_SERVICE:
         return self.db_conn.select("SELECT \
                                 sequence,test_id,service_name,service_port,service_ip,test_type,done_status,done_result,execute_time \
                                   from tasks where test_type = 'Service' ")
     else:
         g_logger.error(
             "Didn't input any legal test sets type for query :%s" %
             (test_type))
         return None
def update_agent(result, *args, **kw):
    """
    update back
    """
    g_logger.info("Close task looping...")
    theApp.task_assgin_lc.stop()
    theApp.task_run_lc.stop()
    theApp.report_proc_lc.stop()
    theApp.test_sets_fetch_lc()    
    
    g_logger.info("Updating Desktop Agent...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'icm-agent_' + version + '.tar.gz'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Package %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error("Package %s is corrupt. Try to download it again." %
                           filename)
            return
    # Stop current agent
    open(os.path.join(
        ROOT_DIR, 'umit', 'icm', 'agent', 'agent_restart_mark'), 'w').close()
    from twisted.internet import reactor
    reactor.callInThread(restart_agent, path)
    reactor.stop()
    g_logger.debug("reactor stopped.")
Exemple #46
0
def update_agent(result, *args, **kw):
    """
    update back
    """
    g_logger.info("Close task looping...")
    theApp.task_assgin_lc.stop()
    theApp.task_run_lc.stop()
    theApp.report_proc_lc.stop()
    theApp.test_sets_fetch_lc()

    g_logger.info("Updating Desktop Agent...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'icm-agent_' + version + '.tar.gz'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Package %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error("Package %s is corrupt. Try to download it again." %
                           filename)
            return
    # Stop current agent
    open(os.path.join(ROOT_DIR, 'umit', 'icm', 'agent', 'agent_restart_mark'),
         'w').close()
    from twisted.internet import reactor
    reactor.callInThread(restart_agent, path)
    reactor.stop()
    g_logger.debug("reactor stopped.")
Exemple #47
0
 def _win_set(self):
     import _winreg as Regedit
     regedit = Regedit.ConnectRegistry(None, Regedit.HKEY_LOCAL_MACHINE)
     try:
         tag = self.regedit_path
         key = Regedit.OpenKey(regedit, tag, 0, Regedit.KEY_WRITE)
         try:
             try:
                 Regedit.SetValueEx(key, self.key_name, 0, Regedit.REG_SZ,
                                    self.exe_path)
                 g_logger.info(
                     "Auto StartUP icm-agent in Windows (%s,%s,%s)" %
                     (tag, self.key_name, self.exe_path))
             except EnvironmentError:
                 g_logger.error(
                     "Write Regedit key Error in Windows (%s,%s,%s)" %
                     (tag, self.key_name, self.exe_path))
                 raise
         finally:
             Regedit.CloseKey(key)
     finally:
         Regedit.CloseKey(regedit)
Exemple #48
0
    def _on_activated(self, widget, row, col):
        """"""
        self.install_btn.set_sensitive(True)
        #choice
        selection = self.treeview.get_selection()
        (model, iter) = selection.get_selected()
        if iter == None:
            return
        else:
            cur_version = self.store.get_value(iter, 1)
            #fill self.current_record
            rs = g_db_helper.select(
                "select * from updates where version = '%s'" % cur_version)
            if len(rs) != 1:
                g_logger.error(
                    "Record is ERROR in DB!!!! The window will be closed!!!")
                self.destroy()
            self.current_record = {}

            self.current_record["version"] = rs[0][0]
            self.current_record["news_date"] = rs[0][1]
            self.current_record["software_name"] = rs[0][2]
            self.current_record["description"] = rs[0][3]
            self.current_record["download_url"] = rs[0][4]
            self.current_record["is_update"] = rs[0][5]
            self.current_record["check_code"] = rs[0][6]


            self.statusbar.push(0,_("You have selected the %s version" % \
                                self.current_record["version"]))

            self.details_textview.set_buffer(
                self._set_details_content(
                    _(self.current_record["description"] + "\n" + "download:" +
                      self.current_record["download_url"] + "\n" +
                      "Designed by Umit!")))
            self.details_textview.show_all()
            g_logger.debug("Selected the item %s" % (self.current_record))
Exemple #49
0
    def _alter_show(self,primary_text,secondary_text):
        #Add the user-friendly information to the user to check the problem.
        if theApp.use_gui == False:
            g_logger.error(primary_text+secondary_text)
            theApp.login_without_gui()
            return
        
        import gtk
        from higwidgets.higwindows import HIGAlertDialog

        alter = HIGAlertDialog(primary_text = primary_text,\
                                       secondary_text = secondary_text)
        
        alter.show()
        alter.run()
        
        #clear db
        theApp.peer_info.clear_db()
        
        theApp.is_auto_login = False
        
        #show login window again
        theApp.gtk_main.show_login()                
    def _alter_show(self,primary_text,secondary_text):
        #Add the user-friendly information to the user to check the problem.
        if theApp.use_gui == False:
            g_logger.error(primary_text+secondary_text)
            theApp.login_without_gui()
            return
        
        import gtk
        from higwidgets.higwindows import HIGAlertDialog

        alter = HIGAlertDialog(primary_text = primary_text,\
                                       secondary_text = secondary_text)
        
        alter.show()
        alter.run()
        
        #clear db
        theApp.peer_info.clear_db()
        
        theApp.is_auto_login = False
        
        #show login window again
        theApp.gtk_main.show_login()                
Exemple #51
0
    def _connection_errback(self, failure):
        g_logger.error("[AggregatorAPI connection] - %s" % failure)

        if isinstance(failure, error.ConnectError) or \
           isinstance(failure, error.DNSLookupError):
            g_logger.error("Connecting to the aggregator failed.")
            self.available = False
            theApp.statistics.aggregator_fail_num = \
                  theApp.statistics.aggregator_fail_num + 1

        try:
            failure.raiseException()
        except Exception, err:
            if isinstance(err, Error):
                g_logger.error(">>> The Aggregator had an Internal Error:")
                g_logger.error(err.response)
                self._alter_network_informaiton(err.response)
    def _connection_errback(self, failure):
        g_logger.error("[AggregatorAPI connection] - %s - %s" % (failure, failure.printDetailedTraceback()))

        if isinstance(failure, error.ConnectError) or \
           isinstance(failure, error.DNSLookupError):
            g_logger.error("Connecting to the aggregator failed.")
            self.available = False
            theApp.statistics.aggregator_fail_num = \
                  theApp.statistics.aggregator_fail_num + 1

        try:
            failure.raiseException()
        except Exception, err:
            if isinstance(err, Error):
                g_logger.error(">>> The Aggregator had an Internal Error:")
                g_logger.error(err.response)
                self._alter_network_informaiton(err.response)
Exemple #53
0
 def build_super_connection(self,host=None,port=None):
     """
     this method will connect to host:port, to get necessary super peer information,
     and add them into peer list and super peer session.
     we will get peer_id, token, ciphered_public_key from super peer
     """
     if host == None or host == "" or port == None or port == "":
          g_logger.error("Wrong super peer conection information: host->%s, port->%d"%(host,port))
          return
     
     from umit.icm.agent.rpc.message import *
     from umit.icm.agent.rpc.MessageFactory import MessageFactory
     
     g_logger.error('Try to connect to super peer...., to get necessary information!!!')
     
     from umit.icm.agent.utils.CreateDB import mod,exp 
     try:
         s  = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
         s.connect((host,port))
     except:
         g_logger.error('Cannot connect to the super peer, maybe it down!')
         return
     
     request_msg = AuthenticatePeer()
     request_msg.agentID = self.application.peer_info.ID
     request_msg.agentType = 2
     request_msg.agentPort = 5895
     request_msg.cipheredPublicKey.mod = str(mod)
     request_msg.cipheredPublicKey.exp = str(exp)
     data = MessageFactory.encode(request_msg)
     length = struct.pack('!I', len(data))
     s.send(length)
     s.send(data)
     length = struct.unpack('!i', s.recv(4))[0]
     data = s.recv(length)
     response_msg = MessageFactory.decode(data)
     
     g_logger.error('Get the super peer information (ip:%s,port:%s,agentID:%s)\
                     with build_super_connection process'%(host,port,response_msg.token))
     
     self.application.peer_manager.add_super_peer(peer_id=response_msg.token,ip=host,port=port)
 def _handle_errback(self, failure):
     g_logger.error("Aggregator failure: %s" % str(failure))
Exemple #55
0
    def _handler_error(self, failure):

        g_logger.error("fetch task error %s" % str(failure))
Exemple #56
0
    def _handler_error(self, failure):

        print failure
        g_logger.error("Fetch new test sets error %s" % str(failure))
Exemple #57
0
 def _handle_errback(self, failure):
     """
     """
     failure.printTraceback()
     g_logger.error(">>> Failure from Application: %s" % failure)
 def _handle_errback(self, failure):
     """
     """
     failure.printTraceback()
     g_logger.error(">>> Failure from Application: %s" % failure)
 def handler_err(self, failure):
     g_logger.error("[WebsiteTest]bench handle failed:%s" % failure)