瀏覽代碼

Handle case where /containers/json returns "Labels": null

Signed-off-by: Aanand Prasad <[email protected]>
Aanand Prasad 10 年之前
父節點
當前提交
0c5c8d1f00
共有 2 個文件被更改,包括 18 次插入1 次删除
  1. 1 1
      compose/legacy.py
  2. 17 0
      tests/integration/legacy_test.py

+ 1 - 1
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)

+ 17 - 0
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):