-
Notifications
You must be signed in to change notification settings - Fork 138
pylxd/models/instance: Support selective state recursion in Instance.all() #707
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
Open
gajeshbhat
wants to merge
6
commits into
canonical:main
Choose a base branch
from
gajeshbhat:feature/instances-state-selective-recursion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+349
−5
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17436df
CONTRIBUTORS: Add Gajesh Bhat
gajeshbhat c83f00e
doc/source/instances: Drop trailing whitespace
gajeshbhat d79a8b9
pylxd/models/instance: Support selective state recursion in Instance.…
gajeshbhat 15e4b92
pylxd/models/tests/test_instance: Add tests for selective state recur…
gajeshbhat ddf2583
doc/source/instances: Document selective state recursion in Instance.…
gajeshbhat 89442a1
integration/test_instances: Add integration tests for Instance.all()
gajeshbhat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Copyright (c) 2016 Canonical Ltd | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from integration.testing import IntegrationTestCase | ||
|
|
||
|
|
||
| class TestInstances(IntegrationTestCase): | ||
| """Tests for `Client.instances`.""" | ||
|
|
||
| def test_get(self): | ||
| """An instance is fetched by name.""" | ||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instance = self.client.instances.get(name) | ||
|
|
||
| self.assertEqual(name, instance.name) | ||
|
|
||
| def test_all(self): | ||
| """A list of all instances is returned.""" | ||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all() | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_recursion_1(self): | ||
| """A list of instances with basic attributes is returned.""" | ||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all(recursion=1) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_recursion_2(self): | ||
| """A list of instances with full state is returned at recursion=2.""" | ||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all(recursion=2) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_selective_recursion_disk(self): | ||
| """Selective recursion with state.disk returns instances correctly. | ||
| Requires the ``instances_state_selective_recursion`` LXD API | ||
| extension. The test is skipped if the extension is not present. | ||
| """ | ||
| if not self.client.has_api_extension("instances_state_selective_recursion"): | ||
| self.skipTest("instances_state_selective_recursion extension not available") | ||
|
|
||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all(recursion=2, fields=["state.disk"]) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_selective_recursion_multiple_fields(self): | ||
| """Selective recursion with multiple fields returns instances correctly. | ||
| Requires the ``instances_state_selective_recursion`` LXD API | ||
| extension. The test is skipped if the extension is not present. | ||
| """ | ||
| if not self.client.has_api_extension("instances_state_selective_recursion"): | ||
| self.skipTest("instances_state_selective_recursion extension not available") | ||
|
|
||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all( | ||
| recursion=2, fields=["state.disk", "state.network"] | ||
| ) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_selective_recursion_empty_fields(self): | ||
| """Selective recursion with empty fields list suppresses all state. | ||
| Requires the ``instances_state_selective_recursion`` LXD API | ||
| extension. The test is skipped if the extension is not present. | ||
| """ | ||
| if not self.client.has_api_extension("instances_state_selective_recursion"): | ||
| self.skipTest("instances_state_selective_recursion extension not available") | ||
|
|
||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| instances = self.client.instances.all(recursion=2, fields=[]) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) | ||
|
|
||
| def test_all_selective_recursion_fallback(self): | ||
| """When the extension is absent, fields is ignored and all() succeeds. | ||
| This verifies the graceful-fallback path: passing ``fields`` on a | ||
| server that does not advertise the extension must not raise and must | ||
| still return the full instance list. | ||
| """ | ||
| if self.client.has_api_extension("instances_state_selective_recursion"): | ||
| self.skipTest( | ||
| "Server has the extension; fallback path cannot be tested here" | ||
| ) | ||
|
|
||
| name = self.create_container() | ||
| self.addCleanup(self.delete_container, name) | ||
|
|
||
| # Should fall back to plain recursion=2 without raising. | ||
| instances = self.client.instances.all(recursion=2, fields=["state.disk"]) | ||
|
|
||
| self.assertIn(name, [i.name for i in instances]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.