def setUp(self): super(FunctionalTest, self).setUp() self.test_dir = self.useFixture(fixtures.TempDir()).path self.api_protocol = 'http' self.api_port, search_sock = test_utils.get_unused_port_and_socket() self.tracecmd = tracecmd_osmap.get(platform.system()) conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(conf_dir) self.copy_data_file('policy.json', conf_dir) self.copy_data_file('property-protections.conf', conf_dir) self.copy_data_file('property-protections-policies.conf', conf_dir) self.property_file_roles = os.path.join(conf_dir, 'property-protections.conf') property_policies = 'property-protections-policies.conf' self.property_file_policies = os.path.join(conf_dir, property_policies) self.policy_file = os.path.join(conf_dir, 'policy.json') self.api_server = SearchServer(self.test_dir, self.api_port, self.policy_file, sock=search_sock) self.pid_files = [self.api_server.pid_file] self.files_to_destroy = [] self.launched_servers = []
def setUp(self): super(FunctionalTest, self).setUp() self.test_dir = self.useFixture(fixtures.TempDir()).path self.api_protocol = 'http' self.api_port, search_sock = test_utils.get_unused_port_and_socket() self.tracecmd = tracecmd_osmap.get(platform.system()) self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) self.copy_data_file('policy.json', self.conf_dir) self.copy_data_file('property-protections.conf', self.conf_dir) self.copy_data_file('property-protections-policies.conf', self.conf_dir) self.property_file_roles = os.path.join(self.conf_dir, 'property-protections.conf') property_policies = 'property-protections-policies.conf' self.property_file_policies = os.path.join(self.conf_dir, property_policies) self.policy_file = os.path.join(self.conf_dir, 'policy.json') self.api_server = SearchServer(self.test_dir, self.api_port, self.policy_file, sock=search_sock) self._additional_server_config() self.pid_files = [self.api_server.pid_file] self.files_to_destroy = [] self.launched_servers = [] self.elastic_connection = elasticsearch.Elasticsearch( "http://localhost:%s" % self.api_server.elasticsearch_port) self.api_server.deployment_flavor = "trusted-auth" # Use the role-based policy file all over; we need it for the property # protection tests self.api_server.property_protection_file = self.property_file_roles self.base_url = "http://127.0.0.1:%d/v1" % self.api_port self.start_with_retry(self.api_server, "api_port", max_retries=3, **self.__dict__.copy()) self.addCleanup(self.cleanup) self.initialized_plugins = {} self.configurePlugins()
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) self.set_policy()
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[], default_config_files=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) self.set_policy() utils.register_plugin_opts()
def write_conf(self, **kwargs): """ Writes the configuration file for the server to its intended destination. Returns the name of the configuration file and the over-ridden config content (may be useful for populating error messages). """ if not self.conf_base: raise RuntimeError("Subclass did not populate config_base!") conf_override = self.__dict__.copy() if kwargs: conf_override.update(**kwargs) # A config file and paste.ini to use just for this test...we don't want # to trample on currently-running Searchlight servers, now do we? conf_dir = os.path.join(self.test_dir, 'etc') conf_filepath = os.path.join(conf_dir, "%s.conf" % self.server_name) if os.path.exists(conf_filepath): os.unlink(conf_filepath) paste_conf_filepath = conf_filepath.replace(".conf", "-paste.ini") if os.path.exists(paste_conf_filepath): os.unlink(paste_conf_filepath) utils.safe_mkdirs(conf_dir) def override_conf(filepath, overridden): with open(filepath, 'w') as conf_file: conf_file.write(overridden) conf_file.flush() return conf_file.name overridden_core = self.conf_base % conf_override self.conf_file_name = override_conf(conf_filepath, overridden_core) overridden_paste = '' if self.paste_conf_base: overridden_paste = self.paste_conf_base % conf_override override_conf(paste_conf_filepath, overridden_paste) overridden = ('==Core config==\n%s\n==Paste config==\n%s' % (overridden_core, overridden_paste)) return self.conf_file_name, overridden
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[], default_config_files=[]) self.addCleanup(CONF.reset) self.mock_exception = mock.patch('searchlight.common.exception', True) self.mock_exception.start() self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) service_policies._ENFORCERS = None self.set_policy() utils.register_plugin_opts()
def setUp(self): super(BaseTestCase, self).setUp() # NOTE(bcwaldon): parse_args has to be called to register certain # command-line options - specifically we need config_dir for # the following policy tests config.parse_args(args=[], default_config_files=[]) self.addCleanup(CONF.reset) mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.stubs = mox_fixture.stubs self.mock_exception = mock.patch( 'searchlight.common.exception', True) self.mock_exception.start() self.test_dir = self.useFixture(fixtures.TempDir()).path self.conf_dir = os.path.join(self.test_dir, 'etc') utils.safe_mkdirs(self.conf_dir) service_policies._ENFORCERS = None self.set_policy() utils.register_plugin_opts()