Beispiel #1
0
    def test_warn_on_masked_no_warning_with_same_path(self):
        volumes_option = [VolumeSpec('/home/user', '/path', 'rw')]
        container_volumes = [VolumeSpec('/home/user', '/path', 'rw')]
        service = 'service_name'

        with mock.patch('compose.service.log', autospec=True) as mock_log:
            warn_on_masked_volume(volumes_option, container_volumes, service)

        assert not mock_log.warn.called
Beispiel #2
0
    def test_warn_on_masked_no_warning_with_container_only_option(self):
        volumes_option = [VolumeSpec(None, '/path', 'rw')]
        container_volumes = [
            VolumeSpec('/var/lib/docker/volume/path', '/path', 'rw')
        ]
        service = 'service_name'

        with mock.patch('compose.service.log', autospec=True) as mock_log:
            warn_on_masked_volume(volumes_option, container_volumes, service)

        assert not mock_log.warn.called
Beispiel #3
0
    def test_warn_on_masked_volume_when_masked(self):
        volumes_option = [VolumeSpec('/home/user', '/path', 'rw')]
        container_volumes = [
            VolumeSpec('/var/lib/docker/path', '/path', 'rw'),
            VolumeSpec('/var/lib/docker/path', '/other', 'rw'),
        ]
        service = 'service_name'

        with mock.patch('compose.service.log', autospec=True) as mock_log:
            warn_on_masked_volume(volumes_option, container_volumes, service)

        mock_log.warn.assert_called_once_with(mock.ANY)
Beispiel #4
0
    def test_for_target(self):
        yml = yaml.load("""
          image: java:latest

          targets:
            build: mvn install
        """)

        config = self.config(yml, "build")

        assert config.construi.before == []
        assert config.construi.name == "build"
        assert config.construi.run == ["mvn install"]

        assert len(config.services) == 1

        service = config.services[0]
        assert service["working_dir"] == self.working_dir
        assert service["name"] == "build"
        assert service["image"] == "java:latest"
        assert service["volumes"] == [
            VolumeSpec(external=self.working_dir,
                       internal=self.working_dir,
                       mode="rw")
        ]
Beispiel #5
0
    def test_for_target(self):
        yml = yaml.load("""
          image: java:latest

          targets:
            build: mvn install
        """)

        config = self.config(yml, 'build')

        assert config.construi['before'] == []
        assert config.construi['name'] == 'build'
        assert config.construi['run'] == ['mvn install']

        assert len(config.services) == 1

        service = config.services[0]
        assert service['working_dir'] == self.working_dir
        assert service['name'] == 'build'
        assert service['image'] == 'java:latest'
        assert service['volumes'] == [
            VolumeSpec(external=self.working_dir,
                       internal=self.working_dir,
                       mode='rw')
        ]
Beispiel #6
0
    def test_volumes(self):
        yml = yaml.load("""
          image: java:latest
          volumes:
            - /a:/a

          targets:
            build:
              volumes:
                - /b:/b
              run: run.sh
        """)

        config = self.config(yml, "build")

        assert config.construi.run == ["run.sh"]
        assert len(config.services) == 1
        assert (VolumeSpec(external="/b", internal="/b", mode="rw")
                in config.services[0]["volumes"])
        assert (VolumeSpec(external="/a", internal="/a", mode="rw")
                in config.services[0]["volumes"])
Beispiel #7
0
    def test_volumes(self):
        yml = yaml.load("""
          image: java:latest
          volumes:
            - /a:/a

          targets:
            build:
              volumes:
                - /b:/b
              run: run.sh
        """)

        config = self.config(yml, 'build')

        assert config.construi['run'] == ['run.sh']
        assert len(config.services) == 1
        assert VolumeSpec(external='/b', internal='/b',
                          mode='rw') in config.services[0]['volumes']
        assert VolumeSpec(external='/a', internal='/a',
                          mode='rw') in config.services[0]['volumes']
Beispiel #8
0
    def test_create_container_with_specified_volume(self):
        host_path = '/tmp/host-path'
        container_path = '/container-path'

        service = self.create_service(
            'db',
            volumes=[VolumeSpec(host_path, container_path, 'rw')])
        container = service.create_container()
        service.start_container(container)
        assert container.get_mount(container_path)

        # Match the last component ("host-path"), because boot2docker symlinks /tmp
        actual_host_path = container.get_mount(container_path)['Source']

        self.assertTrue(path.basename(actual_host_path) == path.basename(host_path),
                        msg=("Last component differs: %s, %s" % (actual_host_path, host_path)))
Beispiel #9
0
    def test_execute_convergence_plan_when_host_volume_is_removed(self):
        host_path = '/tmp/host-path'
        service = self.create_service(
            'db',
            build={'context': 'tests/fixtures/dockerfile-with-volume'},
            volumes=[VolumeSpec(host_path, '/data', 'rw')])

        old_container = create_and_start_container(service)
        assert ([
            mount['Destination'] for mount in old_container.get('Mounts')
        ] == ['/data'])
        service.options['volumes'] = []

        with mock.patch('compose.service.log', autospec=True) as mock_log:
            new_container, = service.execute_convergence_plan(
                ConvergencePlan('recreate', [old_container]))

        assert not mock_log.warn.called
        assert ([
            mount['Destination'] for mount in new_container.get('Mounts')
        ], ['/data'])
        assert new_container.get_mount('/data')['Source'] != host_path