def _get_server_properties(): global _api_cache if not _api_cache: # If we need to refresh the list or if previously no servers were up _api_cache_lock.acquire() try: if not _api_cache: servers = [] client = ZookeeperClient(hosts=get_sentry_server_ha_zookeeper_quorum()) sentry_servers = client.get_children_data(namespace=get_sentry_server_ha_zookeeper_namespace()) for data in sentry_servers: server = json.loads(data.decode("utf-8")) servers.append( { "hostname": server["address"], "port": server["sslPort"] if server["sslPort"] else server["port"], } ) _api_cache = servers except Exception, e: raise PopupException(_("Error in retrieving Sentry server properties from Zookeeper."), detail=e) finally:
def test_get_children_data(self): root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists') client = ZookeeperClient(hosts=zkensemble(), read_only=False) client.zk.start() try: client.zk.create(root_node, value='test_path_exists', makepath=True) finally: client.zk.stop() db = client.get_children_data(namespace=TestWithZooKeeper.namespace) assert_true(len(db) > 0)
def _get_server_properties(): global _api_cache if not _api_cache: # If we need to refresh the list or if previously no servers were up _api_cache_lock.acquire() try: if not _api_cache: servers = [] client = ZookeeperClient(hosts=get_sentry_server_ha_zookeeper_quorum()) sentry_servers = client.get_children_data(namespace=get_sentry_server_ha_zookeeper_namespace()) for data in sentry_servers: server = json.loads(data.decode("utf-8")) servers.append({'hostname': server['address'], 'port': server['sslPort'] if server['sslPort'] else server['port']}) _api_cache = servers except Exception, e: raise PopupException(_('Error in retrieving Sentry server properties from Zookeeper.'), detail=e) finally:
def test_get_children_data(self): client = ZookeeperClient(hosts=zkensemble()) db = client.get_children_data(namespace='') assert_true(len(db) > 0)