From 0c5c8d1f00e13267be233f8b9da8627abf6135d4 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Wed, 15 Jul 2015 17:13:33 +0100 Subject: [PATCH] Handle case where /containers/json returns "Labels": null Signed-off-by: Aanand Prasad --- compose/legacy.py | 2 +- tests/integration/legacy_test.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compose/legacy.py b/compose/legacy.py index c9ec658178..6fbf74d692 100644 --- a/compose/legacy.py +++ b/compose/legacy.py @@ -149,7 +149,7 @@ def _get_legacy_containers_iter( for service in services: for container in containers: - if LABEL_VERSION in container['Labels']: + if LABEL_VERSION in (container.get('Labels') or {}): continue name = get_container_name(container) diff --git a/tests/integration/legacy_test.py b/tests/integration/legacy_test.py index 806b9a457d..f79089b207 100644 --- a/tests/integration/legacy_test.py +++ b/tests/integration/legacy_test.py @@ -1,4 +1,5 @@ import unittest +from mock import Mock from docker.errors import APIError @@ -64,6 +65,22 @@ class UtilitiesTestCase(unittest.TestCase): legacy.is_valid_name("composetest_web_lol_1", one_off=True), ) + def test_get_legacy_containers_no_labels(self): + client = Mock() + client.containers.return_value = [ + { + "Id": "abc123", + "Image": "def456", + "Name": "composetest_web_1", + "Labels": None, + }, + ] + + containers = list(legacy.get_legacy_containers( + client, "composetest", ["web"])) + + self.assertEqual(len(containers), 1) + class LegacyTestCase(DockerClientTestCase):