示例#1
0
    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'])
示例#2
0
 def test_create_container_with_volumes_from(self):
     volume_service = self.create_service('data')
     volume_container_1 = volume_service.create_container()
     volume_container_2 = Container.create(
         self.client,
         image='busybox:latest',
         command=["top"],
         labels={LABEL_PROJECT: 'composetest'},
     )
     host_service = self.create_service(
         'host',
         volumes_from=[
             VolumeFromSpec(volume_service, 'rw'),
             VolumeFromSpec(volume_container_2, 'rw')
         ])
     host_container = host_service.create_container()
     host_container.start()
     self.assertIn(volume_container_1.id + ':rw',
                   host_container.get('HostConfig.VolumesFrom'))
     self.assertIn(volume_container_2.id + ':rw',
                   host_container.get('HostConfig.VolumesFrom'))
示例#3
0
    def test_get_volumes_from_service_no_container(self):
        container_id = 'abababab'
        from_service = mock.create_autospec(Service)
        from_service.containers.return_value = []
        from_service.create_container.return_value = mock.Mock(id=container_id,
                                                               spec=Container)
        service = Service('test',
                          image='foo',
                          volumes_from=[VolumeFromSpec(from_service, 'rw')])

        self.assertEqual(service._get_volumes_from(), [container_id + ':rw'])
        from_service.create_container.assert_called_once_with()
示例#4
0
    def test_get_volumes_from_service_container_exists(self):
        container_ids = ['aabbccddee', '12345']
        from_service = mock.create_autospec(Service)
        from_service.containers.return_value = [
            mock.Mock(id=container_id, spec=Container)
            for container_id in container_ids
        ]
        service = Service('test',
                          volumes_from=[VolumeFromSpec(from_service, 'rw')],
                          image='foo')

        self.assertEqual(service._get_volumes_from(),
                         [container_ids[0] + ":rw"])
示例#5
0
    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]])
示例#6
0
 def test_volumes_from_service(self):
     service_dicts = build_service_dicts({
         'data': {
             'image': 'busybox:latest',
             'volumes': ['/var/data'],
         },
         'db': {
             'image': 'busybox:latest',
             'volumes_from': ['data'],
         },
     })
     project = Project.from_dicts(
         name='composetest',
         service_dicts=service_dicts,
         client=self.client,
     )
     db = project.get_service('db')
     data = project.get_service('data')
     self.assertEqual(db.volumes_from, [VolumeFromSpec(data, 'rw')])
示例#7
0
    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=ServiceNet(Service('other')),
                          links=[(Service('one'), 'one')],
                          volumes_from=[VolumeFromSpec(Service('two'), 'rw')])

        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)