mirror of
https://github.com/docker/docs.git
synced 2026-04-12 06:19:22 +07:00
Require volumes_from a container to be explicit in V2 config.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from compose.const import IS_WINDOWS_PLATFORM
|
||||
from tests import mock
|
||||
from tests import unittest
|
||||
|
||||
DEFAULT_VERSION = 2
|
||||
DEFAULT_VERSION = V2 = 2
|
||||
V1 = 1
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class SortServiceTest(unittest.TestCase):
|
||||
},
|
||||
{
|
||||
'name': 'parent',
|
||||
'volumes_from': [VolumeFromSpec('child', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('child', 'rw', 'service')]
|
||||
},
|
||||
{
|
||||
'links': ['parent'],
|
||||
@@ -120,7 +120,7 @@ class SortServiceTest(unittest.TestCase):
|
||||
},
|
||||
{
|
||||
'name': 'parent',
|
||||
'volumes_from': [VolumeFromSpec('child', 'ro')]
|
||||
'volumes_from': [VolumeFromSpec('child', 'ro', 'service')]
|
||||
},
|
||||
{
|
||||
'name': 'child'
|
||||
@@ -145,7 +145,7 @@ class SortServiceTest(unittest.TestCase):
|
||||
},
|
||||
{
|
||||
'name': 'two',
|
||||
'volumes_from': [VolumeFromSpec('one', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('one', 'rw', 'service')]
|
||||
},
|
||||
{
|
||||
'name': 'one'
|
||||
|
||||
@@ -5,8 +5,11 @@ import pytest
|
||||
|
||||
from compose.config.errors import ConfigurationError
|
||||
from compose.config.types import parse_extra_hosts
|
||||
from compose.config.types import VolumeFromSpec
|
||||
from compose.config.types import VolumeSpec
|
||||
from compose.const import IS_WINDOWS_PLATFORM
|
||||
from tests.unit.config.config_test import V1
|
||||
from tests.unit.config.config_test import V2
|
||||
|
||||
|
||||
def test_parse_extra_hosts_list():
|
||||
@@ -67,3 +70,45 @@ class TestVolumeSpec(object):
|
||||
"/opt/shiny/config",
|
||||
"ro"
|
||||
)
|
||||
|
||||
|
||||
class TestVolumesFromSpec(object):
|
||||
|
||||
services = ['servicea', 'serviceb']
|
||||
|
||||
def test_parse_v1_from_service(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea', self.services, V1)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'rw', 'service')
|
||||
|
||||
def test_parse_v1_from_container(self):
|
||||
volume_from = VolumeFromSpec.parse('foo:ro', self.services, V1)
|
||||
assert volume_from == VolumeFromSpec('foo', 'ro', 'container')
|
||||
|
||||
def test_parse_v1_invalid(self):
|
||||
with pytest.raises(ConfigurationError):
|
||||
VolumeFromSpec.parse('unknown:format:ro', self.services, V1)
|
||||
|
||||
def test_parse_v2_from_service(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'rw', 'service')
|
||||
|
||||
def test_parse_v2_from_service_with_mode(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea:ro', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'ro', 'service')
|
||||
|
||||
def test_parse_v2_from_container(self):
|
||||
volume_from = VolumeFromSpec.parse('container:foo', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('foo', 'rw', 'container')
|
||||
|
||||
def test_parse_v2_from_container_with_mode(self):
|
||||
volume_from = VolumeFromSpec.parse('container:foo:ro', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('foo', 'ro', 'container')
|
||||
|
||||
def test_parse_v2_invalid_type(self):
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
VolumeFromSpec.parse('bogus:foo:ro', self.services, V2)
|
||||
assert "Unknown volumes_from type 'bogus'" in exc.exconly()
|
||||
|
||||
def test_parse_v2_invalid(self):
|
||||
with pytest.raises(ConfigurationError):
|
||||
VolumeFromSpec.parse('unknown:format:ro', self.services, V2)
|
||||
|
||||
@@ -165,10 +165,10 @@ class ProjectTest(unittest.TestCase):
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'busybox:latest',
|
||||
'volumes_from': [VolumeFromSpec('aaa', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('aaa', 'rw', 'container')]
|
||||
}
|
||||
], None), self.mock_client)
|
||||
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_id + ":rw"])
|
||||
assert project.get_service('test')._get_volumes_from() == [container_id + ":rw"]
|
||||
|
||||
def test_use_volumes_from_service_no_container(self):
|
||||
container_name = 'test_vol_1'
|
||||
@@ -188,10 +188,10 @@ class ProjectTest(unittest.TestCase):
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'busybox:latest',
|
||||
'volumes_from': [VolumeFromSpec('vol', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('vol', 'rw', 'service')]
|
||||
}
|
||||
], None), self.mock_client)
|
||||
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_name + ":rw"])
|
||||
assert project.get_service('test')._get_volumes_from() == [container_name + ":rw"]
|
||||
|
||||
def test_use_volumes_from_service_container(self):
|
||||
container_ids = ['aabbccddee', '12345']
|
||||
@@ -204,16 +204,17 @@ class ProjectTest(unittest.TestCase):
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'busybox:latest',
|
||||
'volumes_from': [VolumeFromSpec('vol', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('vol', 'rw', 'service')]
|
||||
}
|
||||
], None), None)
|
||||
with mock.patch.object(Service, 'containers') as mock_return:
|
||||
mock_return.return_value = [
|
||||
mock.Mock(id=container_id, spec=Container)
|
||||
for container_id in container_ids]
|
||||
self.assertEqual(
|
||||
project.get_service('test')._get_volumes_from(),
|
||||
[container_ids[0] + ':rw'])
|
||||
assert (
|
||||
project.get_service('test')._get_volumes_from() ==
|
||||
[container_ids[0] + ':rw']
|
||||
)
|
||||
|
||||
def test_events(self):
|
||||
services = [Service(name='web'), Service(name='db')]
|
||||
|
||||
@@ -70,7 +70,11 @@ class ServiceTest(unittest.TestCase):
|
||||
service = Service(
|
||||
'test',
|
||||
image='foo',
|
||||
volumes_from=[VolumeFromSpec(mock.Mock(id=container_id, spec=Container), 'rw')])
|
||||
volumes_from=[
|
||||
VolumeFromSpec(
|
||||
mock.Mock(id=container_id, spec=Container),
|
||||
'rw',
|
||||
'container')])
|
||||
|
||||
self.assertEqual(service._get_volumes_from(), [container_id + ':rw'])
|
||||
|
||||
@@ -79,7 +83,11 @@ class ServiceTest(unittest.TestCase):
|
||||
service = Service(
|
||||
'test',
|
||||
image='foo',
|
||||
volumes_from=[VolumeFromSpec(mock.Mock(id=container_id, spec=Container), 'ro')])
|
||||
volumes_from=[
|
||||
VolumeFromSpec(
|
||||
mock.Mock(id=container_id, spec=Container),
|
||||
'ro',
|
||||
'container')])
|
||||
|
||||
self.assertEqual(service._get_volumes_from(), [container_id + ':ro'])
|
||||
|
||||
@@ -90,7 +98,10 @@ class ServiceTest(unittest.TestCase):
|
||||
mock.Mock(id=container_id, spec=Container)
|
||||
for container_id in container_ids
|
||||
]
|
||||
service = Service('test', volumes_from=[VolumeFromSpec(from_service, 'rw')], image='foo')
|
||||
service = Service(
|
||||
'test',
|
||||
volumes_from=[VolumeFromSpec(from_service, 'rw', 'service')],
|
||||
image='foo')
|
||||
|
||||
self.assertEqual(service._get_volumes_from(), [container_ids[0] + ":rw"])
|
||||
|
||||
@@ -102,7 +113,10 @@ class ServiceTest(unittest.TestCase):
|
||||
mock.Mock(id=container_id.split(':')[0], spec=Container)
|
||||
for container_id in container_ids
|
||||
]
|
||||
service = Service('test', volumes_from=[VolumeFromSpec(from_service, mode)], image='foo')
|
||||
service = Service(
|
||||
'test',
|
||||
volumes_from=[VolumeFromSpec(from_service, mode, 'service')],
|
||||
image='foo')
|
||||
|
||||
self.assertEqual(service._get_volumes_from(), [container_ids[0]])
|
||||
|
||||
@@ -113,7 +127,10 @@ class ServiceTest(unittest.TestCase):
|
||||
from_service.create_container.return_value = mock.Mock(
|
||||
id=container_id,
|
||||
spec=Container)
|
||||
service = Service('test', image='foo', volumes_from=[VolumeFromSpec(from_service, 'rw')])
|
||||
service = Service(
|
||||
'test',
|
||||
image='foo',
|
||||
volumes_from=[VolumeFromSpec(from_service, 'rw', 'service')])
|
||||
|
||||
self.assertEqual(service._get_volumes_from(), [container_id + ':rw'])
|
||||
from_service.create_container.assert_called_once_with()
|
||||
@@ -389,7 +406,7 @@ class ServiceTest(unittest.TestCase):
|
||||
client=self.mock_client,
|
||||
net=ServiceNet(Service('other')),
|
||||
links=[(Service('one'), 'one')],
|
||||
volumes_from=[VolumeFromSpec(Service('two'), 'rw')])
|
||||
volumes_from=[VolumeFromSpec(Service('two'), 'rw', 'service')])
|
||||
|
||||
config_dict = service.config_dict()
|
||||
expected = {
|
||||
|
||||
Reference in New Issue
Block a user