diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2022-11-08 16:01:30 +0100 |
---|---|---|
committer | Erik Skultety <eskultet@redhat.com> | 2023-02-10 13:05:14 +0000 |
commit | 1c3e16cae38407d0782dc94080d1104106456fa4 (patch) | |
tree | b27a3bdf1ac58c874f65153c0d56af2e562bbbc7 | |
parent | 2c7122b72ca294780cda7b0650444a07e645d338 (diff) | |
download | libvirt-ci-1c3e16cae38407d0782dc94080d1104106456fa4.zip libvirt-ci-1c3e16cae38407d0782dc94080d1104106456fa4.tar.gz libvirt-ci-1c3e16cae38407d0782dc94080d1104106456fa4.tar.bz2 |
targets: support overriding target facts
Allow overriding target facts in a project. This is useful to specify
the paths to a specific version of Python.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | docs/platforms_and_mappings.rst | 1 | ||||
-rw-r--r-- | lcitool/application.py | 16 | ||||
-rw-r--r-- | lcitool/targets.py | 7 | ||||
-rw-r--r-- | lcitool/util.py | 9 | ||||
-rw-r--r-- | tests/data/targets/override/targets/centos-stream-8.yml | 3 | ||||
-rw-r--r-- | tests/test_targets.py | 14 |
6 files changed, 29 insertions, 21 deletions
diff --git a/docs/platforms_and_mappings.rst b/docs/platforms_and_mappings.rst index 6b45b98..cc2d024 100644 --- a/docs/platforms_and_mappings.rst +++ b/docs/platforms_and_mappings.rst @@ -106,3 +106,4 @@ the libvirt-ci repository, located using the ``--data-dir DIR`` argument to ``lcitool``, is extended to the following paths:: $DIR/mappings.yml + $DIR/targets/$NAME.yml diff --git a/lcitool/application.py b/lcitool/application.py index e70b391..e1c55f0 100644 --- a/lcitool/application.py +++ b/lcitool/application.py @@ -72,7 +72,7 @@ class Application: base = resource_filename(__name__, "ansible") config = Config() - targets = Targets() + targets = Targets(data_dir) inventory = Inventory(targets, config) packages = Packages(data_dir) projects = Projects(data_dir) @@ -134,7 +134,7 @@ class Application: self._entrypoint_debug(args) config = Config() - targets = Targets() + targets = Targets(args.data_dir) inventory = Inventory(targets, config) for host in sorted(inventory.hosts): print(host) @@ -142,7 +142,7 @@ class Application: def _action_targets(self, args): self._entrypoint_debug(args) - targets = Targets() + targets = Targets(args.data_dir) for target in sorted(targets.targets): if args.containerized: facts = targets.target_facts[target] @@ -167,7 +167,7 @@ class Application: facts = {} config = Config() - targets = Targets() + targets = Targets(args.data_dir) inventory = Inventory(targets, config) host = args.host target = args.target @@ -224,7 +224,7 @@ class Application: def _action_variables(self, args): self._entrypoint_debug(args) - targets = Targets() + targets = Targets(args.data_dir) packages = Packages(args.data_dir) projects = Projects(args.data_dir) projects_expanded = projects.expand_names(args.projects) @@ -253,7 +253,7 @@ class Application: def _action_dockerfile(self, args): self._entrypoint_debug(args) - targets = Targets() + targets = Targets(args.data_dir) packages = Packages(args.data_dir) projects = Projects(args.data_dir) projects_expanded = projects.expand_names(args.projects) @@ -278,7 +278,7 @@ class Application: def _action_buildenvscript(self, args): self._entrypoint_debug(args) - targets = Targets() + targets = Targets(args.data_dir) packages = Packages(args.data_dir) projects = Projects(args.data_dir) projects_expanded = projects.expand_names(args.projects) @@ -300,7 +300,7 @@ class Application: if args.base_dir is not None: base_path = Path(args.base_dir) ci_path = Path(args.ci_dir) - targets = Targets() + targets = Targets(args.data_dir) packages = Packages(args.data_dir) projects = Projects(args.data_dir) manifest = Manifest(targets, packages, projects, args.manifest, args.quiet, ci_path, base_path) diff --git a/lcitool/targets.py b/lcitool/targets.py index 1bbd253..3d380a6 100644 --- a/lcitool/targets.py +++ b/lcitool/targets.py @@ -52,18 +52,17 @@ class Targets(): def _load_target_facts(self): facts = {} all_targets = {item.stem - for item in self._data_dir.list_files("facts/targets", ".yml", - internal=True)} + for item in self._data_dir.list_files("facts/targets", ".yml")} # first load the shared facts from targets/all.yml - shared_facts = self._data_dir.load_yaml("facts/targets", "all") + shared_facts = self._data_dir.merge_facts("facts/targets", "all") # then load the rest of the facts for target in all_targets: if target == "all": continue - facts[target] = self._data_dir.load_yaml("facts/targets", target) + facts[target] = self._data_dir.merge_facts("facts/targets", target) self._validate_target_facts(facts[target], target) facts[target]["target"] = target diff --git a/lcitool/util.py b/lcitool/util.py index 9a899ba..da7fc8b 100644 --- a/lcitool/util.py +++ b/lcitool/util.py @@ -253,15 +253,6 @@ class DataDir: if file.is_file() and (suffix is None or file.suffix == suffix): yield file - def load_yaml(self, resource_path, name): - file = Path(resource_filename(__name__, resource_path), name + ".yml") - if not file.exists(): - return {} - - log.debug(f"Loading facts from '{file}'") - with open(file, "r") as infile: - return yaml.safe_load(infile) - def merge_facts(self, resource_path, name): result = {} for file in self._search(resource_path, name + ".yml"): diff --git a/tests/data/targets/override/targets/centos-stream-8.yml b/tests/data/targets/override/targets/centos-stream-8.yml new file mode 100644 index 0000000..6b11160 --- /dev/null +++ b/tests/data/targets/override/targets/centos-stream-8.yml @@ -0,0 +1,3 @@ +paths: + pip3: /usr/bin/pip3.8 + python: /usr/bin/python3.8 diff --git a/tests/test_targets.py b/tests/test_targets.py index 61985f7..9a76fc1 100644 --- a/tests/test_targets.py +++ b/tests/test_targets.py @@ -4,9 +4,14 @@ # # SPDX-License-Identifier: GPL-2.0-or-later +from pathlib import Path import pytest +from lcitool.targets import Targets +from lcitool.util import DataDir + from conftest import ALL_TARGETS +import test_utils.utils as test_utils @pytest.mark.parametrize("target", ALL_TARGETS) @@ -32,3 +37,12 @@ def test_group_vars(targets, target): assert facts["target"] == target assert facts["os"]["name"] == target_osname_map[target_os] assert facts["os"]["version"] == target_version.capitalize() + + +def test_override(): + datadir = DataDir(Path(test_utils.test_data_dir(__file__), 'override')) + targets = Targets(datadir) + facts = targets.target_facts['centos-stream-8'] + + assert facts["paths"]["pip3"] == "/usr/bin/pip3.8" + assert facts["paths"]["python"] == "/usr/bin/python3.8" |