def get_stubo_setting(self, setting=None, all_hosts=False): key = 'stubo_setting' if not all_hosts: key = '{0}:{1}'.format(self.host, key) if setting: result = self.get_cache_backend()(get_redis_slave()).get(key, setting) else: result = self.get_cache_backend()(get_redis_slave()).get_all(key) return result
def get_stubo_setting(self, setting=None, all_hosts=False): key = 'stubo_setting' if not all_hosts: key = '{0}:{1}'.format(self.host, key) if setting: result = self.get_cache_backend()(get_redis_slave()).get( key, setting) else: result = self.get_cache_backend()(get_redis_slave()).get_all(key) return result
def add_request(session, request_id, stub, system_date, stub_number, request_cache_limit=10): scenario_key = session['scenario'] session_name = session['session'] host, scenario_name = scenario_key.split(':') cache = Cache(host) request_key = '{0}:{1}'.format(session_name, request_id) request_index_key = get_request_index_hash_key(session, stub_number) request_values = cache.get_cache_backend()(get_redis_slave()).values(cache.get_request_key( scenario_name)) cached_requests = [x for x in request_values if stub.response_ids() == x[0]] if len(cached_requests) < request_cache_limit: # Note only cache the first of request_cache_limit requests that have # the same response. Stops memory exhaustion if a test generates a # unique request each time. result = cache.set(cache.get_request_key(scenario_name), request_key, (stub.response_ids(), stub.delay_policy_name(), stub.recorded(), system_date, stub.module(), request_index_key)) log.debug('add_request: {0} {1} {2} {3} {4} stub_number={5} ' 'request_index_key={6}, result={7}'.format(scenario_key, session_name, request_id, stub.response_ids(), stub.delay_policy_name(), stub_number, request_index_key, result)) return request_index_key
def add_request(session, request_id, stub, system_date, stub_number, request_cache_limit=10): scenario_key = session['scenario'] session_name = session['session'] host, scenario_name = scenario_key.split(':') cache = Cache(host) request_key = '{0}:{1}'.format(session_name, request_id) request_index_key = get_request_index_hash_key(session, stub_number) request_values = cache.get_cache_backend()(get_redis_slave()).values( cache.get_request_key(scenario_name)) cached_requests = [ x for x in request_values if stub.response_ids() == x[0] ] if len(cached_requests) < request_cache_limit: # Note only cache the first of request_cache_limit requests that have # the same response. Stops memory exhaustion if a test generates a # unique request each time. result = cache.set( cache.get_request_key(scenario_name), request_key, (stub.response_ids(), stub.delay_policy_name(), stub.recorded(), system_date, stub.module(), request_index_key)) log.debug('add_request: {0} {1} {2} {3} {4} stub_number={5} ' 'request_index_key={6}, result={7}'.format( scenario_key, session_name, request_id, stub.response_ids(), stub.delay_policy_name(), stub_number, request_index_key, result)) return request_index_key
def get_scenario_key(self, session_name): """Lookup the scenario from => host:sessions returns 'host:scenario_name' or None if not found """ log.debug("get_scenario_key: host={0}, session_name={1}".format( self.host, session_name)) key = '{0}:sessions'.format(self.host) scenario = self.get_cache_backend()(get_redis_slave()).get_raw(key, session_name) if not scenario: return None return '{0}:{1}'.format(self.host, scenario)
def get_scenario_key(self, session_name): """Lookup the scenario from => host:sessions returns 'host:scenario_name' or None if not found """ log.debug("get_scenario_key: host={0}, session_name={1}".format( self.host, session_name)) key = '{0}:sessions'.format(self.host) scenario = self.get_cache_backend()(get_redis_slave()).get_raw( key, session_name) if not scenario: return None return '{0}:{1}'.format(self.host, scenario)
def __init__(self, redis_server=None): self.queue = Queue(self.name, server=redis_server or get_redis_slave())
def get_redis_server(local=True): return get_redis_slave() if local else get_redis_master()