The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/131
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === While exploring the container state issue (that ended up being a non-issue), I added a bunch of test coverage...kinda. I mean, it executes the code path, but makes no assertions, which makes me slightly uncomfortable, but after pouring through the mock_services docs, it seemed non-trivial to handle that, and probably needs some re-working beyond the scope of a small branch.
From 56e12087b014e7920fcef2f882b5bfa4a2fbb7a3 Mon Sep 17 00:00:00 2001 From: Paul Hummer <paul.hum...@canonical.com> Date: Fri, 3 Jun 2016 23:33:09 -0600 Subject: [PATCH] Add more tests for container state --- pylxd/container.py | 6 +++--- pylxd/tests/mock_lxd.py | 31 +++++++++++++++++++++++++++++++ pylxd/tests/test_container.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/pylxd/container.py b/pylxd/container.py index 3408f52..3bb5a22 100644 --- a/pylxd/container.py +++ b/pylxd/container.py @@ -59,7 +59,7 @@ def get(self, filepath): '_client', 'architecture', 'config', 'created_at', 'devices', 'ephemeral', 'expanded_config', 'expanded_devices', 'name', 'profiles', 'status' - ] + ] @classmethod def get(cls, client, name): @@ -164,7 +164,7 @@ def _set_state(self, state, timeout=30, force=True, wait=False): 'action': state, 'timeout': timeout, 'force': force - }) + }) if wait: self.wait_for_operation(response.json()['operation']) self.fetch() @@ -253,7 +253,7 @@ def execute(self, commands, environment={}): 'environment': environment, 'wait-for-websocket': False, 'interactive': False, - }) + }) operation_id = response.json()['operation'] self.wait_for_operation(operation_id) diff --git a/pylxd/tests/mock_lxd.py b/pylxd/tests/mock_lxd.py index 38f4930..ed6d0e5 100644 --- a/pylxd/tests/mock_lxd.py +++ b/pylxd/tests/mock_lxd.py @@ -106,11 +106,42 @@ def profile_GET(request, context): 'metadata': { 'status': 'Running', 'status_code': 103, + 'disk': { + 'root': { + 'usage': 10, + } + }, + 'memory': { + 'usage': 15, + 'usage_peak': 20, + 'swap_usage': 0, + 'swap_usage_peak': 5, + }, + 'network': { + 'l0': { + 'addresses': [ + {'family': 'inet', + 'address': '127.0.0.1', + 'netmask': '8', + 'scope': 'local'} + ], + } + }, + 'pid': 69, + 'processes': 100, }}), 'method': 'GET', 'url': r'^http://pylxd.test/1.0/containers/an-container/state$', # NOQA }, { + 'status_code': 202, + 'json': { + 'type': 'async', + 'operation': 'operation-abc'}, + 'method': 'PUT', + 'url': r'^http://pylxd.test/1.0/containers/an-container/state$', # NOQA + }, + { 'text': json.dumps({ 'type': 'sync', # This should be async 'operation': 'operation-abc'}), diff --git a/pylxd/tests/test_container.py b/pylxd/tests/test_container.py index 49b7c40..3b9d994 100644 --- a/pylxd/tests/test_container.py +++ b/pylxd/tests/test_container.py @@ -194,6 +194,36 @@ def test_get(self): self.assertEqual('Running', state.status) self.assertEqual(103, state.status_code) + def test_start(self): + """A container is started.""" + an_container = container.Container.get(self.client, 'an-container') + + an_container.start(wait=True) + + def test_stop(self): + """A container is stopped.""" + an_container = container.Container.get(self.client, 'an-container') + + an_container.stop() + + def test_restart(self): + """A container is restarted.""" + an_container = container.Container.get(self.client, 'an-container') + + an_container.restart() + + def test_freeze(self): + """A container is suspended.""" + an_container = container.Container.get(self.client, 'an-container') + + an_container.freeze() + + def test_unfreeze(self): + """A container is resumed.""" + an_container = container.Container.get(self.client, 'an-container') + + an_container.unfreeze() + class TestContainerSnapshots(testing.PyLXDTestCase): """Tests for pylxd.container.Container.snapshots."""
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel