Skip to content

Commit

Permalink
store entire response on push
Browse files Browse the repository at this point in the history
Signed-off-by: Isabella do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Oct 25, 2024
1 parent a2b7a89 commit cc14598
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
14 changes: 3 additions & 11 deletions omlmd/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def download_file(uri: str):

@dataclass
class Helper:
_registry: OMLMDRegistry = (
field( # TODO: this is a bit limiting when used from CLI, to be refactored
default_factory=lambda: OMLMDRegistry(insecure=True)
)
_registry: OMLMDRegistry = field(
default_factory=lambda: OMLMDRegistry(insecure=True)
)
_listeners: list[Listener] = field(default_factory=list)

Expand Down Expand Up @@ -89,13 +87,7 @@ def push(
manifest_config=manifest_cfg,
do_chunked=True,
)
self.notify_listeners(
PushEvent(
result.headers["Docker-Content-Digest"],
target,
model_metadata,
)
)
self.notify_listeners(PushEvent(result, target, model_metadata))
return result
finally:
if owns_meta_files:
Expand Down
11 changes: 10 additions & 1 deletion omlmd/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass

import requests

from .model_metadata import ModelMetadata


Expand All @@ -26,6 +28,13 @@ class Event(ABC):

@dataclass
class PushEvent(Event):
digest: str
response: requests.Response
target: str
metadata: ModelMetadata

@property
def ok(self) -> bool:
return self.response.status_code == 200

def get_digest(self) -> str:
return self.response.headers["Docker-Content-Digest"] if self.ok else ""
4 changes: 2 additions & 2 deletions tests/test_e2e_model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ListenerForModelRegistry(Listener):

def update(self, source: Helper, event: Event) -> None:
if isinstance(event, PushEvent):
self.sha = event.digest
self.rm = from_oci_to_kfmr(model_registry, event, event.digest)
self.sha = event.get_digest()
self.rm = from_oci_to_kfmr(model_registry, event, self.sha)

listener = ListenerForModelRegistry()
omlmd = Helper()
Expand Down

0 comments on commit cc14598

Please sign in to comment.