def config_validator(user): from libsentry.api import get_api from libsentry.api2 import get_api as get_api2 res = [] try: get_api(user).list_sentry_roles_by_group('*') except Exception as e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 1)."))) try: get_api2(user).list_sentry_roles_by_group('*') except Exception as e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 2)."))) return res
def test_ha_failover_all_bad(self): # Test with all bad hosts xml = self._sentry_site_xml(rpc_addresses='bad-host-1:8039,bad-host-2', rpc_port=self.rpc_port) file(os.path.join(self.tmpdir, 'sentry-site.xml'), 'w').write(xml) sentry_site.reset() api = get_api(self.user) assert_equal('bad-host-1:8039,bad-host-2', ','.join(sentry_site.get_sentry_server_rpc_addresses())) assert_raises(PopupException, api.list_sentry_roles_by_group, '*') api2 = get_api2(self.user, 'solr') assert_raises(PopupException, api2.list_sentry_roles_by_group, '*')
def test_no_rpc_hosts(self): # Test with no rpc hosts and fallback to hostname and port xml = self._sentry_site_xml(rpc_addresses='') file(os.path.join(self.tmpdir, 'sentry-site.xml'), 'w').write(xml) sentry_site.reset() api = get_api(self.user) assert_false(sentry_site.is_ha_enabled(), sentry_site.get_sentry_server_rpc_addresses()) assert_true(is_enabled() and HOSTNAME.get() and HOSTNAME.get() != 'localhost') resp = api.list_sentry_roles_by_group(groupName='*') assert_true(isinstance(resp, list)) api2 = get_api2(self.user, 'solr') resp = api2.list_sentry_roles_by_group(groupName='*') assert_true(isinstance(resp, list))
def test_ha_failover_good_bad_bad(self): # Test with good-host,bad-host-1,bad-host-2 xml = self._sentry_site_xml(rpc_addresses='%s,bad-host-1,bad-host-2' % self.rpc_addresses) file(os.path.join(self.tmpdir, 'sentry-site.xml'), 'w').write(xml) sentry_site.reset() api = get_api(self.user) assert_equal('%s,bad-host-1,bad-host-2' % self.rpc_addresses, ','.join(sentry_site.get_sentry_server_rpc_addresses())) resp = api.list_sentry_roles_by_group(groupName='*') assert_true(isinstance(resp, list)) api2 = get_api2(self.user, 'solr') resp = api2.list_sentry_roles_by_group(groupName='*') assert_true(isinstance(resp, list))
help=_t("Use Sentry generic API V2 for Hive."), default=False, type=coerce_bool) SOLR_V2 = Config(key="solr_v2", help=_t("Use Sentry generic API V2 for Solr."), default=True, type=coerce_bool) def config_validator(user): from libsentry.api import get_api from libsentry.api2 import get_api as get_api2 res = [] try: get_api(user).list_sentry_roles_by_group('*') except Exception, e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 1)."))) try: get_api2(user).list_sentry_roles_by_group('*') except Exception, e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 2)."))) return res
key="hive_v2", help=_t("Use Sentry generic API V2 for Hive."), default=False, type=coerce_bool) SOLR_V2 = Config( key="solr_v2", help=_t("Use Sentry generic API V2 for Solr."), default=True, type=coerce_bool) def config_validator(user): from libsentry.api import get_api from libsentry.api2 import get_api as get_api2 res = [] try: get_api(user).list_sentry_roles_by_group('*') except Exception, e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 1)."))) try: get_api2(user).list_sentry_roles_by_group('*') except Exception, e: res.append(('%s: Sentry Service' % NICE_NAME, _("Failed to connect to Sentry API (version 2)."))) return res