How to use retry_wrapper method in tavern

Best Python code snippet using tavern

common.py

Source:common.py Github

copy

Full Screen

...76CONF.register_opts(volume_opts)77URI_VPOOL_VARRAY_CAPACITY = '/block/vpools/{0}/varrays/{1}/capacity'78URI_BLOCK_EXPORTS_FOR_INITIATORS = '/block/exports?initiators={0}'79EXPORT_RETRY_COUNT = 580def retry_wrapper(func):81 def try_and_retry(*args, **kwargs):82 retry = False83 try:84 return func(*args, **kwargs)85 except coprhd_utils.CoprHdError as e:86 # if we got an http error and87 # the string contains 401 or if the string contains the word cookie88 if (e.err_code == coprhd_utils.CoprHdError.HTTP_ERR and89 (e.msg.find('401') != -1 or90 e.msg.lower().find('cookie') != -1)):91 retry = True92 args[0].AUTHENTICATED = False93 else:94 exception_message = (_("\nCoprHD Exception: %(msg)s\n") %...

Full Screen

Full Screen

connection.py

Source:connection.py Github

copy

Full Screen

...4import avro.protocol as protocol5# TODO(hammer): Figure the canonical place to put this file6PROTO_FILE = os.path.join(os.path.dirname(__file__), 'schema/hbase.avpr')7PROTOCOL = protocol.parse(open(PROTO_FILE).read())8def retry_wrapper(fn):9 """a decorator to add retry symantics to any method that uses hbase"""10 def f(self, *args, **kwargs):11 try:12 return fn(self, *args, **kwargs)13 except:14 try:15 self.close()16 except:17 pass18 self.make_connection()19 return fn(self, *args, **kwargs)20 return f21class HBaseConnection(object):22 """...

Full Screen

Full Screen

54397_bootstrap_utils.py

Source:54397_bootstrap_utils.py Github

copy

Full Screen

1# Licensed to the StackStorm, Inc ('StackStorm') under one or more2# contributor license agreements. See the NOTICE file distributed with3# this work for additional information regarding copyright ownership.4# The ASF licenses this file to You under the Apache License, Version 2.05# (the "License"); you may not use this file except in compliance with6# the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15import socket16import retrying17from oslo_config import cfg18from kombu import Connection19from st2common import log as logging20from st2common.transport import utils as transport_utils21from st2common.transport.actionexecutionstate import ACTIONEXECUTIONSTATE_XCHG22from st2common.transport.announcement import ANNOUNCEMENT_XCHG23from st2common.transport.connection_retry_wrapper import ConnectionRetryWrapper24from st2common.transport.execution import EXECUTION_XCHG25from st2common.transport.liveaction import LIVEACTION_XCHG, LIVEACTION_STATUS_MGMT_XCHG26from st2common.transport.reactor import SENSOR_CUD_XCHG27from st2common.transport.reactor import TRIGGER_CUD_XCHG, TRIGGER_INSTANCE_XCHG28from st2common.transport import reactor29from st2common.transport.queues import ACTIONSCHEDULER_REQUEST_QUEUE30from st2common.transport.queues import ACTIONRUNNER_WORK_QUEUE31from st2common.transport.queues import ACTIONRUNNER_CANCEL_QUEUE32from st2common.transport.queues import NOTIFIER_ACTIONUPDATE_WORK_QUEUE33from st2common.transport.queues import RESULTSTRACKER_ACTIONSTATE_WORK_QUEUE34from st2common.transport.queues import RULESENGINE_WORK_QUEUE35from st2common.transport.queues import STREAM_ANNOUNCEMENT_WORK_QUEUE36from st2common.transport.queues import STREAM_EXECUTION_ALL_WORK_QUEUE37from st2common.transport.queues import STREAM_LIVEACTION_WORK_QUEUE38from st2common.transport.queues import STREAM_EXECUTION_OUTPUT_QUEUE39LOG = logging.getLogger('st2common.transport.bootstrap')40__all__ = [41 'register_exchanges',42 'EXCHANGES',43 'QUEUES'44]45# List of exchanges which are pre-declared on service set up.46EXCHANGES = [47 ACTIONEXECUTIONSTATE_XCHG,48 ANNOUNCEMENT_XCHG,49 EXECUTION_XCHG,50 LIVEACTION_XCHG,51 LIVEACTION_STATUS_MGMT_XCHG,52 TRIGGER_CUD_XCHG,53 TRIGGER_INSTANCE_XCHG,54 SENSOR_CUD_XCHG55]56# List of queues which are pre-declared on service startup.57# All the queues need to be declared and bound up front so we can guarantee messages get routed58# and don't get lost even if there are no consumers online59QUEUES = [60 ACTIONSCHEDULER_REQUEST_QUEUE,61 ACTIONRUNNER_WORK_QUEUE,62 ACTIONRUNNER_CANCEL_QUEUE,63 NOTIFIER_ACTIONUPDATE_WORK_QUEUE,64 RESULTSTRACKER_ACTIONSTATE_WORK_QUEUE,65 RULESENGINE_WORK_QUEUE,66 STREAM_ANNOUNCEMENT_WORK_QUEUE,67 STREAM_EXECUTION_ALL_WORK_QUEUE,68 STREAM_LIVEACTION_WORK_QUEUE,69 STREAM_EXECUTION_OUTPUT_QUEUE,70 # Those queues are dynamically / late created on some class init but we still need to71 # pre-declare them for redis Kombu backend to work.72 reactor.get_trigger_cud_queue(name='st2.preinit', routing_key='init'),73 reactor.get_sensor_cud_queue(name='st2.preinit', routing_key='init')74]75def _do_register_exchange(exchange, connection, channel, retry_wrapper):76 try:77 kwargs = {78 'exchange': exchange.name,79 'type': exchange.type,80 'durable': exchange.durable,81 'auto_delete': exchange.auto_delete,82 'arguments': exchange.arguments,83 'nowait': False,84 'passive': False85 }86 # Use the retry wrapper to increase resiliency in recoverable errors.87 retry_wrapper.ensured(connection=connection,88 obj=channel,89 to_ensure_func=channel.exchange_declare,90 **kwargs)91 LOG.debug('Registered exchange %s (%s).' % (exchange.name, str(kwargs)))92 except Exception:93 LOG.exception('Failed to register exchange: %s.', exchange.name)94def _do_predeclare_queue(channel, queue):95 LOG.debug('Predeclaring queue for exchange "%s"' % (queue.exchange.name))96 bound_queue = None97 try:98 bound_queue = queue(channel)99 bound_queue.declare(nowait=False)100 LOG.debug('Predeclared queue for exchange "%s"' % (queue.exchange.name))101 except Exception:102 LOG.exception('Failed to predeclare queue for exchange "%s"' % (queue.exchange.name))103 return bound_queue104def register_exchanges():105 LOG.debug('Registering exchanges...')106 connection_urls = transport_utils.get_messaging_urls()107 with Connection(connection_urls) as conn:108 # Use ConnectionRetryWrapper to deal with rmq clustering etc.109 retry_wrapper = ConnectionRetryWrapper(cluster_size=len(connection_urls), logger=LOG)110 def wrapped_register_exchanges(connection, channel):111 for exchange in EXCHANGES:112 _do_register_exchange(exchange=exchange, connection=connection, channel=channel,113 retry_wrapper=retry_wrapper)114 retry_wrapper.run(connection=conn, wrapped_callback=wrapped_register_exchanges)115 def wrapped_predeclare_queues(connection, channel):116 for queue in QUEUES:117 _do_predeclare_queue(channel=channel, queue=queue)118 retry_wrapper.run(connection=conn, wrapped_callback=wrapped_predeclare_queues)119def register_exchanges_with_retry():120 def retry_if_io_error(exception):121 return isinstance(exception, socket.error)122 retrying_obj = retrying.Retrying(123 retry_on_exception=retry_if_io_error,124 wait_fixed=cfg.CONF.messaging.connection_retry_wait,125 stop_max_attempt_number=cfg.CONF.messaging.connection_retries126 )...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful