-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from 7 commits
b55d152
cad6ced
31dec93
8dba6f1
769ab33
15856ba
61a75cb
982db23
d1b54b0
c6d5a69
c4274b8
62f9d3c
d7c7996
b1dcdf9
66d5008
ce2330a
5312f01
a14cdfd
01023e6
806e730
2f3555b
f3473eb
72a61bb
4c97da5
eabfe48
8709e37
365285a
80292a1
9b43c78
996ac61
fb0d3a1
f54055f
11e554c
41bb355
9eaff75
2bd4b54
282731b
a05205b
8ed15f7
56b5f59
1fbd9c9
bc4671e
4d56ad2
a86e514
b4e2d73
c861774
4c23b11
fbec8f4
b6bf5a9
2c11855
50623c3
defcafb
4157805
ce6ca72
d730a1b
bab6f27
3ecd993
7bd99e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
""" | ||
|
@@ -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 | ||
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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 | ||
|
||
|
@@ -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. | ||
|
There was a problem hiding this comment.
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 asabstractmethod
because that requires concrete classes to override them. We want their default behavior to be a NOOP, don't we?There was a problem hiding this comment.
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