aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMD NADEEM <mail2nadeem92@gmail.com>2016-06-20 11:16:46 +0530
committerMD NADEEM <mail2nadeem92@gmail.com>2016-06-27 14:11:51 +0530
commit02e060e099f2fb483fda86f496cad22e42064f3f (patch)
tree96852cc8489e518d51a2353f8c22dbd6490aa7b9 /tests
parent01d183da274280b16122e55b20355c0a469a5db7 (diff)
downloadkolla-02e060e099f2fb483fda86f496cad22e42064f3f.tar.gz
kolla-02e060e099f2fb483fda86f496cad22e42064f3f.zip
Add unit test for stop and restart container
Change-Id: Icd73eb6e2d5b4207142ef249c8995c98056ae1c4 Partially-Implements: blueprint ansible-unit-tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_kolla_docker.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py
index 8acba9a38..583fe07d3 100644
--- a/tests/test_kolla_docker.py
+++ b/tests/test_kolla_docker.py
@@ -147,6 +147,18 @@ FAKE_DATA = {
'Names': '/my_container'}
],
+ 'container_inspect': {
+ 'Config': {
+ 'Env': ['KOLLA_BASE_DISTRO=ubuntu',
+ 'KOLLA_INSTALL_TYPE=binary',
+ 'KOLLA_INSTALL_METATYPE=rdo'],
+ 'Hostname': 'node2',
+ 'Volumes': {'/var/lib/kolla/config_files/': {}}},
+ 'Mounts': {},
+ 'NetworkSettings': {},
+ 'State': {}
+ }
+
}
@@ -238,4 +250,51 @@ class TestContainer(base.BaseTestCase):
self.dw.start_container()
self.assertTrue(self.dw.changed)
self.dw.dc.start.assert_called_once_with(
- container=self.fake_data["params"].get('name'))
+ container=self.fake_data['params'].get('name'))
+
+ def test_stop_container(self):
+ self.dw = get_DockerWorker({'name': 'my_container',
+ 'action': 'stop_container'})
+ self.dw.dc.containers.return_value = self.fake_data['containers']
+ self.dw.stop_container()
+
+ self.assertTrue(self.dw.changed)
+ self.dw.dc.containers.assert_called_once_with(all=True)
+ self.dw.dc.stop.assert_called_once_with('my_container')
+
+ def test_stop_container_not_exists(self):
+ self.dw = get_DockerWorker({'name': 'fake_container',
+ 'action': 'stop_container'})
+ self.dw.dc.containers.return_value = self.fake_data['containers']
+ self.dw.stop_container()
+
+ self.assertFalse(self.dw.changed)
+ self.dw.dc.containers.assert_called_once_with(all=True)
+ self.dw.module.fail_json.assert_called_once_with(
+ msg="No such container: fake_container to stop")
+
+ def test_restart_container(self):
+ self.dw = get_DockerWorker({'name': 'my_container',
+ 'action': 'restart_container'})
+ self.dw.dc.containers.return_value = self.fake_data['containers']
+ self.fake_data['container_inspect'].update(
+ self.fake_data['containers'][0])
+ self.dw.dc.inspect_container.return_value = (
+ self.fake_data['container_inspect'])
+ self.dw.restart_container()
+
+ self.assertTrue(self.dw.changed)
+ self.dw.dc.containers.assert_called_once_with(all=True)
+ self.dw.dc.inspect_container.assert_called_once_with('my_container')
+ self.dw.dc.restart.assert_called_once_with('my_container')
+
+ def test_restart_container_not_exists(self):
+ self.dw = get_DockerWorker({'name': 'fake-container',
+ 'action': 'restart_container'})
+ self.dw.dc.containers.return_value = self.fake_data['containers']
+ self.dw.restart_container()
+
+ self.assertFalse(self.dw.changed)
+ self.dw.dc.containers.assert_called_once_with(all=True)
+ self.dw.module.fail_json.assert_called_once_with(
+ msg="No such container: fake-container")