[lxc-devel] [pylxd/master] Fix integration tests
rockstar on Github
lxc-bot at linuxcontainers.org
Wed Jun 1 18:57:56 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1074 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160601/418af395/attachment.bin>
-------------- next part --------------
From 8ba6ece3b318bed204f15d8d6aff366b9ba5a662 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:10:45 -0600
Subject: [PATCH 1/6] Fix the container integration tests.
---
integration/test_containers.py | 9 ++++++---
integration/testing.py | 9 +++++++--
pylxd/container.py | 2 +-
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/integration/test_containers.py b/integration/test_containers.py
index cb0086d..43b5166 100644
--- a/integration/test_containers.py
+++ b/integration/test_containers.py
@@ -11,11 +11,13 @@
# 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 pylxd import exceptions
+
from integration.testing import IntegrationTestCase
class TestContainers(IntegrationTestCase):
- """Tests for `Client.containers`"""
+ """Tests for `Client.containers`."""
def test_get(self):
"""A container is fetched by name."""
@@ -38,6 +40,7 @@ def test_all(self):
def test_create(self):
"""Creates and returns a new container."""
+ _, alias = self.create_image()
config = {
'name': 'an-container',
'architecture': '2',
@@ -45,7 +48,7 @@ def test_create(self):
'ephemeral': True,
'config': {'limits.cpu': '2'},
'source': {'type': 'image',
- 'alias': 'busybox'},
+ 'alias': alias},
}
self.addCleanup(self.delete_container, config['name'])
@@ -89,7 +92,7 @@ def test_delete(self):
self.container.delete(wait=True)
self.assertRaises(
- NameError, self.client.containers.get, self.container.name)
+ exceptions.NotFound, self.client.containers.get, self.container.name)
def test_start_stop(self):
"""The container is started and then stopped."""
diff --git a/integration/testing.py b/integration/testing.py
index ba2d1da..c8ee7be 100644
--- a/integration/testing.py
+++ b/integration/testing.py
@@ -11,8 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
-import uuid
import unittest
+import uuid
from pylxd.client import Client
from integration.busybox import create_busybox_image
@@ -27,6 +27,7 @@ def setUp(self):
self.lxd = self.client.api
def generate_object_name(self):
+ """Generate a random object name."""
# Underscores are not allowed in container names.
test = self.id().split('.')[-1].replace('_', '')
rando = str(uuid.uuid1()).split('-')[-1]
@@ -34,6 +35,8 @@ def generate_object_name(self):
def create_container(self):
"""Create a container in lxd."""
+ fingerprint, alias = self.create_image()
+
name = self.generate_object_name()
machine = {
'name': name,
@@ -42,7 +45,7 @@ def create_container(self):
'ephemeral': False,
'config': {'limits.cpu': '2'},
'source': {'type': 'image',
- 'alias': 'busybox'},
+ 'alias': alias},
}
result = self.lxd['containers'].post(json=machine)
operation_uuid = result.json()['operation'].split('/')[-1]
@@ -92,6 +95,7 @@ def delete_image(self, fingerprint):
self.lxd.images[fingerprint].delete()
def create_profile(self):
+ """Create a profile."""
name = self.generate_object_name()
config = {'limits.memory': '1GB'}
self.lxd.profiles.post(json={
@@ -101,6 +105,7 @@ def create_profile(self):
return name
def delete_profile(self, name):
+ """Delete a profile."""
self.lxd.profiles[name].delete()
def assertCommon(self, response):
diff --git a/pylxd/container.py b/pylxd/container.py
index 5e2e153..4620f58 100644
--- a/pylxd/container.py
+++ b/pylxd/container.py
@@ -226,7 +226,7 @@ def rename_snapshot(self, old, new, wait=False): # pragma: no cover
def delete_snapshot(self, name, wait=False): # pragma: no cover
"""Delete a snapshot."""
snapshot = self.snapshots.get(name)
- snapshot.delete()
+ snapshot.delete(wait=wait)
@deprecated('Container.get_file is deprecated. Please use Container.files.get') # NOQA
def get_file(self, filepath): # pragma: no cover
From e350582e4a110950f5db66feef4f87c1e375459f Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:32:56 -0600
Subject: [PATCH 2/6] Fix test_images integration tests
---
integration/test_images.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/integration/test_images.py b/integration/test_images.py
index 7bf1450..f69dab8 100644
--- a/integration/test_images.py
+++ b/integration/test_images.py
@@ -11,6 +11,8 @@
# 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 pylxd import exceptions
+
from integration.testing import create_busybox_image, IntegrationTestCase
@@ -69,7 +71,7 @@ def test_update(self):
def test_delete(self):
"""The image is deleted."""
- self.image.delete()
+ self.image.delete(wait=True)
self.assertRaises(
- NameError, self.client.images.get, self.image.fingerprint)
+ exceptions.NotFound, self.client.images.get, self.image.fingerprint)
From 5f427d08b996f01864849a1544a4eb818baef717 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:43:45 -0600
Subject: [PATCH 3/6] Fix profile integration tests
---
integration/test_profiles.py | 6 ++++--
pylxd/profile.py | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/integration/test_profiles.py b/integration/test_profiles.py
index f5f1e00..5055504 100644
--- a/integration/test_profiles.py
+++ b/integration/test_profiles.py
@@ -13,6 +13,8 @@
# under the License.
import unittest
+from pylxd import exceptions
+
from integration.testing import IntegrationTestCase
@@ -40,7 +42,7 @@ def test_all(self):
def test_create(self):
"""A profile is created."""
name = 'an-profile'
- config = {'limits.memory': '4GB'}
+ config = {'limits.memory': '1GB'}
profile = self.client.profiles.create(name, config)
self.addCleanup(self.delete_profile, name)
@@ -84,4 +86,4 @@ def test_delete(self):
self.profile.delete()
self.assertRaises(
- NameError, self.client.profiles.get, self.profile.name)
+ exceptions.NotFound, self.client.profiles.get, self.profile.name)
diff --git a/pylxd/profile.py b/pylxd/profile.py
index 7df3520..749aa0d 100644
--- a/pylxd/profile.py
+++ b/pylxd/profile.py
@@ -53,7 +53,7 @@ def create(cls, client, name, config=None, devices=None):
profile['devices'] = devices
response = client.api.profiles.post(json=profile)
- if response.status_code is not 202:
+ if response.status_code is not 200:
raise exceptions.CreateFailed(response.json())
return cls.get(client, name)
From c0eab89267ba02718a9de852a02db7fcf86c050a Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:45:14 -0600
Subject: [PATCH 4/6] Update mock_lxd to look more like lxd
---
pylxd/tests/mock_lxd.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pylxd/tests/mock_lxd.py b/pylxd/tests/mock_lxd.py
index 5150503..a05eef9 100644
--- a/pylxd/tests/mock_lxd.py
+++ b/pylxd/tests/mock_lxd.py
@@ -17,7 +17,7 @@ def images_POST(request, context):
def profiles_POST(request, context):
- context.status_code = 202
+ context.status_code = 200
return json.dumps({'metadata': {}})
From 30ecae9ec9174ffcfc642ec0d502eb4a88b8d48f Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:47:45 -0600
Subject: [PATCH 5/6] Fix lint
---
integration/test_containers.py | 3 ++-
integration/test_images.py | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/integration/test_containers.py b/integration/test_containers.py
index 43b5166..46076d1 100644
--- a/integration/test_containers.py
+++ b/integration/test_containers.py
@@ -92,7 +92,8 @@ def test_delete(self):
self.container.delete(wait=True)
self.assertRaises(
- exceptions.NotFound, self.client.containers.get, self.container.name)
+ exceptions.NotFound,
+ self.client.containers.get, self.container.name)
def test_start_stop(self):
"""The container is started and then stopped."""
diff --git a/integration/test_images.py b/integration/test_images.py
index f69dab8..a16932e 100644
--- a/integration/test_images.py
+++ b/integration/test_images.py
@@ -74,4 +74,5 @@ def test_delete(self):
self.image.delete(wait=True)
self.assertRaises(
- exceptions.NotFound, self.client.images.get, self.image.fingerprint)
+ exceptions.NotFound,
+ self.client.images.get, self.image.fingerprint)
From c1fc195605fd3d121917123e7c738137826eacc0 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Wed, 1 Jun 2016 12:49:43 -0600
Subject: [PATCH 6/6] Fix container test to be able to run in parallel
---
integration/test_containers.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/integration/test_containers.py b/integration/test_containers.py
index 46076d1..609f19b 100644
--- a/integration/test_containers.py
+++ b/integration/test_containers.py
@@ -35,8 +35,7 @@ def test_all(self):
containers = self.client.containers.all()
- self.assertEqual(1, len(containers))
- self.assertEqual(name, containers[0].name)
+ self.assertIn(name, [c.name for c in containers])
def test_create(self):
"""Creates and returns a new container."""
More information about the lxc-devel
mailing list