Resolves #874, Rename instead of use an intermediate.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
99f2a3a583
commit
6829efd4d3
4 changed files with 60 additions and 59 deletions
|
|
@ -249,25 +249,20 @@ class ServiceTest(DockerClientTestCase):
|
|||
num_containers_before = len(self.client.containers(all=True))
|
||||
|
||||
service.options['environment']['FOO'] = '2'
|
||||
tuples = service.recreate_containers()
|
||||
self.assertEqual(len(tuples), 1)
|
||||
|
||||
intermediate_container = tuples[0][0]
|
||||
new_container = tuples[0][1]
|
||||
self.assertEqual(intermediate_container.dictionary['Config']['Entrypoint'], ['/bin/echo'])
|
||||
new_container, = service.recreate_containers()
|
||||
|
||||
self.assertEqual(new_container.dictionary['Config']['Entrypoint'], ['sleep'])
|
||||
self.assertEqual(new_container.dictionary['Config']['Cmd'], ['300'])
|
||||
self.assertIn('FOO=2', new_container.dictionary['Config']['Env'])
|
||||
self.assertEqual(new_container.name, 'composetest_db_1')
|
||||
self.assertEqual(new_container.inspect()['Volumes']['/etc'], volume_path)
|
||||
self.assertIn(intermediate_container.id, new_container.dictionary['HostConfig']['VolumesFrom'])
|
||||
self.assertIn(old_container.id, new_container.dictionary['HostConfig']['VolumesFrom'])
|
||||
|
||||
self.assertEqual(len(self.client.containers(all=True)), num_containers_before)
|
||||
self.assertNotEqual(old_container.id, new_container.id)
|
||||
self.assertRaises(APIError,
|
||||
self.client.inspect_container,
|
||||
intermediate_container.id)
|
||||
old_container.id)
|
||||
|
||||
def test_recreate_containers_when_containers_are_stopped(self):
|
||||
service = self.create_service(
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class ServiceTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(service._get_volumes_from(), [container_id])
|
||||
|
||||
def test_get_volumes_from_intermediate_container(self):
|
||||
def test_get_volumes_from_previous_container(self):
|
||||
container_id = 'aabbccddee'
|
||||
service = Service('test', image='foo')
|
||||
container = mock.Mock(id=container_id, spec=Container, image='foo')
|
||||
|
|
@ -263,6 +263,20 @@ class ServiceTest(unittest.TestCase):
|
|||
mock_log.info.assert_called_once_with(
|
||||
'Pulling foo (someimage:sometag)...')
|
||||
|
||||
@mock.patch('compose.service.Container', autospec=True)
|
||||
def test_recreate_container(self, _):
|
||||
mock_container = mock.create_autospec(Container)
|
||||
service = Service('foo', client=self.mock_client, image='someimage')
|
||||
new_container = service.recreate_container(mock_container)
|
||||
|
||||
mock_container.stop.assert_called_once_with()
|
||||
self.mock_client.rename.assert_called_once_with(
|
||||
mock_container.id,
|
||||
'%s_%s' % (mock_container.short_id, mock_container.name))
|
||||
|
||||
new_container.start.assert_called_once_with()
|
||||
mock_container.remove.assert_called_once_with()
|
||||
|
||||
def test_parse_repository_tag(self):
|
||||
self.assertEqual(parse_repository_tag("root"), ("root", ""))
|
||||
self.assertEqual(parse_repository_tag("root:tag"), ("root", "tag"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue