-
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
Conversation
src/inmanta/agent/handler.py
Outdated
@@ -793,7 +823,7 @@ def call() -> typing.Awaitable[Result]: | |||
|
|||
|
|||
@stable_api | |||
class CRUDHandler(ResourceHandler): | |||
class CRUDHandler(ResourceHandler, HandlerABC): |
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.
Shouldn't ResourceHandler
just inherit from HandlerABC
instead?
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 guess you mean CRUDHandler
? This would mean we need to lift some functionality from ResourceHandler to HandlerABC ?
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.
No, I mean ResourceHandler
. If it inherits from HandlerABC
, CRUDHandler
doesn't need to. Now we have
class HandlerABC: pass
class ResourceHandler: pass
class CRUDHandler(ResourceHandler, HandlerABC): pass
and I'm proposing
class HandlerABC: pass
class ResourceHandler(HandlerABC): pass
class CRUDHandler(ResourceHandler): pass
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.
My first snippet is not right. Not sure if you changed it or I saw it wrong. Anyway, if ResourceHandler(HandlerABC)
, why would we explicitly inherit from it in CRUDHandler
?
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.
Right, 100% agree
src/inmanta/agent/handler.py
Outdated
@@ -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 provides an implementation for. # TODO rephrase 'provides an implementation for' |
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.
Don't forget about this TODO
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.
Not sure I can contribute here. I a missing missing the point on what the goal of this refactor is.
src/inmanta/agent/handler.py
Outdated
:param resource: The resource to query facts for. | ||
""" | ||
|
||
@abstractmethod |
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 as abstractmethod
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
""" | ||
|
||
def __init__(self, agent: "inmanta.agent.agent.AgentInstance", io: Optional["IOBase"] = None) -> None: | ||
self._agent = agent |
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.
Shouldn't we call super here instead of setting self._agent
, self._ioloop
and self._client
directly?
src/inmanta/agent/handler.py
Outdated
requires: Dict[ResourceIdStr, ResourceState], | ||
) -> None: | ||
""" | ||
Main entrypoint of the handler that will be called by the agent. |
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.
This docstring doesn't really describe the behavior of the method.
src/inmanta/agent/handler.py
Outdated
@stable_api | ||
class ResourceHandler(HandlerABC): | ||
""" | ||
A baseclass for classes that handle resources. New handler are registered with the |
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.
The part about handler registration seems relevant for the top level ABC as well.
src/inmanta/agent/handler.py
Outdated
self, | ||
ctx: HandlerContext, | ||
resource: R, | ||
requires: Dict[ResourceIdStr, ResourceState], |
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 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?
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 we ever update it.
src/inmanta/agent/handler.py
Outdated
:return: A client that is associated with the session of the agent that executes this handler. | ||
""" | ||
if self._client is None: | ||
self._client = protocol.SessionClient("agent", self._agent.sessionid) | ||
return self._client | ||
|
||
|
||
@stable_api | ||
class ResourceHandler(HandlerABC): |
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.
class ResourceHandler(HandlerABC): | |
class ResourceHandler(HandlerABC[R]): |
I think. Then update all type annotations of resources.Resource
to R
instead. Same for the CRUDHandler
.
Co-authored-by: arnaudsjs <[email protected]>
…t-top-level-handler-ABC' into issue/6025-implement-top-level-handler-ABC
Co-authored-by: Sander Van Balen <[email protected]>
Co-authored-by: Sander Van Balen <[email protected]>
Co-authored-by: Sander Van Balen <[email protected]>
Co-authored-by: Sander Van Balen <[email protected]>
Co-authored-by: Sander Van Balen <[email protected]>
Co-authored-by: Sander Van Balen <[email protected]>
Regarding the typing issue on |
@sanderr I still have the following type error left:
I don't really see how that can be fixed. |
Processing this pull request |
Pull request rejected by merge tool. This pull request has not been approved yet. |
Sander is out of office for several says
Processing this pull request |
Merged into branches master in 4ffeafa |
…rce handlers generic in their resource type. (Issue #6025, PR #6246) # Description Part of #6025 # Self Check: Strike through any lines that are not applicable (`~~line~~`) then check the box - [ ] Attached issue to pull request - [ ] Changelog entry - [ ] Type annotations are present - [ ] Code is clear and sufficiently documented - [ ] No (preventable) type errors (check using make mypy or make mypy-diff) - [ ] Sufficient test cases (reproduces the bug/tests the requested feature) - [ ] Correct, in line with design - [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: ) - [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
Description
Part of #6025
Self Check:
Strike through any lines that are not applicable (
~~line~~
) then check the box