def test_invokes_hook_with_java_home(self): plugin = team.PluginDescriptor( name="unit-test-plugin", config="default", config_paths=["/etc/plugin"], variables={ "active": True, }, ) installer = provisioner.PluginInstaller( plugin, java_home="/usr/local/javas/java8", hook_handler_class=NoopHookHandler) assert len(installer.hook_handler.hook_calls) == 0 installer.invoke_install_hook(team.BootstrapPhase.post_install, {"foo": "bar"}) assert len(installer.hook_handler.hook_calls) == 1 assert installer.hook_handler.hook_calls["post_install"][ "variables"] == { "foo": "bar" } assert installer.hook_handler.hook_calls["post_install"]["kwargs"] == { "env": { "JAVA_HOME": "/usr/local/javas/java8" } }
def test_pass_plugin_properties(self): plugin = team.PluginDescriptor(name="unit-test-plugin", config="default", config_paths=["/etc/plugin"], variables={"active": True}) installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) self.assertEqual("unit-test-plugin", installer.plugin_name) self.assertEqual({"active": True}, installer.variables) self.assertEqual(["/etc/plugin"], installer.config_source_paths)
def test_invokes_hook(self): plugin = team.PluginDescriptor(name="unit-test-plugin", config="default", config_paths=["/etc/plugin"], variables={"active": True}) installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) self.assertEqual(0, len(installer.hook_handler.hook_calls)) installer.invoke_install_hook(provisioner.ProvisioningPhase.post_install, {"foo": "bar"}) self.assertEqual(1, len(installer.hook_handler.hook_calls)) self.assertEqual({"foo": "bar"}, installer.hook_handler.hook_calls["post_install"])
def test_install_plugin_successfully(self, installer_subprocess): installer_subprocess.return_value = 0 plugin = team.PluginDescriptor(name="unit-test-plugin", config="default", variables={"active": True}) installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) installer.install(es_home_path="/opt/elasticsearch") installer_subprocess.assert_called_with('/opt/elasticsearch/bin/elasticsearch-plugin install --batch "unit-test-plugin"')
def test_install_plugin_with_io_error(self, installer_subprocess): # I/O error installer_subprocess.return_value = 74 plugin = team.PluginDescriptor(name="simple") installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) with self.assertRaises(exceptions.SupplyError) as ctx: installer.install(es_home_path="/opt/elasticsearch") self.assertEqual("I/O error while trying to install [simple]", ctx.exception.args[0]) installer_subprocess.assert_called_with('/opt/elasticsearch/bin/elasticsearch-plugin install --batch "simple"')
def test_install_unknown_plugin(self, installer_subprocess): # unknown plugin installer_subprocess.return_value = 64 plugin = team.PluginDescriptor(name="unknown") installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) with self.assertRaises(exceptions.SystemSetupError) as ctx: installer.install(es_home_path="/opt/elasticsearch") self.assertEqual("Unknown plugin [unknown]", ctx.exception.args[0]) installer_subprocess.assert_called_with('/opt/elasticsearch/bin/elasticsearch-plugin install --batch "unknown"')
def test_install_plugin_with_unknown_error(self, installer_subprocess): # some other error installer_subprocess.return_value = 12987 plugin = team.PluginDescriptor(name="simple") installer = provisioner.PluginInstaller(plugin, hook_handler_class=PluginInstallerTests.NoopHookHandler) with self.assertRaises(exceptions.RallyError) as ctx: installer.install(es_home_path="/opt/elasticsearch") self.assertEqual("Unknown error while trying to install [simple] (installer return code [12987]). Please check the logs.", ctx.exception.args[0]) installer_subprocess.assert_called_with('/opt/elasticsearch/bin/elasticsearch-plugin install --batch "simple"')
def test_invokes_hook_no_java_home(self): plugin = team.PluginDescriptor(name="unit-test-plugin", config="default", config_paths=["/etc/plugin"], variables={"active": True}) installer = provisioner.PluginInstaller(plugin, java_home=None, hook_handler_class=NoopHookHandler) self.assertEqual(0, len(installer.hook_handler.hook_calls)) installer.invoke_install_hook(team.BootstrapPhase.post_install, {"foo": "bar"}) self.assertEqual(1, len(installer.hook_handler.hook_calls)) self.assertEqual({"foo": "bar"}, installer.hook_handler.hook_calls["post_install"]["variables"]) self.assertEqual({"env": {}}, installer.hook_handler.hook_calls["post_install"]["kwargs"])
def test_pass_plugin_properties(self): plugin = team.PluginDescriptor( name="unit-test-plugin", config="default", config_paths=["/etc/plugin"], variables={ "active": True, }, ) installer = provisioner.PluginInstaller( plugin, java_home="/usr/local/javas/java8", hook_handler_class=NoopHookHandler) assert installer.plugin_name == "unit-test-plugin" assert installer.variables == {"active": True} assert installer.config_source_paths == ["/etc/plugin"]
def test_install_unknown_plugin(self, installer_subprocess): # unknown plugin installer_subprocess.return_value = 64 plugin = team.PluginDescriptor(name="unknown") installer = provisioner.PluginInstaller( plugin, java_home="/usr/local/javas/java8", hook_handler_class=NoopHookHandler) with pytest.raises(exceptions.SystemSetupError) as exc: installer.install(es_home_path="/opt/elasticsearch") assert exc.value.args[0] == "Unknown plugin [unknown]" installer_subprocess.assert_called_with( '/opt/elasticsearch/bin/elasticsearch-plugin install --batch "unknown"', env={"JAVA_HOME": "/usr/local/javas/java8"}, )
def test_install_plugin_with_unknown_error(self, installer_subprocess): # some other error installer_subprocess.return_value = 12987 plugin = team.PluginDescriptor(name="simple") installer = provisioner.PluginInstaller( plugin, java_home="/usr/local/javas/java8", hook_handler_class=NoopHookHandler) with pytest.raises(exceptions.RallyError) as exc: installer.install(es_home_path="/opt/elasticsearch") assert exc.value.args[ 0] == "Unknown error while trying to install [simple] (installer return code [12987]). Please check the logs." installer_subprocess.assert_called_with( '/opt/elasticsearch/bin/elasticsearch-plugin install --batch "simple"', env={"JAVA_HOME": "/usr/local/javas/java8"}, )
def test_install_plugin_with_io_error(self, installer_subprocess): # I/O error installer_subprocess.return_value = 74 plugin = team.PluginDescriptor(name="simple") installer = provisioner.PluginInstaller( plugin, java_home="/usr/local/javas/java8", hook_handler_class=NoopHookHandler) with pytest.raises(exceptions.SupplyError) as exc: installer.install(es_home_path="/opt/elasticsearch") assert exc.value.args[ 0] == "I/O error while trying to install [simple]" installer_subprocess.assert_called_with( '/opt/elasticsearch/bin/elasticsearch-plugin install --batch "simple"', env={"JAVA_HOME": "/usr/local/javas/java8"}, )
def test_install_plugin_with_bundled_jdk(self, installer_subprocess): installer_subprocess.return_value = 0 plugin = team.PluginDescriptor( name="unit-test-plugin", config="default", variables={ "active": True, }, ) installer = provisioner.PluginInstaller( plugin, # bundled JDK java_home=None, hook_handler_class=NoopHookHandler, ) installer.install(es_home_path="/opt/elasticsearch") installer_subprocess.assert_called_with( '/opt/elasticsearch/bin/elasticsearch-plugin install --batch "unit-test-plugin"', env={}, )
def test_prepare_distribution_ge_63_with_plugins(self, mock_rm, mock_ensure_dir, mock_install, mock_decompress): """ Test that plugin.mandatory is set to the meta plugin name (e.g. `x-pack`) and not the specific plugin name (e.g. `x-pack-security`) for Elasticsearch >=6.3.0 See: https://github.com/elastic/elasticsearch/pull/28710 """ apply_config_calls = [] def null_apply_config(source_root_path, target_root_path, config_vars): apply_config_calls.append( (source_root_path, target_root_path, config_vars)) installer = provisioner.ElasticsearchInstaller( car=team.Car(names="unit-test-car", root_path=None, config_paths=[ HOME_DIR + "/.rally/benchmarks/teams/default/my-car" ], variables={ "heap": "4g", "runtime.jdk": "8", "runtime.jdk.bundled": "true" }), java_home="/usr/local/javas/java8", node_name="rally-node-0", node_root_dir=HOME_DIR + "/.rally/benchmarks/races/unittest", all_node_ips=["10.17.22.22", "10.17.22.23"], all_node_names=["rally-node-0", "rally-node-1"], ip="10.17.22.23", http_port=9200) p = provisioner.BareProvisioner( cluster_settings={"indices.query.bool.max_clause_count": 50000}, es_installer=installer, plugin_installers=[ provisioner.PluginInstaller( BareProvisionerTests.MockRallyTeamXPackPlugin(), java_home="/usr/local/javas/java8", hook_handler_class=BareProvisionerTests.NoopHookHandler) ], distribution_version="6.3.0", apply_config=null_apply_config) node_config = p.prepare( {"elasticsearch": "/opt/elasticsearch-6.3.0.tar.gz"}) self.assertEqual({}, node_config.car_env) self.assertEqual("8", node_config.car_runtime_jdks) self.assertEqual("/opt/elasticsearch-6.3.0", node_config.binary_path) self.assertEqual(["/opt/elasticsearch-6.3.0/data"], node_config.data_paths) self.assertEqual(1, len(apply_config_calls)) source_root_path, target_root_path, config_vars = apply_config_calls[0] self.assertEqual(HOME_DIR + "/.rally/benchmarks/teams/default/my-car", source_root_path) self.assertEqual("/opt/elasticsearch-6.3.0", target_root_path) self.maxDiff = None self.assertEqual( { "cluster_settings": { "indices.query.bool.max_clause_count": 50000, "plugin.mandatory": ["x-pack"] }, "heap": "4g", "runtime.jdk": "8", "runtime.jdk.bundled": "true", "cluster_name": "rally-benchmark", "node_name": "rally-node-0", "data_paths": ["/opt/elasticsearch-6.3.0/data"], "log_path": HOME_DIR + "/.rally/benchmarks/races/unittest/logs/server", "heap_dump_path": HOME_DIR + "/.rally/benchmarks/races/unittest/heapdump", "node_ip": "10.17.22.23", "network_host": "10.17.22.23", "http_port": "9200", "transport_port": "9300", "all_node_ips": "[\"10.17.22.22\",\"10.17.22.23\"]", "all_node_names": "[\"rally-node-0\",\"rally-node-1\"]", "minimum_master_nodes": 2, "install_root_path": "/opt/elasticsearch-6.3.0", "plugin_name": "x-pack-security", "xpack_security_enabled": True }, config_vars)
def test_prepare_distribution_lt_63_with_plugins(self, mock_rm, mock_ensure_dir, mock_install, mock_decompress): """ Test that plugin.mandatory is set to the specific plugin name (e.g. `x-pack-security`) and not the meta plugin name (e.g. `x-pack`) for Elasticsearch <6.3 See: https://github.com/elastic/elasticsearch/pull/28710 """ apply_config_calls = [] def null_apply_config(source_root_path, target_root_path, config_vars): apply_config_calls.append( (source_root_path, target_root_path, config_vars)) installer = provisioner.ElasticsearchInstaller( car=team.Car( names="unit-test-car", root_path=None, config_paths=[ HOME_DIR + "/.rally/benchmarks/teams/default/my-car" ], variables={ "heap": "4g", "runtime.jdk": "8", "runtime.jdk.bundled": "true", }, ), java_home="/usr/local/javas/java8", node_name="rally-node-0", node_root_dir=HOME_DIR + "/.rally/benchmarks/races/unittest", all_node_ips=["10.17.22.22", "10.17.22.23"], all_node_names=["rally-node-0", "rally-node-1"], ip="10.17.22.23", http_port=9200, ) p = provisioner.BareProvisioner( es_installer=installer, plugin_installers=[ provisioner.PluginInstaller( self.MockRallyTeamXPackPlugin(), java_home="/usr/local/javas/java8", hook_handler_class=self.NoopHookHandler, ) ], distribution_version="6.2.3", apply_config=null_apply_config, ) node_config = p.prepare( {"elasticsearch": "/opt/elasticsearch-5.0.0.tar.gz"}) assert node_config.car_runtime_jdks == "8" assert node_config.binary_path == "/opt/elasticsearch-5.0.0" assert node_config.data_paths == ["/opt/elasticsearch-5.0.0/data"] assert len(apply_config_calls) == 1 source_root_path, target_root_path, config_vars = apply_config_calls[0] assert source_root_path == HOME_DIR + "/.rally/benchmarks/teams/default/my-car" assert target_root_path == "/opt/elasticsearch-5.0.0" self.maxDiff = None assert config_vars == { "cluster_settings": { "plugin.mandatory": ["x-pack-security"] }, "heap": "4g", "runtime.jdk": "8", "runtime.jdk.bundled": "true", "cluster_name": "rally-benchmark", "node_name": "rally-node-0", "data_paths": ["/opt/elasticsearch-5.0.0/data"], "log_path": HOME_DIR + "/.rally/benchmarks/races/unittest/logs/server", "heap_dump_path": HOME_DIR + "/.rally/benchmarks/races/unittest/heapdump", "node_ip": "10.17.22.23", "network_host": "10.17.22.23", "http_port": "9200", "transport_port": "9300", "all_node_ips": '["10.17.22.22","10.17.22.23"]', "all_node_names": '["rally-node-0","rally-node-1"]', "minimum_master_nodes": 2, "install_root_path": "/opt/elasticsearch-5.0.0", "plugin_name": "x-pack-security", "xpack_security_enabled": True, }