예제 #1
0
def update_error_task(task, results, db, query_db):
    task['retryCount'] = task.get('retryCount', 0) + 1
    if results:
        task['retryCount'] = -2
        db.error_task.save(task)
        db_update(db.device, {"_id": task.get("dev_id")}, {
            "$set": {
                "devices.%s.code" % task.get('name'): STATUS_RETRY_SUCCESS
            }
        })
        logger.debug('successed, task_id = %s dev_id = %s host=%s...' %
                     (task.get("_id"), task.get("dev_id"), task.get("host")))
        if not query_db.error_tasks.find({
                "dev_id": task.get("dev_id"),
                "retryCount": {
                    '$ne': -2
                },
                "status": 'OPEN'
        }).count():
            verify.verify(task.get("urls"), db, 'FINISHED')
    else:
        db.error_task.save(task)
    if task.get('retryCount') == 1:
        logger.debug(
            "retryCount:3, status:FAILED,task_id : %s dev_id : %s..." %
            (task.get("_id"), task.get("dev_id")))
        verify.verify(task.get("urls"), db, 'FAILED')
        queue.put_json2("error_task", [get_queue(task)])
예제 #2
0
def run():
    res, user_dic = verify.verify()
    if res:
        res, result = display.display(user_dic)

        if res:
            while True:
                inp = input(">>>").strip()
                if len(inp) == 0: continue
                if inp == 'exit': exit()
                if hasattr(command.cmdHandler, inp):
                    func = getattr(command.cmdHandler, inp)
                    local = input("local_file>").strip()
                    target = input("target_file>").strip()
                    for line in result:
                        t = threading.Thread(target=func,
                                             args=(line, local, target))
                        t.start()
                else:
                    for line in result:
                        t = threading.Thread(target=command.worker,
                                             args=(
                                                 line,
                                                 inp,
                                             ))
                        t.start()
        else:
            print("\033[32;1m没有主机.\033[0m")
            exit()
    else:
        exit()
예제 #3
0
    def save_device_results(self, url):
        tt1 = time.time()
        db.device.insert(self.db_dev)
        tt2 = time.time()
        logger.debug(
            'save_device_results devices insert over by %s s ,dev_id %s' %
            (tt2 - tt1, self.db_dev.get('_id')))
        logger.debug('init refresh_result start...')
        # try:
        #     self.insert_refresh_result([url], self.db_dev.get('devices').values())
        # except Exception, e:
        #     logger.info('insert_refresh_result error urls:%s, error:%s' % ([url], traceback.format_exc(e)))
        # logger.debug('init refresh_result end...')

        # if devices is null, we think is a successful one, we can get the info from db.device to know that the devices is empty.

        # devices_list_failed_test = []
        # dev_failed_test = {}
        # dev_failed_test['host'] = '58.67.207.6'
        # dev_failed_test['name'] = 'BGP-GZ-5-3g3'
        # dev_failed_test['firstLayer'] = False
        # devices_list_failed_test.append(dev_failed_test)

        if not self.db_dev.get("devices"):
            #  url refresh at this place, which is finished by default
            verify.verify([url], db)
            # verify.verify([url], db, 'FAILED')
        else:
            # test
            # link_detection.link_detection.delay([url], devices_list_failed_test, "ret")
            if self.fail_device_list:
                # if devices_list_failed_test:
                verify.verify([url], db, 'FAILED', self.db_dev)
                try:
                    # link_detection.link_detection.delay(rid, failed_dev_list)

                    link_detection_all.link_detection_refresh.delay(
                        [url], self.fail_device_list, "ret")

                    # link_detection.link_detection.delay([url], self.fail_device_list,"ret")

                    # test
                    # link_detection.link_detection.delay([url], devices_list_failed_test, "ret")
                except Exception, ex:
                    logger.error(ex)
                    # verify.verify([url], db, 'FAILED', self.db_dev)
            else:
예제 #4
0
def test_create_new_todo():
    to_do = Todo(text='Hello Blat', due_date='Wed Jul 05 2023')
    # to_do = Todo(text='Hello Blat')
    screen('todo').create_new_todo(to_do)
    existing_todos: List = screen("todo").get_existing_todos()
    assert verify(to_do == existing_todos[0], True, operator='==')
