-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(RHTAPWATCH-662): add inputs to odcs compose entrypoint
Required inputs when running the odcs entrypoint to specify where the compose should be stored and where the configurations reside. Had to rename the directory name to avoid it having the same name as one of the the modules. Signed-off-by: Yftach Herzog <[email protected]>
- Loading branch information
1 parent
8831254
commit b8aadaa
Showing
14 changed files
with
268 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Initialize and use a compose generator using ODCS""" | ||
|
||
from pathlib import Path | ||
|
||
import click | ||
import yaml | ||
|
||
from .compose_generator import ComposeGenerator | ||
from .odcs_configurations_generator import ODCSConfigurationsGenerator | ||
from .odcs_fetcher import ODCSFetcher | ||
from .odcs_requester import ODCSRequester | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--compose-path", | ||
help="Path to where the compose should be saved.", | ||
type=click.Path(path_type=Path), | ||
required=True, | ||
) | ||
@click.option( | ||
"--container-yaml-path", | ||
help="Path in which container yaml file is stored", | ||
type=click.Path(path_type=Path), | ||
required=True, | ||
) | ||
@click.option( | ||
"--content-sets-yaml-path", | ||
help="Path in which content_sets yaml file is stored", | ||
type=click.Path(path_type=Path), | ||
required=True, | ||
) | ||
def main( | ||
compose_path: Path, | ||
container_yaml_path: Path, | ||
content_sets_yaml_path: Path, | ||
): | ||
""" | ||
Get inputs from container and content_sets yamls and relay them to an ODCS | ||
compose generator that will request a compose and store it in a TBD location. | ||
""" | ||
container_data: dict = yaml.safe_load(container_yaml_path.read_text()) | ||
content_sets_data: dict = yaml.safe_load(content_sets_yaml_path.read_text()) | ||
|
||
compose_generator = ComposeGenerator( | ||
configurations_generator=ODCSConfigurationsGenerator( | ||
container_data=container_data, | ||
content_sets_data=content_sets_data, | ||
), | ||
requestor=ODCSRequester(), | ||
fetcher=ODCSFetcher(compose_path=compose_path), | ||
) | ||
compose_generator() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() # pylint: disable=no-value-for-parameter |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
"""Test odcs_compose_generator.py end-to-end""" | ||
from pathlib import Path | ||
from unittest.mock import MagicMock, create_autospec | ||
|
||
import pytest | ||
import yaml | ||
from pytest import MonkeyPatch | ||
|
||
from generate_compose import odcs_compose_generator | ||
from generate_compose.compose_generator import ComposeGenerator | ||
from generate_compose.odcs_configurations_generator import ODCSConfigurationsGenerator | ||
from generate_compose.odcs_fetcher import ODCSFetcher | ||
from generate_compose.odcs_requester import ODCSRequester | ||
|
||
|
||
class TestODCSComposeGenerator: | ||
"""Test odcs_compose_generator.py end-to-end""" | ||
|
||
@pytest.fixture() | ||
def container_data(self) -> dict: | ||
"""container.yaml content""" | ||
return { | ||
"compose": {"pulp_repos": True, "signing_intent": "release"}, | ||
"image_build_method": "imagebuilder", | ||
"remote_source": { | ||
"pkg_managers": [], | ||
"ref": "f6ceb2ff45a71938f6949abcd15aa0a1b0f79842", | ||
"repo": "https://github.com/kubevirt/must-gather", | ||
}, | ||
} | ||
|
||
@pytest.fixture() | ||
def container_yaml(self, container_data: dict, tmp_path: Path) -> Path: | ||
"""path to container.yaml with content""" | ||
path = tmp_path / "container.yaml" | ||
with path.open("w") as file: | ||
yaml.dump(container_data, file) | ||
return path | ||
|
||
@pytest.fixture() | ||
def content_sets_data(self) -> dict: | ||
"""content_sets.yaml content""" | ||
return { | ||
"x86_64": [ | ||
"rhel-8-for-x86_64-baseos-eus-rpms__8_DOT_6", | ||
"rhel-8-for-x86_64-appstream-eus-rpms__8_DOT_6", | ||
], | ||
"aarch64": [ | ||
"rhel-8-for-aarch64-baseos-eus-rpms__8_DOT_6", | ||
"rhel-8-for-aarch64-appstream-eus-rpms__8_DOT_6", | ||
], | ||
} | ||
|
||
@pytest.fixture() | ||
def content_sets_yaml(self, content_sets_data: dict, tmp_path: Path) -> Path: | ||
"""path to content_sets.yaml with content""" | ||
path = tmp_path / "content_sets.yml" | ||
with path.open("w") as file: | ||
yaml.dump(content_sets_data, file) | ||
return path | ||
|
||
@pytest.fixture() | ||
def compose_path(self, tmp_path: Path) -> Path: | ||
"""Path to where the compose should be stored""" | ||
return tmp_path / "repofile.repo" | ||
|
||
@pytest.fixture() | ||
def mock_config_generator(self, monkeypatch: MonkeyPatch) -> MagicMock: | ||
"""Monkey-patched ODCSConfigurationsGenerator""" | ||
mock: MagicMock = create_autospec( | ||
ODCSConfigurationsGenerator, | ||
return_value=create_autospec(ODCSConfigurationsGenerator, instance=True), | ||
) | ||
monkeypatch.setattr( | ||
odcs_compose_generator, ODCSConfigurationsGenerator.__name__, mock | ||
) | ||
return mock | ||
|
||
@pytest.fixture() | ||
def mock_compose_generator(self, monkeypatch: MonkeyPatch) -> MagicMock: | ||
"""Monkey-patched ComposeGenerator""" | ||
mock: MagicMock = create_autospec(ComposeGenerator) | ||
monkeypatch.setattr(odcs_compose_generator, ComposeGenerator.__name__, mock) | ||
return mock | ||
|
||
@pytest.fixture() | ||
def mock_requester(self, monkeypatch: MonkeyPatch) -> MagicMock: | ||
"""Monkey-patched ODCSRequester""" | ||
mock: MagicMock = create_autospec(ODCSRequester) | ||
monkeypatch.setattr(odcs_compose_generator, ODCSRequester.__name__, mock) | ||
return mock | ||
|
||
@pytest.fixture() | ||
def mock_fetcher(self, monkeypatch: MonkeyPatch) -> MagicMock: | ||
"""Monkey-patched ODCSFetcher""" | ||
mock: MagicMock = create_autospec(ODCSFetcher) | ||
monkeypatch.setattr(odcs_compose_generator, ODCSFetcher.__name__, mock) | ||
return mock | ||
|
||
def test_main( # pylint: disable=too-many-arguments | ||
self, | ||
compose_path: Path, | ||
container_data: dict, | ||
container_yaml: Path, | ||
content_sets_data: dict, | ||
content_sets_yaml: Path, | ||
mock_compose_generator: MagicMock, | ||
mock_config_generator: MagicMock, | ||
mock_requester: MagicMock, | ||
mock_fetcher: MagicMock, | ||
) -> None: | ||
"""Test call to odcs_compose_generator.py main function""" | ||
odcs_compose_generator.main( # pylint: disable=no-value-for-parameter | ||
args=[ | ||
"--compose-path", | ||
str(compose_path), | ||
"--container-yaml-path", | ||
str(container_yaml), | ||
"--content-sets-yaml-path", | ||
str(content_sets_yaml), | ||
], | ||
obj={}, | ||
standalone_mode=False, | ||
) | ||
|
||
mock_config_generator.assert_called_once_with( | ||
container_data=container_data, content_sets_data=content_sets_data | ||
) | ||
mock_fetcher.assert_called_once_with(compose_path=compose_path) | ||
mock_compose_generator.assert_called_once_with( | ||
configurations_generator=mock_config_generator.return_value, | ||
requestor=mock_requester.return_value, | ||
fetcher=mock_fetcher.return_value, | ||
) | ||
mock_compose_generator.return_value.assert_called_once_with() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters