Merge pull request #2126 from mnowster/1188-support-ro-options-in-volumes-from

1188 support ro options in volumes from
This commit is contained in:
Aanand Prasad 2015-10-07 11:57:14 +01:00
commit 627f1acdc4
7 changed files with 105 additions and 34 deletions

View file

@ -168,7 +168,7 @@ class ProjectTest(unittest.TestCase):
'volumes_from': ['aaa']
}
], self.mock_client)
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_id])
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_id + ":rw"])
def test_use_volumes_from_service_no_container(self):
container_name = 'test_vol_1'
@ -191,7 +191,7 @@ class ProjectTest(unittest.TestCase):
'volumes_from': ['vol']
}
], self.mock_client)
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_name])
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_name + ":rw"])
@mock.patch.object(Service, 'containers')
def test_use_volumes_from_service_container(self, mock_return):
@ -211,7 +211,7 @@ class ProjectTest(unittest.TestCase):
'volumes_from': ['vol']
}
], None)
self.assertEqual(project.get_service('test')._get_volumes_from(), container_ids)
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_ids[0] + ':rw'])
def test_net_unset(self):
project = Project.from_dicts('test', [

View file

@ -24,6 +24,7 @@ from compose.service import parse_repository_tag
from compose.service import parse_volume_spec
from compose.service import Service
from compose.service import ServiceNet
from compose.service import VolumeFromSpec
class ServiceTest(unittest.TestCase):
@ -75,9 +76,18 @@ class ServiceTest(unittest.TestCase):
service = Service(
'test',
image='foo',
volumes_from=[mock.Mock(id=container_id, spec=Container)])
volumes_from=[VolumeFromSpec(mock.Mock(id=container_id, spec=Container), 'rw')])
self.assertEqual(service._get_volumes_from(), [container_id])
self.assertEqual(service._get_volumes_from(), [container_id + ':rw'])
def test_get_volumes_from_container_read_only(self):
container_id = 'aabbccddee'
service = Service(
'test',
image='foo',
volumes_from=[VolumeFromSpec(mock.Mock(id=container_id, spec=Container), 'ro')])
self.assertEqual(service._get_volumes_from(), [container_id + ':ro'])
def test_get_volumes_from_service_container_exists(self):
container_ids = ['aabbccddee', '12345']
@ -86,9 +96,21 @@ class ServiceTest(unittest.TestCase):
mock.Mock(id=container_id, spec=Container)
for container_id in container_ids
]
service = Service('test', volumes_from=[from_service], image='foo')
service = Service('test', volumes_from=[VolumeFromSpec(from_service, 'rw')], image='foo')
self.assertEqual(service._get_volumes_from(), container_ids)
self.assertEqual(service._get_volumes_from(), [container_ids[0] + ":rw"])
def test_get_volumes_from_service_container_exists_with_flags(self):
for mode in ['ro', 'rw', 'z', 'rw,z', 'z,rw']:
container_ids = ['aabbccddee:' + mode, '12345:' + mode]
from_service = mock.create_autospec(Service)
from_service.containers.return_value = [
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')
self.assertEqual(service._get_volumes_from(), [container_ids[0]])
def test_get_volumes_from_service_no_container(self):
container_id = 'abababab'
@ -97,9 +119,9 @@ class ServiceTest(unittest.TestCase):
from_service.create_container.return_value = mock.Mock(
id=container_id,
spec=Container)
service = Service('test', image='foo', volumes_from=[from_service])
service = Service('test', image='foo', volumes_from=[VolumeFromSpec(from_service, 'rw')])
self.assertEqual(service._get_volumes_from(), [container_id])
self.assertEqual(service._get_volumes_from(), [container_id + ':rw'])
from_service.create_container.assert_called_once_with()
def test_split_domainname_none(self):
@ -357,7 +379,7 @@ class ServiceTest(unittest.TestCase):
client=self.mock_client,
net=ServiceNet(Service('other')),
links=[(Service('one'), 'one')],
volumes_from=[Service('two')])
volumes_from=[VolumeFromSpec(Service('two'), 'rw')])
config_dict = service.config_dict()
expected = {