Beispiel #1
0
def test_docker_image_exists_with_api_error(mocker, mock_client, caplog):
    mock_images = mocker.Mock()
    mock_images.get = mocker.Mock()

    images_mock = mocker.PropertyMock(return_value=mock_images)

    mock_client.images = images_mock

    image_tag = "gcr.io/sigint/test-image-name"

    mock_client.images.get.side_effect = docker_errors.APIError("pew")

    with pytest.raises(SystemExit):
        docker_utils.docker_image_exists(image_tag, mock_client)

    assert 1 == len(caplog.records)
Beispiel #2
0
def test_docker_image_exists(mocker, mock_client):
    mock_images = mocker.Mock()
    mock_images.get = mocker.Mock()

    images_mock = mocker.PropertyMock(return_value=mock_images)

    mock_client.images = images_mock

    image_tag = "gcr.io/sigint/test-image-name"

    exists = docker_utils.docker_image_exists(image_tag, mock_client)

    mock_client.images.get.assert_called_once_with(image_tag)
    assert exists
Beispiel #3
0
def test_docker_image_exists_with_image_not_found_error(mocker, mock_client):
    mock_images = mocker.Mock()
    mock_images.get = mocker.Mock()

    images_mock = mocker.PropertyMock(return_value=mock_images)

    mock_client.images = images_mock

    image_tag = "gcr.io/sigint/test-image-name"

    mock_client.images.get.side_effect = docker_errors.ImageNotFound(
        "pew", "pew")

    exists = docker_utils.docker_image_exists(image_tag, mock_client)

    assert not exists
Beispiel #4
0
    def _setup_docker_image(self):
        image_exists = docker_utils.docker_image_exists(
            self._full_image_name, self._docker_client)

        if not image_exists or self.docker_runtime_config.force_build:
            logging.info("Building worker image: %s" % self._full_image_name)

            _pipe_opts = self.klio_config.pipeline_options
            return docker_utils.build_docker_image(
                self.job_dir,
                _pipe_opts.worker_harness_container_image,
                self.docker_runtime_config.image_tag,
                self.docker_runtime_config.config_file_override,
            )

        logging.info("Found worker image: %s" % self._full_image_name)