• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.retry函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vdsm.utils.retry函数的典型用法代码示例。如果您正苦于以下问题:Python retry函数的具体用法?Python retry怎么用?Python retry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了retry函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testThreadLeak

 def testThreadLeak(self):
     mailer = sm.SPM_MailMonitor(StoragePoolStub(), 100)
     threadCount = len(threading.enumerate())
     mailer.stop()
     mailer.run()
     t = lambda: self.assertEquals(threadCount, len(threading.enumerate()))
     retry(AssertionError, t, timeout=4, sleep=0.1)
开发者ID:doronunu,项目名称:vdsm,代码行数:7,代码来源:storageMailboxTests.py


示例2: testZombie

 def testZombie(self):
     args = [EXT_SLEEP, "0"]
     sproc = commands.execCmd(args, sync=False)
     sproc.kill()
     try:
         test = lambda: self.assertEquals(utils.getCmdArgs(sproc.pid),
                                          tuple())
         utils.retry(AssertionError, test, tries=10, sleep=0.1)
     finally:
         sproc.wait()
开发者ID:yingyun001,项目名称:vdsm,代码行数:10,代码来源:utilsTests.py


示例3: testStop

    def testStop(self):
        p = rhandler.PoolHandler()
        procPath = os.path.join("/proc", str(p.process.pid))

        # Make sure handler is running
        self.assertTrue(p.proxy.callCrabRPCFunction(4, "os.path.exists",
                                                    procPath))
        p.stop()
        test = lambda: self.assertFalse(os.path.exists(procPath))

        utils.retry(test, AssertionError, timeout=4, sleep=0.1)
开发者ID:edwardbadboy,项目名称:vdsm-ubuntu,代码行数:11,代码来源:remoteFileHandlerTests.py


示例4: _connect

    def _connect(self):
        self._manager = _SuperVdsmManager(address=ADDRESS, authkey='')
        self._manager.register('instance')
        self._manager.register('open')
        self._log.debug("Trying to connect to Super Vdsm")
        try:
            utils.retry(self._manager.connect, Exception, timeout=60, tries=3)
        except Exception as ex:
            msg = "Connect to supervdsm service failed: %s" % ex
            panic(msg)

        self._svdsm = self._manager.instance()
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:12,代码来源:supervdsm.py


示例5: retryAssert

 def retryAssert(self, *args, **kwargs):
     '''Keep retrying an assertion if AssertionError is raised.
        See function utils.retry for the meaning of the arguments.
     '''
     # the utils module only can be imported correctly after
     # hackVdsmModule() is called. Do not import it at the
     # module level.
     from vdsm.utils import retry
     return retry(expectedException=AssertionError, *args, **kwargs)
开发者ID:humblec,项目名称:vdsm,代码行数:9,代码来源:testrunner.py


示例6: testThreadLeak

    def testThreadLeak(self):
        with make_env() as env:
            mailer = sm.SPM_MailMonitor(
                SPUUID, 100,
                inbox=env.inbox,
                outbox=env.outbox,
                monitorInterval=MONITOR_INTERVAL)
            try:
                threadCount = len(threading.enumerate())
                mailer.stop()
                mailer.run()

                t = lambda: self.assertEqual(
                    threadCount, len(threading.enumerate()))
                retry(AssertionError, t, timeout=4, sleep=0.1)
            finally:
                self.assertTrue(
                    mailer.wait(timeout=MAILER_TIMEOUT),
                    msg='mailer.wait: Timeout expired')
开发者ID:EdDev,项目名称:vdsm,代码行数:19,代码来源:storage_mailbox_test.py


示例7: _recoverThread

 def _recoverThread(self):
     # Trying to run recover process until it works. During that time vdsm
     # stays in recovery mode (_recover=True), means all api requests
     # returns with "vdsm is in initializing process" message.
     utils.retry(self._recoverExistingVms, sleep=5)
开发者ID:kanalun,项目名称:vdsm,代码行数:5,代码来源:clientIF.py


示例8: _connect

 def _connect(self):
     retry(self.start, (socket.error, KeyError), tries=30)
开发者ID:mykaul,项目名称:vdsm,代码行数:2,代码来源:utils.py


示例9: __init__

 def __init__(self):
     retry(self.start, (socket.error, KeyError), tries=30)
开发者ID:futurice,项目名称:vdsm,代码行数:2,代码来源:utils.py


示例10: get

def get(cif=None):
    """Return current connection to libvirt or open a new one.

    Wrap methods of connection object so that they catch disconnection, and
    take vdsm down.
    """
    def wrapMethod(f):
        def wrapper(*args, **kwargs):
            try:
                ret = f(*args, **kwargs)
                if isinstance(ret, libvirt.virDomain):
                    for name in dir(ret):
                        method = getattr(ret, name)
                        if callable(method) and name[0] != '_':
                            setattr(ret, name, wrapMethod(method))
                return ret
            except libvirt.libvirtError as e:
                edom = e.get_error_domain()
                ecode = e.get_error_code()
                EDOMAINS = (libvirt.VIR_FROM_REMOTE,
                            libvirt.VIR_FROM_RPC)
                ECODES = (libvirt.VIR_ERR_SYSTEM_ERROR,
                          libvirt.VIR_ERR_INTERNAL_ERROR,
                          libvirt.VIR_ERR_NO_CONNECT,
                          libvirt.VIR_ERR_INVALID_CONN)
                if edom in EDOMAINS and ecode in ECODES:
                    cif.log.error('connection to libvirt broken. '
                                  'taking vdsm down. ecode: %d edom: %d',
                                  ecode, edom)
                    cif.prepareForShutdown()
                else:
                    cif.log.debug('Unknown libvirterror: ecode: %d edom: %d '
                                  'level: %d message: %s', ecode, edom,
                                  e.get_error_level(), e.get_error_message())
                raise
        wrapper.__name__ = f.__name__
        wrapper.__doc__ = f.__doc__
        return wrapper

    def req(credentials, user_data):
        passwd = file(constants.P_VDSM_LIBVIRT_PASSWD).readline().rstrip("\n")
        for cred in credentials:
            if cred[0] == libvirt.VIR_CRED_AUTHNAME:
                cred[4] = constants.SASL_USERNAME
            elif cred[0] == libvirt.VIR_CRED_PASSPHRASE:
                cred[4] = passwd
        return 0

    auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
            req, None]

    with __connectionLock:
        conn = __connections.get(id(cif))
        if not conn:
            libvirtOpenAuth = functools.partial(libvirt.openAuth,
                                                'qemu:///system', auth, 0)
            logging.debug('trying to connect libvirt')
            conn = utils.retry(libvirtOpenAuth, timeout=10, sleep=0.2)
            __connections[id(cif)] = conn
            if cif is not None:
                for ev in (libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                           libvirt.VIR_DOMAIN_EVENT_ID_REBOOT,
                           libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
                           libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
                           libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS,
                           libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
                           libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG):
                    conn.domainEventRegisterAny(None, ev,
                                                __eventCallback, (cif, ev))
                for name in dir(libvirt.virConnect):
                    method = getattr(conn, name)
                    if callable(method) and name[0] != '_':
                        setattr(conn, name, wrapMethod(method))
            # In case we're running into troubles with keeping the connections
            # alive we should place here:
            # conn.setKeepAlive(interval=5, count=3)
            # However the values need to be considered wisely to not affect
            # hosts which are hosting a lot of virtual machines

        return conn
开发者ID:lukas-bednar,项目名称:vdsm,代码行数:80,代码来源:libvirtconnection.py



注:本文中的vdsm.utils.retry函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.rmFile函数代码示例发布时间:2022-05-26
下一篇:
Python utils.readMemInfo函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap