Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(RHTAPWATCH-633): Generate ODCS configurations #30

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion generate_compose/compose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class ComposeGenerator:

def __call__(self) -> ODCSResultReference:
configs: ODCSComposesConfigs = self.configurations_generator()
request_reference: ODCSRequestReferences = self.requester(configs=configs)
request_reference: ODCSRequestReferences = self.requester(
compose_configs=configs
)
result_reference: ODCSResultReference = self.fetcher(
request_reference=request_reference
)
Expand Down
7 changes: 6 additions & 1 deletion generate_compose/odcs_configurations_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configurations generator for ODCS compose"""

from dataclasses import dataclass

from .protocols import ComposeConfigurationsGenerator, ODCSComposesConfigs
Expand All @@ -15,4 +16,8 @@ class ODCSConfigurationsGenerator(ComposeConfigurationsGenerator):
compose_inputs: dict

def __call__(self) -> ODCSComposesConfigs:
raise NotImplementedError()
"""Generate odcs configurations based on composes request information.

:returns: an odcs configuration.
"""
return ODCSComposesConfigs.from_list(self.compose_inputs["composes"])
14 changes: 9 additions & 5 deletions generate_compose/odcs_requester.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Request a new ODCS compose"""
from dataclasses import dataclass

from odcs.client.odcs import ODCS # type: ignore
from odcs.client.odcs import ODCS, AuthMech # type: ignore

from .odcs_configurations_generator import ODCSComposesConfigs
from .protocols import ComposeRequester, ODCSRequestReferences
Expand All @@ -14,16 +14,20 @@ class ODCSRequester(ComposeRequester):
to the remote compose location.
"""

odcs: ODCS = ODCS("https://odcs.engineering.redhat.com/")
odcs: ODCS = ODCS(
"https://odcs.engineering.redhat.com/", auth_mech=AuthMech.Kerberos
)

def __call__(self, compose_configs: ODCSComposesConfigs) -> ODCSRequestReferences:
composes = [
self.odcs.request_compose(config.spec, **config.additional_args)
for config in compose_configs.configs
]
for compose in composes:
self.odcs.wait_for_compose(compose["id"])

compose_urls = [compose["result_repofile"] for compose in composes]
finished_composes = [
self.odcs.wait_for_compose(compose["id"]) for compose in composes
]

compose_urls = [compose["result_repofile"] for compose in finished_composes]
req_refrences = ODCSRequestReferences(compose_urls=compose_urls)
return req_refrences
54 changes: 52 additions & 2 deletions generate_compose/protocols.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""compose generator protocols"""
from dataclasses import dataclass, field
from pathlib import Path
from typing import Protocol
from typing import ClassVar, Mapping, Protocol

from odcs.client.odcs import ComposeSourceGeneric # type: ignore
from odcs.client.odcs import (
ComposeSourceBuild,
ComposeSourceModule,
ComposeSourcePulp,
ComposeSourceRawConfig,
ComposeSourceTag,
)

# pylint: disable=too-few-public-methods

Expand All @@ -26,6 +33,49 @@ class ODCSComposesConfigs:

configs: list[ODCSComposeConfig]

kinds: ClassVar[Mapping] = {
"ComposeSourceBuild": ComposeSourceBuild,
"ComposeSourceModule": ComposeSourceModule,
"ComposeSourcePulp": ComposeSourcePulp,
"ComposeSourceRawConfig": ComposeSourceRawConfig,
"ComposeSourceTag": ComposeSourceTag,
}

@classmethod
def from_list(cls, input_configs: list) -> "ODCSComposesConfigs":
"""
Return an instance of the class given a configuration list extracted from
input config yaml.

yaml structure:
composes:
- kind: ComposeSourceTag
spec:
tag: some-tag
some-source-kw-arg: some-source-kw-value
additional_args:
some-additional-arg: some-additional-value

:param input_configs: configs extracted from yaml.
"""
configs = [
ODCSComposeConfig(
spec=cls.make_compose_config(entry["spec"], entry["kind"]),
additional_args=entry["additional_args"],
)
for entry in input_configs
]

return cls(configs)

@classmethod
def make_compose_config(cls, spec: dict, kind: str) -> ComposeSourceGeneric:
"""
Create an instance of ComposeSourceGeneric implementation given the class name
and the required inputs.
"""
return cls.kinds[kind](**spec)


class ComposeConfigurationsGenerator(Protocol):
"""
Expand Down Expand Up @@ -59,7 +109,7 @@ class ComposeRequester(Protocol):
Given compose configurations, return a remote compose reference
"""

def __call__(self, configs: ODCSComposesConfigs) -> ODCSRequestReferences:
def __call__(self, compose_configs: ODCSComposesConfigs) -> ODCSRequestReferences:
pass


Expand Down
2 changes: 1 addition & 1 deletion tests/test_compose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_compose_generator(

mock_config_generator.assert_called_once_with()
mock_requester.assert_called_once_with(
configs=mock_config_generator.return_value
compose_configs=mock_config_generator.return_value
)
mock_fetcher.assert_called_once_with(
request_reference=mock_requester.return_value
Expand Down
Loading