def _create_solr_cloud_index(self, name, fields, unique_key_field, df): with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True) try: root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name) config_root_path = '%s/%s' % (solr_config_path, 'conf') zc.copy_path(root_node, config_root_path) if is_enabled(): with open( os.path.join(config_root_path, 'solrconfig.xml.secure')) as f: zc.set( os.path.join(root_node, 'conf', 'solrconfig.xml'), f.read()) if not self.api.create_collection(name): raise Exception('Failed to create collection: %s' % name) except Exception, e: if zc.path_exists(root_node): # Remove the root node from Zookeeper zc.delete_path(root_node) raise PopupException(_( 'Could not create index. Check error logs for more info.'), detail=e) finally:
def test_metadata_configurations(user): from libsentry.conf import is_enabled result = [] if not is_enabled() and NAVIGATOR.APPLY_SENTRY_PERMISSIONS.get(): result.append(("metadata", "Please enable Sentry when using metadata with Security.")) return result
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 copy_configs(fields, unique_key_field, df, solr_cloud_mode=True): # Create temporary copy of solr configs tmp_path = tempfile.mkdtemp() try: config_template_path = get_config_template_path(solr_cloud_mode) solr_config_path = os.path.join(tmp_path, 'solr_configs') shutil.copytree(config_template_path, solr_config_path) if fields or unique_key_field: # Get complete schema.xml with open(os.path.join(config_template_path, 'conf/schema.xml')) as f: schemaxml = SchemaXml(f.read()) schemaxml.uniqueKeyField(unique_key_field) schemaxml.fields(fields) # Write complete schema.xml to copy with open(os.path.join(solr_config_path, 'conf/schema.xml'), 'w') as f: f.write(smart_str(schemaxml.xml)) if df: # Use secure template solrconfig = 'conf/solrconfig.xml%s' % ('.secure' if is_enabled() else '') # Get complete solrconfig.xml with open(os.path.join(config_template_path, solrconfig)) as f: solrconfigxml = SolrConfigXml(f.read()) solrconfigxml.defaultField(df) # Write complete solrconfig.xml to copy with open(os.path.join(solr_config_path, 'conf/solrconfig.xml'), 'w') as f: f.write(smart_str(solrconfigxml.xml)) return tmp_path, solr_config_path except Exception: # Don't leak the tempdir if there was an exception. shutil.rmtree(tmp_path) raise
def _create_solr_cloud_index(self, name, fields, unique_key_field, df): with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True) try: root_node = "%s/%s" % (ZK_SOLR_CONFIG_NAMESPACE, name) config_root_path = "%s/%s" % (solr_config_path, "conf") zc.copy_path(root_node, config_root_path) if is_enabled(): with open(os.path.join(config_root_path, "solrconfig.xml.secure")) as f: zc.set(os.path.join(root_node, "conf", "solrconfig.xml"), f.read()) if not self.api.create_collection(name): raise Exception("Failed to create collection: %s" % name) except Exception, e: if zc.path_exists(root_node): # Remove the root node from Zookeeper zc.delete_path(root_node) raise PopupException(_("Could not create index. Check error logs for more info."), detail=e) finally:
def get_security_default(): '''Get if Sentry is available so that we filter the objects or not''' from libsentry.conf import is_enabled return is_enabled()