Skip to content

Commit

Permalink
Merge pull request #554 from simondeziel/old-fixed-issues
Browse files Browse the repository at this point in the history
Update code for fixed issues in LXD
  • Loading branch information
tomponline committed Jul 13, 2023
2 parents fd70a6d + 2a6c7fe commit 796f3f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
5 changes: 1 addition & 4 deletions doc/source/instances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ us to use our own namespacing).
A instance object (returned by `get` or `all`) has the following methods:

- `rename` - rename a snapshot
- `publish` - create an image from a snapshot. However, this may fail if the
image from the snapshot is bigger than the logical volume that is allocated
by lxc. See https://github.com/canonical/lxd/issues/2201 for more details. The solution
is to increase the `storage.lvm_volume_size` parameter in lxc.
- `publish` - create an image from a snapshot.
- `restore` - restore the instance to this snapshot.

.. code-block:: python
Expand Down
19 changes: 9 additions & 10 deletions integration/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_put(self):

storage_pool = self.client.storage_pools.get(name)
new_desc = "new description"
self.assertNotEqual(storage_pool.description, new_desc)
put_object = {
"description": new_desc,
"config": storage_pool.config,
Expand All @@ -92,22 +93,20 @@ def test_put(self):
p = self.client.storage_pools.get(name)
self.assertEqual(p.description, new_desc)

# can't test this as patch doesn't seem to work for storage pools.
# Need to wait until bug: https://github.com/canonical/lxd/issues/4709
# fix is released.
@unittest.skip("Can't test until fix to lxd bug #4709 is released")
def test_patch(self):
name = self.create_storage_pool()
self.addCleanup(self.delete_storage_pool, name)

desc = "My storage pool"
storage_pool = self.client.storage_pools.get(name)
patch = {"description": "hello world"}
storage_pool.patch(patch)
self.assertEqual(storage_pool.description, desc)

new_desc = "new description"
self.assertNotEqual(storage_pool.description, new_desc)
patch_object = {
"description": new_desc,
}
storage_pool.patch(patch_object)
self.assertEqual(storage_pool.description, new_desc)
p = self.client.storage_pools.get(name)
self.assertEqual(p.description, "hello world")
self.assertEqual(p.description, new_desc)


class TestStorageResources(StorageTestCase):
Expand Down
20 changes: 9 additions & 11 deletions pylxd/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,22 @@ def get(cls, client, name):
def all(cls, client, recursion=0):
"""Get all instances.
This method returns an Instance array. If recursion is unset,
only the name of each instance will be set and `Instance.sync`
can be used to return more information. If recursion is between
1-2 this method will pre-fetch additional instance attributes for
This method returns an Instance array. If recursion is unset,
only the name of each instance will be set and `Instance.sync`
can be used to return more information. If recursion is between
1-2 this method will pre-fetch additional instance attributes for
all instances in the array.
"""
response = client.api[cls._endpoint].get(params={'recursion': recursion})
params = {}
if recursion != 0:
params = {"recursion": recursion}
response = client.api[cls._endpoint].get(params=params)

instances = []
for instance in response.json()["metadata"]:
if type(instance) == dict:
# User specified recursion so returning all data for each instance at once
instance_class = cls(client, name=instance['name'])
instance_class = cls(client, name=instance["name"])
for key, data in instance.items():
try:
setattr(instance_class, key, data)
Expand Down Expand Up @@ -862,11 +865,6 @@ def publish(self, public=False, wait=False):
"""Publish a snapshot as an image.
If wait=True, an Image is returned.
This functionality is currently broken in LXD. Please see
https://github.com/canonical/lxd/issues/2201 - The implementation
here is mostly a guess. Once that bug is fixed, we can verify
that this works, or file a bug to fix it appropriately.
"""
data = {
"public": public,
Expand Down

0 comments on commit 796f3f3

Please sign in to comment.