Skip to content

Commit

Permalink
chore(RHTAPWATCH-662): add inputs to odcs compose entrypoint
Browse files Browse the repository at this point in the history
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
yftacherzog committed Dec 10, 2023
1 parent 8831254 commit b8aadaa
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
checks: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install pipenv
Expand Down
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ black = "*"
mypy = "*"
pylint = "*"
isort = "*"
pyyaml = "*"
types-pyyaml = "*"

[dev-packages]

[requires]
python_version = "3.11"
python_full_version = "3.11.6"
67 changes: 65 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions compose_generator/odcs_compose_generator.py

This file was deleted.

2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -ex

main() {
local pkgs=("tests" "compose_generator")
local pkgs=("tests" "generate_compose")
pipenv run isort --profile black "${pkgs[@]}"
pipenv run black "${pkgs[@]}"
}
Expand Down
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions generate_compose/odcs_compose_generator.py
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Fetch ready ODCS compose"""
from dataclasses import dataclass
from pathlib import Path
from typing import Optional

from .protocols import ComposeFetcher, ComposeReference

Expand All @@ -20,5 +21,7 @@ class ODCSFetcher(ComposeFetcher):
Fetch ODCS compose based on a remote compose-reference and store it locally
"""

compose_path: Optional[Path]

def __call__(self, request_reference: ComposeReference) -> ODCSResultReference:
raise NotImplementedError()
File renamed without changes.
File renamed without changes.
135 changes: 135 additions & 0 deletions tests/test_odcs_compose_generator.py
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()
2 changes: 1 addition & 1 deletion tests/test_static_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from subprocess import run
from typing import Final

PKGS: Final[list[str]] = ["tests", "compose_generator"]
PKGS: Final[list[str]] = ["tests", "generate_compose"]


def test_mypy() -> None:
Expand Down

0 comments on commit b8aadaa

Please sign in to comment.