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

Issue/6025 implement top level handler abc #6246

Closed
wants to merge 58 commits into from
Closed
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b55d152
[WIP]
Hugo-Inmanta Jul 7, 2023
cad6ced
[FIX] fix broken anchor in link
Hugo-Inmanta Jul 7, 2023
31dec93
[WIP]
Hugo-Inmanta Jul 7, 2023
8dba6f1
[WIP] Implement top-level handler ABC
Hugo-Inmanta Jul 10, 2023
769ab33
[FIX] remove unrelated change
Hugo-Inmanta Jul 10, 2023
15856ba
[WIP]
Hugo-Inmanta Jul 11, 2023
61a75cb
[FIX]
Hugo-Inmanta Jul 12, 2023
982db23
Merge branch 'master' into issue/6025-implement-top-level-handler-ABC
Hugo-Inmanta Jul 19, 2023
d1b54b0
[FORMAT]
Hugo-Inmanta Jul 19, 2023
c6d5a69
[DOC] add changelog
Hugo-Inmanta Jul 19, 2023
c4274b8
[WIP]
Hugo-Inmanta Jul 19, 2023
62f9d3c
[FORMAT]
Hugo-Inmanta Jul 19, 2023
d7c7996
[WIP]
Hugo-Inmanta Jul 19, 2023
b1dcdf9
[WIP]
Hugo-Inmanta Jul 19, 2023
66d5008
Update src/inmanta/agent/handler.py
Hugo-Inmanta Jul 21, 2023
ce2330a
[WIP]
Hugo-Inmanta Jul 21, 2023
5312f01
Merge remote-tracking branch 'refs/remotes/origin/issue/6025-implemen…
Hugo-Inmanta Jul 21, 2023
a14cdfd
[WIP]
Hugo-Inmanta Jul 21, 2023
01023e6
[WIP]
Hugo-Inmanta Jul 24, 2023
806e730
proposal for handler api class
wouterdb Jul 31, 2023
2f3555b
Merge branch 'issue/handler_abc_wdb' into issue/6025-implement-top-le…
Hugo-Inmanta Aug 1, 2023
f3473eb
[WIP]
Hugo-Inmanta Aug 1, 2023
72a61bb
[WIP]
Hugo-Inmanta Aug 1, 2023
4c97da5
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 2, 2023
eabfe48
Update changelogs/unreleased/6025-implement-top-level-handler-abc.yml
Hugo-Inmanta Aug 2, 2023
8709e37
Apply suggestions from code review
Hugo-Inmanta Aug 3, 2023
365285a
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 3, 2023
80292a1
[WIP]
Hugo-Inmanta Aug 3, 2023
9b43c78
[WIP]
Hugo-Inmanta Aug 3, 2023
996ac61
[WIP]
Hugo-Inmanta Aug 3, 2023
fb0d3a1
Merge branch 'master' into issue/6025-implement-top-level-handler-ABC
Hugo-Inmanta Aug 3, 2023
f54055f
[WIP]
Hugo-Inmanta Aug 3, 2023
11e554c
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 3, 2023
41bb355
[FIX] unmark HandlerAPI as stableAPI
Hugo-Inmanta Aug 3, 2023
9eaff75
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 3, 2023
2bd4b54
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 3, 2023
282731b
[WIP]
Hugo-Inmanta Aug 3, 2023
a05205b
[WIP]
Hugo-Inmanta Aug 3, 2023
8ed15f7
[WIP]
Hugo-Inmanta Aug 3, 2023
56b5f59
[FIX] move following methods to utility section: pre, post, can_relo…
Hugo-Inmanta Aug 3, 2023
1fbd9c9
[FIX] move set_cache method to api section
Hugo-Inmanta Aug 3, 2023
bc4671e
Update src/inmanta/agent/handler.py
Hugo-Inmanta Aug 4, 2023
4d56ad2
[WIP] make top handler generic in its resource type
Hugo-Inmanta Aug 7, 2023
a86e514
Merge branch 'master' into issue/6025-implement-top-level-handler-ABC
Hugo-Inmanta Aug 7, 2023
b4e2d73
[WIP]
Hugo-Inmanta Aug 7, 2023
c861774
Update changelogs/unreleased/6025-implement-top-level-handler-abc.yml
arnaudsjs Aug 16, 2023
4c23b11
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
fbec8f4
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
b6bf5a9
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
2c11855
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
50623c3
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
defcafb
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
4157805
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
ce6ca72
Update src/inmanta/agent/handler.py
arnaudsjs Aug 16, 2023
d730a1b
Improve changelog entry
arnaudsjs Aug 16, 2023
bab6f27
Fix typing issues
arnaudsjs Aug 16, 2023
3ecd993
Merge branch 'master' into issue/6025-implement-top-level-handler-ABC
arnaudsjs Aug 16, 2023
7bd99e9
Fix type annotation in clone() method
arnaudsjs Aug 16, 2023
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
68 changes: 48 additions & 20 deletions src/inmanta/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class provider(object): # noqa: N801
"""
A decorator that registers a new handler.

:param resource_type: The type of the resource this handler provides an implementation for.
:param resource_type: The type of the resource this handler is responsible for.
For example, :inmanta:entity:`std::File`
:param name: A name to reference this provider.
"""
Expand Down Expand Up @@ -419,7 +419,52 @@ def _log_msg(self, level: int, msg: str, *args: object, exc_info: bool = False,


@stable_api
class ResourceHandler(object):
class HandlerABC(ABC):
"""
Top-level abstract base class all handlers should inherit from.
"""

@abstractmethod
def pre(self, ctx: HandlerContext, resource: resources.Resource) -> None:
"""
Method executed before a handler operation (Facts, dryrun, real deployment, ...) is executed. Override this method
to run before an operation.

:param ctx: Context object to report changes and logs to the agent and server.
:param resource: The resource to query facts for.
"""

@abstractmethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one or pre should be marked as abstractmethod because that requires concrete classes to override them. We want their default behavior to be a NOOP, don't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's the route I took on my PR implementing the DiscoveryHandler, I'll change it here as well

def post(self, ctx: HandlerContext, resource: resources.Resource) -> None:
"""
Method executed after an operation. Override this method to run after an operation.

:param ctx: Context object to report changes and logs to the agent and server.
:param resource: The resource to query facts for.
"""

@abstractmethod
def deploy(
sanderr marked this conversation as resolved.
Show resolved Hide resolved
self,
ctx: HandlerContext,
resource: resources.Resource,
requires: Dict[ResourceIdStr, ResourceState],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a good time to clean up this type. Either dict or abc.Mapping. Afaik we don't ever update it so Mapping would be best. @arnaudsjs do you know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever update it.

) -> None:
"""
This method is always called by the agent
"""
pass

@abstractmethod
def execute(self, ctx: HandlerContext, resource: resources.Resource, dry_run: Optional[bool] = None) -> None:
"""
Update the given resource. This method is called by the agent.
"""
pass
arnaudsjs marked this conversation as resolved.
Show resolved Hide resolved


@stable_api
class ResourceHandler(HandlerABC):
"""
A baseclass for classes that handle resources. New handler are registered with the
:func:`~inmanta.agent.handler.provider` decorator.
Expand Down Expand Up @@ -499,23 +544,6 @@ def do_reload(self, ctx: HandlerContext, resource: resources.Resource) -> None:
:param resource: The resource to reload.
"""

def pre(self, ctx: HandlerContext, resource: resources.Resource) -> None:
"""
Method executed before a handler operation (Facts, dryrun, real deployment, ...) is executed. Override this method
to run before an operation.

:param ctx: Context object to report changes and logs to the agent and server.
:param resource: The resource to query facts for.
"""

def post(self, ctx: HandlerContext, resource: resources.Resource) -> None:
"""
Method executed after an operation. Override this method to run after an operation.

:param ctx: Context object to report changes and logs to the agent and server.
:param resource: The resource to query facts for.
"""

def close(self) -> None:
pass

Expand Down Expand Up @@ -582,7 +610,7 @@ def deploy(
requires: Dict[ResourceIdStr, ResourceState],
) -> None:
"""
This method is always be called by the agent, even when one of the requires of the given resource
This method is always called by the agent, even when one of the requires of the given resource
failed to deploy. The default implementation of this method will deploy the given resource when all its
requires were deployed successfully. Override this method if a different condition determines whether the
resource should deploy.
Expand Down