-
Notifications
You must be signed in to change notification settings - Fork 119
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
Enhancement request: access virtual filesystem in the test module #931
Comments
This is a good idea, I think we just need to come up with an appropriate API for it. What about a new harness = Harness(MyCharm)
with harness.connected_container(FLASK_CONTAINER_NAME) as container:
container.make_dir("/srv/flask", make_parents=True)
container.push(...)
container.push_path(...) The yielded I've added the 23.10 label to this one. It's not on our roadmap but if we can get agreement on the API it's small enough to sneak in. Thoughts, @PietroPasotti? (Though of course you're going to say "this problem is already solved in ops-scenario". :-) |
Yes, this looks good. Thanks! |
@weiiwang01 If you'd like to open a PR for this, go right ahead. Otherwise I'll try to get to it in the next few weeks. |
No problem, I will create a PR shortly. |
Well of course if you used scenario this wouldn't be an issue, but I think the solution proposed by Ben above is good. with h.connected_container(foo, False):
with assert_raises(SomeError):
h.charm.do_something_you_can_only_do_if_container_can_connect()
with h.connected_container(foo, True):
h.charm.do_something_you_can_only_do_if_container_can_connect() WDYT @weiiwang01 @benhoyt |
Yes, that could totally work. However, in my opinion, this helper function seems to be designed for test setup, asserting, and similar tasks. When it comes to running charm code, I think the current |
I'm more of a mind of exposing a |
Thanks @jameinel. Just for the record, John also suggested, if we do end up going the |
How about implementing a method called Implementing this feature should be relatively straightforward with a proxy class. |
I'm in favor of something to that effect, as a nice way to set the
"ecosystem" around the charm.
John
=:->
…On Wed, May 17, 2023 at 11:44 PM Weii Wang ***@***.***> wrote:
How about implementing a method called
Harness.get_container_filesystem(container)? This method would return a
ContainerFsFacade object, and only contains filesystem-related methods
such as push, pull, list_files, push_path, etc and its access would
always be permitted and unaffected by set_can_connect. The
ContainerFsFacade would provide a familiar interface for setting up the
container filesystem in tests while not being able to affect charm code.
Implementing this feature should be relatively straightforward with a
proxy class.
—
Reply to this email directly, view it on GitHub
<#931 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABRQ7KUM7VSEG5KTECVZ4LXGWLI7ANCNFSM6AAAAAAYCCYUXI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yeah, that sounds reasonable to me, too -- given that the interface will be the same as the existing FS methods, we're not (excatly) introducing swaths of brand new public API. @weiiwang01 If you're still game, go ahead and submit a PR for something like that, and then we'll refine it from there. |
Pull request created #933 |
Per discussion and per @weiiwang01's OP036 spec, we're going to change our testing approach here to use a temp directory on the real filesystem. |
This is solved with the addition of |
Currently, the testing module of the operator framework includes a mock filesystem for the pebble-controlled container. However, the mock filesystem is initially empty, which differs from real-world scenarios where OCI images already contain numerous files and directories (e.g., /etc, /srv) that the charm relies on during execution.
Presently, we rely on the
Harness.model.unit.get_container
method to obtain the test pebble client before starting the test case and prime the mock filesystem with the necessary charm files. However, this approach presents a problem. The test pebble client obtained using this method is guarded byset_can_connect
, requiring us to make the container connectable before adding files and directories to the mock filesystem. This could interfere with the actual test cases, since the connectable state is persisted until the harness is destroyed.https://github.com/canonical/flask-k8s-operator/blob/979f3aaf0b8f120a874d1ad9f039983b7ffc37eb/tests/unit/conftest.py#L74-L77
It would be great if the harness provided an API to access an unrestricted simulated container, not protected by set_can_connect. This container would be used exclusively by the test code for priming, inspecting the mock filesystem, and other similar operations. It will not be used by the charm code.
The text was updated successfully, but these errors were encountered: