Skip to content

Commit

Permalink
Merge pull request #408 from milanbalazs/main
Browse files Browse the repository at this point in the history
Fix the locally non-existent image fails with AttributeError
  • Loading branch information
openshift-merge-bot[bot] authored Jul 24, 2024
2 parents 12c877d + 281508b commit 35777ad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion podman/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def from_env(
@cached_property
def containers(self) -> ContainersManager:
"""Returns Manager for operations on containers stored by a Podman service."""
return ContainersManager(client=self.api)
return ContainersManager(client=self.api, podman_client=self)

@cached_property
def images(self) -> ImagesManager:
Expand Down
2 changes: 1 addition & 1 deletion podman/domain/containers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get(self, key: str) -> Container:
"""Get container by name or id.
Args:
container_id: Container name or id.
key: Container name or id.
Returns:
A `Container` object corresponding to `key`.
Expand Down
2 changes: 1 addition & 1 deletion podman/domain/containers_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(
try:
container = self.create(image=image, command=command, **kwargs)
except ImageNotFound:
self.client.images.pull(image, platform=kwargs.get("platform"))
self.podman_client.images.pull(image, platform=kwargs.get("platform"))
container = self.create(image=image, command=command, **kwargs)

container.start()
Expand Down
3 changes: 2 additions & 1 deletion podman/domain/images_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def pull(
else:
params["reference"] = f"{repository}:{tag}"

if "platform" in kwargs:
# Check if "platform" in kwargs AND it has value.
if "platform" in kwargs and kwargs["platform"]:
tokens = kwargs.get("platform").split("/")
if 1 < len(tokens) > 3:
raise ValueError(f'\'{kwargs.get("platform")}\' is not a legal platform.')
Expand Down
14 changes: 12 additions & 2 deletions podman/domain/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ def __init__(
attrs: Optional[Mapping[str, Any]] = None,
client: Optional[APIClient] = None,
collection: Optional["Manager"] = None,
podman_client: Optional["PodmanClient"] = None,
):
"""Initialize base class for PodmanResource's.
Args:
attrs: Mapping of attributes for resource from Podman service.
client: Configured connection to a Podman service.
collection: Manager of this category of resource, named `collection` for compatibility
podman_client: PodmanClient() configured to connect to Podman object.
"""
super().__init__()
self.client = client
self.manager = collection
self.podman_client = podman_client

self.attrs = {}
if attrs is not None:
Expand Down Expand Up @@ -77,14 +80,18 @@ class Manager(ABC):
def resource(self):
"""Type[PodmanResource]: Class which the factory method prepare_model() will use."""

def __init__(self, client: APIClient = None) -> None:
def __init__(
self, client: Optional[APIClient] = None, podman_client: Optional["PodmanClient"] = None
) -> None:
"""Initialize Manager() object.
Args:
client: APIClient() configured to connect to Podman service.
podman_client: PodmanClient() configured to connect to Podman object.
"""
super().__init__()
self.client = client
self.podman_client = podman_client

@abstractmethod
def exists(self, key: str) -> bool:
Expand All @@ -110,14 +117,17 @@ def prepare_model(self, attrs: Union[PodmanResource, Mapping[str, Any]]) -> Podm
# Refresh existing PodmanResource.
if isinstance(attrs, PodmanResource):
attrs.client = self.client
attrs.podman_client = self.podman_client
attrs.collection = self
return attrs

# Instantiate new PodmanResource from Mapping[str, Any]
if isinstance(attrs, abc.Mapping):
# TODO Determine why pylint is reporting typing.Type not callable
# pylint: disable=not-callable
return self.resource(attrs=attrs, client=self.client, collection=self)
return self.resource(
attrs=attrs, client=self.client, podman_client=self.podman_client, collection=self
)

# pylint: disable=broad-exception-raised
raise Exception(f"Can't create {self.resource.__name__} from {attrs}")

0 comments on commit 35777ad

Please sign in to comment.