Use 12 characters for the short id to match docker and fix backwards compatibility.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-02-08 12:18:48 -05:00
parent edcbe2eb4d
commit deeca57a0d
2 changed files with 16 additions and 8 deletions

View File

@ -60,7 +60,7 @@ class Container(object):
@property
def short_id(self):
return self.id[:10]
return self.id[:12]
@property
def name(self):

View File

@ -12,8 +12,9 @@ from compose.container import get_container_name
class ContainerTest(unittest.TestCase):
def setUp(self):
self.container_id = "abcabcabcbabc12345"
self.container_dict = {
"Id": "abc",
"Id": self.container_id,
"Image": "busybox:latest",
"Command": "top",
"Created": 1387384730,
@ -41,19 +42,22 @@ class ContainerTest(unittest.TestCase):
self.assertEqual(
container.dictionary,
{
"Id": "abc",
"Id": self.container_id,
"Image": "busybox:latest",
"Name": "/composetest_db_1",
})
def test_from_ps_prefixed(self):
self.container_dict['Names'] = ['/swarm-host-1' + n for n in self.container_dict['Names']]
self.container_dict['Names'] = [
'/swarm-host-1' + n for n in self.container_dict['Names']
]
container = Container.from_ps(None,
container = Container.from_ps(
None,
self.container_dict,
has_been_inspected=True)
self.assertEqual(container.dictionary, {
"Id": "abc",
"Id": self.container_id,
"Image": "busybox:latest",
"Name": "/composetest_db_1",
})
@ -142,6 +146,10 @@ class ContainerTest(unittest.TestCase):
self.assertEqual(container.get('HostConfig.VolumesFrom'), ["volume_id"])
self.assertEqual(container.get('Foo.Bar.DoesNotExist'), None)
def test_short_id(self):
container = Container(None, self.container_dict, has_been_inspected=True)
assert container.short_id == self.container_id[:12]
class GetContainerNameTestCase(unittest.TestCase):