aboutsummaryrefslogtreecommitdiff
path: root/tests/test_kolla_container_facts.py
diff options
context:
space:
mode:
authorIvan Halomi <ivan.halomi@tietoevry.com>2024-07-18 11:26:14 +0200
committerRoman Krcek <roman.krcek@tietoevry.com>2025-03-19 17:19:24 +0000
commit12aa03929a30dc9d10b12a64551623d9fd998a2f (patch)
tree91869298a4bbc1f535775b01362c45a4cc9b2300 /tests/test_kolla_container_facts.py
parent32cdbd23d5dee8dbfe22570b61981f3e7000aa68 (diff)
downloadkolla-ansible-12aa03929a30dc9d10b12a64551623d9fd998a2f.tar.gz
kolla-ansible-12aa03929a30dc9d10b12a64551623d9fd998a2f.zip
Add action for getting container names list
This patch adds a new action to kolla_container_facts module, which retrieves list of names of all containers. It is intended to be an alternative to using "docker ps -a" type of commands in the Ansible code. Change-Id: I9c04d6fe77f20e5aa832684bd65de95d161cd8ea Signed-off-by: Ivan Halomi <ivan.halomi@tietoevry.com>
Diffstat (limited to 'tests/test_kolla_container_facts.py')
-rw-r--r--tests/test_kolla_container_facts.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_kolla_container_facts.py b/tests/test_kolla_container_facts.py
index f1fc59f3e..0db0c2eb4 100644
--- a/tests/test_kolla_container_facts.py
+++ b/tests/test_kolla_container_facts.py
@@ -310,3 +310,27 @@ class TestContainerFacts(base.BaseTestCase):
self.assertIn('volumes', self.dfw.result)
self.assertEqual(len(self.dfw.result['volumes']), 0)
self.assertNotIn('nonexistent_volume', self.dfw.result['volumes'])
+
+ def test_get_containers_names(self):
+ """Test fetching container names when containers exist"""
+ self.dfw = get_DockerFactsWorker({'action': 'get_containers_names'})
+ full_cont_list = get_containers(self.fake_data['containers'])
+ self.dfw.client.containers.list.return_value = full_cont_list
+ expected_names = ["my_container"]
+
+ self.dfw.get_containers_names()
+
+ self.assertFalse(self.dfw.result['changed'])
+ self.assertIn('container_names', self.dfw.result)
+ self.assertEqual(self.dfw.result['container_names'], expected_names)
+
+ def test_get_containers_names_no_containers(self):
+ """Test fetching container names when no containers exist"""
+ self.dfw = get_DockerFactsWorker({'action': 'get_containers_names'})
+ self.dfw.client.containers.list.return_value = []
+
+ self.dfw.get_containers_names()
+
+ self.assertFalse(self.dfw.result['changed'])
+ self.assertIn('container_names', self.dfw.result)
+ self.assertEqual(self.dfw.result['container_names'], [])