Example #1
0
def get_routes_from_coordinator():
    """
    get the associated routes for the worker and store them in cache
    """
    config_cache = ConfigCache()

    config = config_cache.get_config()

    token_header = {"WORKER-ID": config.worker_id,
                    "WORKER-TOKEN": config.worker_token}
    request_uri = "{0}/worker/{1}/routes".format(
        config.coordinator_uri, config.worker_id)

    try:
        resp = http_request(request_uri, token_header, http_verb='GET')

    except requests.RequestException:
        return False

    #if the coordinator issues a response, cache the worker routes
    #and return true
    if resp.status_code == httplib.OK:
        routes = resp.json()['routes']

        config_cache.set_routes(routes)

        return True
Example #2
0
    def test_set_routes_calls_cache_set(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_set', self.cache_set):
            config_cache = ConfigCache()
            config_cache.set_routes(self.routes)

        self.cache_set.assert_called_once_with(
            'routes', jsonutils.dumps(self.routes),
            CONFIG_EXPIRES, CACHE_CONFIG)