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:
commit
627f1acdc4
7 changed files with 105 additions and 34 deletions
|
|
@ -6,6 +6,7 @@ from compose.const import LABEL_PROJECT
|
|||
from compose.container import Container
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
from compose.service import VolumeFromSpec
|
||||
|
||||
|
||||
def build_service_dicts(service_config):
|
||||
|
|
@ -72,7 +73,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
)
|
||||
db = project.get_service('db')
|
||||
data = project.get_service('data')
|
||||
self.assertEqual(db.volumes_from, [data])
|
||||
self.assertEqual(db.volumes_from, [VolumeFromSpec(data, 'rw')])
|
||||
|
||||
def test_volumes_from_container(self):
|
||||
data_container = Container.create(
|
||||
|
|
@ -93,7 +94,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
client=self.client,
|
||||
)
|
||||
db = project.get_service('db')
|
||||
self.assertEqual(db.volumes_from, [data_container])
|
||||
self.assertEqual(db._get_volumes_from(), [data_container.id + ':rw'])
|
||||
|
||||
def test_net_from_service(self):
|
||||
project = Project.from_dicts(
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ from compose.service import ConfigError
|
|||
from compose.service import ConvergencePlan
|
||||
from compose.service import Net
|
||||
from compose.service import Service
|
||||
from compose.service import VolumeFromSpec
|
||||
|
||||
|
||||
def create_and_start_container(service, **override_options):
|
||||
|
|
@ -272,12 +273,18 @@ class ServiceTest(DockerClientTestCase):
|
|||
command=["top"],
|
||||
labels={LABEL_PROJECT: 'composetest'},
|
||||
)
|
||||
host_service = self.create_service('host', volumes_from=[volume_service, volume_container_2])
|
||||
host_service = self.create_service(
|
||||
'host',
|
||||
volumes_from=[
|
||||
VolumeFromSpec(volume_service, 'rw'),
|
||||
VolumeFromSpec(volume_container_2, 'rw')
|
||||
]
|
||||
)
|
||||
host_container = host_service.create_container()
|
||||
host_service.start_container(host_container)
|
||||
self.assertIn(volume_container_1.id,
|
||||
self.assertIn(volume_container_1.id + ':rw',
|
||||
host_container.get('HostConfig.VolumesFrom'))
|
||||
self.assertIn(volume_container_2.id,
|
||||
self.assertIn(volume_container_2.id + ':rw',
|
||||
host_container.get('HostConfig.VolumesFrom'))
|
||||
|
||||
def test_execute_convergence_plan_recreate(self):
|
||||
|
|
|
|||
|
|
@ -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', [
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue