mirror of
				https://github.com/docker/compose.git
				synced 2025-11-03 21:25:21 +01:00 
			
		
		
		
	Fixes #1757 - include all service properties in the config_dict()
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
		
							parent
							
								
									08ba857807
								
							
						
					
					
						commit
						c183e52502
					
				@ -488,6 +488,9 @@ class Service(object):
 | 
			
		||||
        return {
 | 
			
		||||
            'options': self.options,
 | 
			
		||||
            'image_id': self.image()['Id'],
 | 
			
		||||
            'links': [(service.name, alias) for service, alias in self.links],
 | 
			
		||||
            'net': self.get_net_name() or getattr(self.net, 'id', self.net),
 | 
			
		||||
            'volumes_from': self.get_volumes_from_names(),
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def get_dependency_names(self):
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,7 @@
 | 
			
		||||
"""
 | 
			
		||||
Integration tests which cover state convergence (aka smart recreate) performed
 | 
			
		||||
by `docker-compose up`.
 | 
			
		||||
"""
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
@ -151,6 +155,24 @@ class ProjectWithDependenciesTest(ProjectTestCase):
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(new_containers - old_containers, set())
 | 
			
		||||
 | 
			
		||||
    def test_service_removed_while_down(self):
 | 
			
		||||
        next_cfg = {
 | 
			
		||||
            'web': {
 | 
			
		||||
                'image': 'busybox:latest',
 | 
			
		||||
                'command': 'tail -f /dev/null',
 | 
			
		||||
            },
 | 
			
		||||
            'nginx': self.cfg['nginx'],
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        containers = self.run_up(self.cfg)
 | 
			
		||||
        self.assertEqual(len(containers), 3)
 | 
			
		||||
 | 
			
		||||
        project = self.make_project(self.cfg)
 | 
			
		||||
        project.stop(timeout=1)
 | 
			
		||||
 | 
			
		||||
        containers = self.run_up(next_cfg)
 | 
			
		||||
        self.assertEqual(len(containers), 2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def converge(service,
 | 
			
		||||
             allow_recreate=True,
 | 
			
		||||
 | 
			
		||||
@ -189,7 +189,7 @@ class ServiceTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            opts['labels'][LABEL_CONFIG_HASH],
 | 
			
		||||
            'b30306d0a73b67f67a45b99b88d36c359e470e6fa0c04dda1cf62d2087205b81')
 | 
			
		||||
            '3c85881a8903b9d73a06c41860c8be08acce1494ab4cf8408375966dccd714de')
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            opts['environment'],
 | 
			
		||||
            {
 | 
			
		||||
@ -331,6 +331,47 @@ class ServiceTest(unittest.TestCase):
 | 
			
		||||
        self.assertEqual(self.mock_client.build.call_count, 1)
 | 
			
		||||
        self.assertFalse(self.mock_client.build.call_args[1]['pull'])
 | 
			
		||||
 | 
			
		||||
    def test_config_dict(self):
 | 
			
		||||
        self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
 | 
			
		||||
        service = Service(
 | 
			
		||||
            'foo',
 | 
			
		||||
            image='example.com/foo',
 | 
			
		||||
            client=self.mock_client,
 | 
			
		||||
            net=Service('other'),
 | 
			
		||||
            links=[(Service('one'), 'one')],
 | 
			
		||||
            volumes_from=[Service('two')])
 | 
			
		||||
 | 
			
		||||
        config_dict = service.config_dict()
 | 
			
		||||
        expected = {
 | 
			
		||||
            'image_id': 'abcd',
 | 
			
		||||
            'options': {'image': 'example.com/foo'},
 | 
			
		||||
            'links': [('one', 'one')],
 | 
			
		||||
            'net': 'other',
 | 
			
		||||
            'volumes_from': ['two'],
 | 
			
		||||
        }
 | 
			
		||||
        self.assertEqual(config_dict, expected)
 | 
			
		||||
 | 
			
		||||
    def test_config_dict_with_net_from_container(self):
 | 
			
		||||
        self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
 | 
			
		||||
        container = Container(
 | 
			
		||||
            self.mock_client,
 | 
			
		||||
            {'Id': 'aaabbb', 'Name': '/foo_1'})
 | 
			
		||||
        service = Service(
 | 
			
		||||
            'foo',
 | 
			
		||||
            image='example.com/foo',
 | 
			
		||||
            client=self.mock_client,
 | 
			
		||||
            net=container)
 | 
			
		||||
 | 
			
		||||
        config_dict = service.config_dict()
 | 
			
		||||
        expected = {
 | 
			
		||||
            'image_id': 'abcd',
 | 
			
		||||
            'options': {'image': 'example.com/foo'},
 | 
			
		||||
            'links': [],
 | 
			
		||||
            'net': 'aaabbb',
 | 
			
		||||
            'volumes_from': [],
 | 
			
		||||
        }
 | 
			
		||||
        self.assertEqual(config_dict, expected)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def mock_get_image(images):
 | 
			
		||||
    if images:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user