浏览代码

Prevent unnecessary inspection of containers when created from an inspect.

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 9 年之前
父节点
当前提交
73d57a1acb
共有 3 个文件被更改,包括 16 次插入7 次删除
  1. 1 1
      compose/container.py
  2. 6 6
      tests/integration/service_test.py
  3. 9 0
      tests/unit/project_test.py

+ 1 - 1
compose/container.py

@@ -39,7 +39,7 @@ class Container(object):
 
     @classmethod
     def from_id(cls, client, id):
-        return cls(client, client.inspect_container(id))
+        return cls(client, client.inspect_container(id), has_been_inspected=True)
 
     @classmethod
     def create(cls, client, **options):

+ 6 - 6
tests/integration/service_test.py

@@ -769,17 +769,17 @@ class ServiceTest(DockerClientTestCase):
         container = service.create_container(number=next_number, quiet=True)
         container.start()
 
-        self.assertTrue(container.is_running)
-        self.assertEqual(len(service.containers()), 1)
+        container.inspect()
+        assert container.is_running
+        assert len(service.containers()) == 1
 
         service.scale(1)
-
-        self.assertEqual(len(service.containers()), 1)
+        assert len(service.containers()) == 1
         container.inspect()
-        self.assertTrue(container.is_running)
+        assert container.is_running
 
         captured_output = mock_log.info.call_args[0]
-        self.assertIn('Desired container number already achieved', captured_output)
+        assert 'Desired container number already achieved' in captured_output
 
     @mock.patch('compose.service.log')
     def test_scale_with_custom_container_name_outputs_warning(self, mock_log):

+ 9 - 0
tests/unit/project_test.py

@@ -270,12 +270,21 @@ class ProjectTest(unittest.TestCase):
                 'time': 1420092061,
                 'timeNano': 14200920610000004000,
             },
+            {
+                'status': 'destroy',
+                'from': 'example/db',
+                'id': 'eeeee',
+                'time': 1420092061,
+                'timeNano': 14200920610000004000,
+            },
         ])
 
         def dt_with_microseconds(dt, us):
             return datetime.datetime.fromtimestamp(dt).replace(microsecond=us)
 
         def get_container(cid):
+            if cid == 'eeeee':
+                raise NotFound(None, None, "oops")
             if cid == 'abcde':
                 name = 'web'
                 labels = {LABEL_SERVICE: name}