diff --git a/esrally/mechanic/team.py b/esrally/mechanic/team.py index aab92ccb4..f0f2b5d23 100644 --- a/esrally/mechanic/team.py +++ b/esrally/mechanic/team.py @@ -49,7 +49,7 @@ def list_cars(cfg: types.Config): console.println(tabulate.tabulate([[c.name, c.type, c.description] for c in cars], headers=["Name", "Type", "Description"])) -def load_car(repo, name, car_params=None): +def load_car(repo: str, name: Collection[str], car_params: Mapping=None) -> "Car": class Component: def __init__(self, root_path, entry_point): self.root_path = root_path diff --git a/esrally/utils/modules.py b/esrally/utils/modules.py index 9b5dd2aa3..555663954 100644 --- a/esrally/utils/modules.py +++ b/esrally/utils/modules.py @@ -77,7 +77,7 @@ def can_load(self): """ :return: True iff the component entry point could be found. """ - return self.root_path and all( + return all(self.root_path) and all( os.path.exists(os.path.join(root_path, "%s.py" % self.component_entry_point)) for root_path in self.root_path ) diff --git a/tests/mechanic/provisioner_test.py b/tests/mechanic/provisioner_test.py index fe6aeae4b..d4a8ac982 100644 --- a/tests/mechanic/provisioner_test.py +++ b/tests/mechanic/provisioner_test.py @@ -42,7 +42,7 @@ def null_apply_config(source_root_path, target_root_path, config_vars): installer = provisioner.ElasticsearchInstaller( car=team.Car( names="unit-test-car", - root_path=None, + root_path=None, # type: ignore config_paths=[HOME_DIR + "/.rally/benchmarks/teams/default/my-car"], variables={ "heap": "4g", diff --git a/tests/mechanic/team_test.py b/tests/mechanic/team_test.py index 32dcbedcf..6fb0fce04 100644 --- a/tests/mechanic/team_test.py +++ b/tests/mechanic/team_test.py @@ -48,17 +48,17 @@ def test_load_known_car(self): car = team.load_car(self.team_dir, ["default"], car_params={"data_paths": ["/mnt/disk0", "/mnt/disk1"]}) assert car.name == "default" assert car.config_paths == [os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates")] - assert car.root_path is None + assert car.root_path == [] assert car.variables == {"heap_size": "1g", "clean_command": "./gradlew clean", "data_paths": ["/mnt/disk0", "/mnt/disk1"]} - assert car.root_path is None + assert car.root_path == [] def test_load_car_with_mixin_single_config_base(self): car = team.load_car(self.team_dir, ["32gheap", "ea"]) assert car.name == "32gheap+ea" assert car.config_paths == [os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates")] - assert car.root_path is None + assert car.root_path == [] assert car.variables == {"heap_size": "32g", "clean_command": "./gradlew clean", "assertions": "true"} - assert car.root_path is None + assert car.root_path == [] def test_load_car_with_mixin_multiple_config_bases(self): car = team.load_car(self.team_dir, ["32gheap", "ea", "verbose"]) @@ -67,7 +67,7 @@ def test_load_car_with_mixin_multiple_config_bases(self): os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates"), os.path.join(current_dir, "data", "cars", "v1", "verbose_logging", "templates"), ] - assert car.root_path is None + assert car.root_path == [] assert car.variables == {"heap_size": "32g", "clean_command": "./gradlew clean", "verbose_logging": "true", "assertions": "true"} def test_load_car_with_install_hook(self): @@ -77,7 +77,7 @@ def test_load_car_with_install_hook(self): os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates"), os.path.join(current_dir, "data", "cars", "v1", "with_hook", "templates"), ] - assert car.root_path == os.path.join(current_dir, "data", "cars", "v1", "with_hook") + assert car.root_path == [os.path.join(current_dir, "data", "cars", "v1", "with_hook")] assert car.variables == {"heap_size": "1g", "clean_command": "./gradlew clean", "data_paths": ["/mnt/disk0", "/mnt/disk1"]} def test_load_car_with_multiple_bases_referring_same_install_hook(self): @@ -88,7 +88,7 @@ def test_load_car_with_multiple_bases_referring_same_install_hook(self): os.path.join(current_dir, "data", "cars", "v1", "with_hook", "templates"), os.path.join(current_dir, "data", "cars", "v1", "verbose_logging", "templates"), ] - assert car.root_path == os.path.join(current_dir, "data", "cars", "v1", "with_hook") + assert car.root_path == [os.path.join(current_dir, "data", "cars", "v1", "with_hook")] assert car.variables == {"heap_size": "16g", "clean_command": "./gradlew clean", "verbose_logging": "true"} def test_raises_error_on_unknown_car(self): @@ -112,12 +112,10 @@ def test_raises_error_on_missing_config_base(self): ): team.load_car(self.team_dir, ["missing_cfg_base"]) - def test_raises_error_if_more_than_one_different_install_hook(self): - with pytest.raises( - exceptions.SystemSetupError, - match=r"Invalid car: \['multi_hook'\]. Multiple bootstrap hooks are forbidden.", - ): - team.load_car(self.team_dir, ["multi_hook"]) + def test_doesnt_raise_error_if_more_than_one_different_install_hook(self): + car = team.load_car(self.team_dir, ["multi_hook"]) + assert isinstance(car.root_path, list) + assert len(car.root_path) == 2 class TestPluginLoader: @@ -229,7 +227,7 @@ def test_loads_module(self): hook = self.UnitTestHook() handler = team.BootstrapHookHandler(plugin, loader_class=self.UnitTestComponentLoader) - handler.loader.registration_function = hook + handler.loader.registration_function = [hook] handler.load() handler.invoke("post_install", variables={"increment": 4}) @@ -242,7 +240,7 @@ def test_cannot_register_for_unknown_phase(self): hook = self.UnitTestHook(phase="this_is_an_unknown_install_phase") handler = team.BootstrapHookHandler(plugin, loader_class=self.UnitTestComponentLoader) - handler.loader.registration_function = hook + handler.loader.registration_function = [hook] with pytest.raises(exceptions.SystemSetupError) as exc: handler.load() assert exc.value.args[0] == "Unknown bootstrap phase [this_is_an_unknown_install_phase]. Valid phases are: ['post_install']."