예제 #5
0
                    link_detection_all.link_detection_refresh.delay(
                        [url], self.fail_device_list, "ret")

                    # link_detection.link_detection.delay([url], self.fail_device_list,"ret")

                    # test
                    # link_detection.link_detection.delay([url], devices_list_failed_test, "ret")
                except Exception, ex:
                    logger.error(ex)
                    # verify.verify([url], db, 'FAILED', self.db_dev)
            else:
                # if self.conflict:
                #     verify.verify(urls, db, 'CONFLICT', self.db_dev)
                # else:
                verify.verify([url], db, devs=self.db_dev)
        tt3 = time.time()
        logger.debug('save_device_results dir update over by %s s ,dev_id %s' %
                     (tt3 - tt2, self.db_dev.get('_id')))

    def get_refresh_results(self, results):
        for ret in results:
            self.db_dev.get("devices").get(
                ret.get("name"))["code"] = ret.get("code")
            self.db_dev.get("devices").get(
                ret.get("name"))["total_cost"] = ret.get("total_cost")
            self.db_dev.get("devices").get(
                ret.get("name"))["connect_cost"] = ret.get("connect_cost")
            self.db_dev.get("devices").get(
                ret.get("name"))["response_cost"] = ret.get("response_cost")
            self.db_dev.get("devices").get(
예제 #6
0
    def save_device_results(self, urls):

        tt1 = time.time()
        db.device.insert(self.db_dev)
        tt2 = time.time()
        logger.debug(
            'save_device_results devices insert over by %s s ,dev_id %s' %
            (tt2 - tt1, self.db_dev.get('_id')))

        # if devices is null, we think is a successful one, we can get the info from db.device to know that the devices is empty.

        # devices_list_failed_test = []
        # dev_failed_test = {}
        # dev_failed_test['host'] = '182.118.78.102'
        # dev_failed_test['name'] = 'BGP-GZ-5-3g3'
        # dev_failed_test['firstLayer'] = False
        # devices_list_failed_test.append(dev_failed_test)
        try:
            user_list = eval(
                config.get('refresh_redis_store_usernames', 'usernames'))
        except Exception:
            logger.debug('splitter_new submit error:%s' %
                         traceback.format_exc())
            user_list = []

        if urls[0].get("username") in user_list:
            delete_fc_rid(urls, list(self.db_dev.get("devices").values()))
            sadd_hpcc_urlid(urls, list(self.db_dev.get('devices').values()))

        if not self.db_dev.get("devices"):
            verify.verify(urls, db)
        else:
            if self.fail_device_list:
                verify.verify(urls, db, 'FAILED', self.db_dev)
                try:
                    # link_detection.link_detection.delay(rid, failed_dev_list)
                    # link_detection.link_detection.delay(urls, devices_list_failed_test, "url_ret")
                    # logger.debug('test save_device_results fail_device_list:%s' % self.fail_device_list)
                    link_detection_all.link_detection_refresh.delay(
                        urls, self.fail_device_list, "url_ret")
                except Exception:
                    logger.debug(traceback.format_exc())
                    logger.error(ex)
                #verify.verify(urls, db, 'FAILED', self.db_dev)
            else:
                # if self.conflict:
                #     verify.verify(urls, db, 'CONFLICT', self.db_dev)
                # else:
                verify.verify(urls, db, devs=self.db_dev)
        tt3 = time.time()
        try:
            for url_dict in urls:
                #logger.debug('----------%s'%(url_dict))
                if url_dict['type'] == 'REFRESH_PRELOAD':
                    refresh_end = datetime.now()
                    db.refresh_preload.update(
                        {
                            'url': url_dict['url'],
                            "r_id": url_dict['r_id']
                        }, {
                            '$set': {
                                'callback': 'success',
                                'refresh_end_time': refresh_end
                            }
                        },
                        multi=True)
        except Exception:
            logger.debug(e.message)
        logger.debug(
            'save_device_results url update over by %s s ,dev_id %s, len url is %s'
            % (tt3 - tt2, self.db_dev.get('_id'), len(urls)))
예제 #7
0
        # dev_failed_test['firstLayer'] = False
        # devices_list_failed_test.append(dev_failed_test)
        try:
            user_list = eval(
                config.get('refresh_redis_store_usernames', 'usernames'))
        except Exception, e:
            logger.debug('splitter_new submit error:%s' %
                         traceback.format_exc(e))
            user_list = []

        if urls[0].get("username") in user_list:
            delete_fc_rid(urls, self.db_dev.get("devices").values())
            sadd_hpcc_urlid(urls, self.db_dev.get('devices').values())

        if not self.db_dev.get("devices"):
            verify.verify(urls, db)
        else:
            if self.fail_device_list:
                verify.verify(urls, db, 'FAILED', self.db_dev)
                try:
                    # link_detection.link_detection.delay(rid, failed_dev_list)
                    # link_detection.link_detection.delay(urls, devices_list_failed_test, "url_ret")
                    # logger.debug('test save_device_results fail_device_list:%s' % self.fail_device_list)
                    link_detection_all.link_detection_refresh.delay(
                        urls, self.fail_device_list, "url_ret")
                except Exception, ex:
                    logger.debug(traceback.format_exc(ex))
                    logger.error(ex)
                    # verify.verify(urls, db, 'FAILED', self.db_dev)
            else:
                # if self.conflict: