def _register_with_coordinator(self, coordinator_uri, personality, registration, auth_header): """ register with the coordinator and persist the configuration to cache """ try: resp = http_request(coordinator_uri + '/pairing', auth_header, jsonutils.dumps(registration), http_verb='POST') except requests.RequestException: _LOG.exception( 'Pairing Process: error posting worker registration') return False _LOG.debug('resp.status_code: {0}'.format(resp.status_code)) if resp.status_code == httplib.ACCEPTED: body = resp.json()['worker_identity'] config = WorkerConfiguration(personality, body['personality_module'], body['worker_token'], body['worker_id'], coordinator_uri) config_cache = ConfigCache() config_cache.set_config(config) return True
def _register_with_coordinator( self, coordinator_uri, personality, registration, auth_header): """ register with the coordinator and persist the configuration to cache """ try: resp = http_request(coordinator_uri + '/pairing', auth_header, jsonutils.dumps( registration), http_verb='POST') except requests.RequestException: _LOG.exception( 'Pairing Process: error posting worker registration') return False _LOG.debug('resp.status_code: {0}'.format(resp.status_code)) if resp.status_code == httplib.ACCEPTED: body = resp.json()['worker_identity'] config = WorkerConfiguration( personality, body['personality_module'], body['worker_token'], body['worker_id'], coordinator_uri) config_cache = ConfigCache() config_cache.set_config(config) return True
def test_set_config_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_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG)
def test_set_config_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_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG)