Merge pull request #1835 from aanand/fix-crash-when-container-has-no-name
Ignore containers that don't have a name
(cherry picked from commit 4e12ce39b3)
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
22ccf35fa1
commit
74b4fb89bb
6 changed files with 64 additions and 11 deletions
|
|
@ -65,7 +65,7 @@ class UtilitiesTestCase(unittest.TestCase):
|
|||
legacy.is_valid_name("composetest_web_lol_1", one_off=True),
|
||||
)
|
||||
|
||||
def test_get_legacy_containers_no_labels(self):
|
||||
def test_get_legacy_containers(self):
|
||||
client = Mock()
|
||||
client.containers.return_value = [
|
||||
{
|
||||
|
|
@ -74,12 +74,23 @@ class UtilitiesTestCase(unittest.TestCase):
|
|||
"Name": "composetest_web_1",
|
||||
"Labels": None,
|
||||
},
|
||||
{
|
||||
"Id": "ghi789",
|
||||
"Image": "def456",
|
||||
"Name": None,
|
||||
"Labels": None,
|
||||
},
|
||||
{
|
||||
"Id": "jkl012",
|
||||
"Image": "def456",
|
||||
"Labels": None,
|
||||
},
|
||||
]
|
||||
|
||||
containers = list(legacy.get_legacy_containers(
|
||||
client, "composetest", ["web"]))
|
||||
containers = legacy.get_legacy_containers(client, "composetest", ["web"])
|
||||
|
||||
self.assertEqual(len(containers), 1)
|
||||
self.assertEqual(containers[0].id, 'abc123')
|
||||
|
||||
|
||||
class LegacyTestCase(DockerClientTestCase):
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from .. import unittest
|
|||
from compose.service import Service
|
||||
from compose.project import Project
|
||||
from compose.container import Container
|
||||
from compose.const import LABEL_SERVICE
|
||||
|
||||
import mock
|
||||
import docker
|
||||
|
|
@ -260,3 +261,27 @@ class ProjectTest(unittest.TestCase):
|
|||
|
||||
service = project.get_service('test')
|
||||
self.assertEqual(service._get_net(), 'container:' + container_name)
|
||||
|
||||
def test_container_without_name(self):
|
||||
self.mock_client.containers.return_value = [
|
||||
{'Image': 'busybox:latest', 'Id': '1', 'Name': '1'},
|
||||
{'Image': 'busybox:latest', 'Id': '2', 'Name': None},
|
||||
{'Image': 'busybox:latest', 'Id': '3'},
|
||||
]
|
||||
self.mock_client.inspect_container.return_value = {
|
||||
'Id': '1',
|
||||
'Config': {
|
||||
'Labels': {
|
||||
LABEL_SERVICE: 'web',
|
||||
},
|
||||
},
|
||||
}
|
||||
project = Project.from_dicts(
|
||||
'test',
|
||||
[{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
}],
|
||||
self.mock_client,
|
||||
)
|
||||
self.assertEqual([c.id for c in project.containers()], ['1'])
|
||||
|
|
|
|||
|
|
@ -76,6 +76,18 @@ class ServiceTest(unittest.TestCase):
|
|||
all=False,
|
||||
filters={'label': expected_labels})
|
||||
|
||||
def test_container_without_name(self):
|
||||
self.mock_client.containers.return_value = [
|
||||
{'Image': 'foo', 'Id': '1', 'Name': '1'},
|
||||
{'Image': 'foo', 'Id': '2', 'Name': None},
|
||||
{'Image': 'foo', 'Id': '3'},
|
||||
]
|
||||
service = Service('db', self.mock_client, 'myproject', image='foo')
|
||||
|
||||
self.assertEqual([c.id for c in service.containers()], ['1'])
|
||||
self.assertEqual(service._next_container_number(), 2)
|
||||
self.assertEqual(service.get_container(1).id, '1')
|
||||
|
||||
def test_get_volumes_from_container(self):
|
||||
container_id = 'aabbccddee'
|
||||
service = Service(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue