Example #1
0
def test_build_envoy_binary_from_source(mock_copy_source, mock_checkout_hash,
                                        mock_run_command,
                                        mock_run_check_command):
    """Verify the calls made to build an envoy binary from source."""
    mock_copy_source.return_value = None
    mock_checkout_hash.return_value = None
    mock_run_command.side_effect = _check_call_side_effect
    mock_run_check_command.side_effect = _check_call_side_effect

    manager = _generate_default_source_manager()
    builder = envoy_builder.EnvoyBuilder(manager)
    binary_path = builder.build_envoy_binary_from_source()

    assert constants.ENVOY_BINARY_TARGET_OUTPUT_PATH in binary_path
Example #2
0
def test_build_envoy_image_from_source_fail(mock_get_source_tree):
    """Verify an exception is raised if the source identity is invalid"""

    nighthawk_source_repo = proto_source.SourceRepository(
        identity=proto_source.SourceRepository.SourceIdentity.SRCID_NIGHTHAWK,
        source_path='/some_random_not_envoy_directory')

    mock_get_source_tree.return_value = nighthawk_source_repo
    manager = _generate_default_source_manager()
    builder = envoy_builder.EnvoyBuilder(manager)

    with pytest.raises(envoy_builder.EnvoyBuilderError) as builder_error:
        builder.build_envoy_image_from_source()

    assert str(builder_error.value) == "This class builds Envoy only."
Example #3
0
def test_build_envoy_image_from_source(mock_copy_source, mock_checkout_hash,
                                       mock_run_command,
                                       mock_run_check_command):
    """Verify the calls made to build an envoy image from a source tree."""
    mock_copy_source.return_value = None
    mock_checkout_hash.return_value = None
    mock_run_command.side_effect = _check_call_side_effect
    mock_run_check_command.side_effect = _check_call_side_effect

    manager = _generate_default_source_manager()
    builder = envoy_builder.EnvoyBuilder(manager)
    builder.build_envoy_image_from_source()

    mock_copy_source.assert_called_once()
    mock_checkout_hash.assert_called_once()
Example #4
0
def test_create_docker_image(mock_run_command, mock_glob):
    """Verify that we issue the correct commands to build an envoy docker
  image.
  """
    mock_run_command.side_effect = _check_call_side_effect
    mock_glob.return_value = ['docker_ignore_file1', 'docker_ignore_file2']

    manager = _generate_default_source_manager()
    builder = envoy_builder.EnvoyBuilder(manager)
    builder.create_docker_image()

    calls = [
        mock.call(("docker build -f ci/Dockerfile-envoy -t "
                   "envoyproxy/envoy-dev:v1.16.0 --build-arg "
                   "TARGETPLATFORM='.' ."), mock.ANY)
    ]
    mock_run_command.assert_has_calls(calls)
Example #5
0
def test_stage_envoy(mock_run_command):
    """Verify the commands used to stage the envoy binary for docker image
  construction.
  """
    mock_run_command.side_effect = _check_call_side_effect

    calls = [
        mock.call(("cp -fv bazel-bin/source/exe/envoy-static "
                   "build_release_stripped/envoy"), mock.ANY),
        mock.call(("objcopy --strip-debug bazel-bin/source/exe/envoy-static "
                   "build_release_stripped/envoy"), mock.ANY)
    ]
    manager = _generate_default_source_manager()
    builder = envoy_builder.EnvoyBuilder(manager)
    builder.stage_envoy(False)
    builder.stage_envoy(True)

    mock_run_command.assert_has_calls(calls)
    def _prepare_envoy(self) -> None:
        """Prepare the envoy source for the benchmark.

    Raises:
      BinaryBenchmarkError: an invalid envoy binary is specified via ENVOY_PATH
    """
        if self._envoy_binary_path:
            if not (os.path.exists(self._envoy_binary_path) \
                and os.access(self._envoy_binary_path, os.X_OK)):
                raise BinaryBenchmarkError(
                    "ENVOY_PATH environment variable specified, but invalid")
            # We already have a binary, no need to build
            log.info(
                "Using Envoy binary specified in ENVOY_PATH environment variable"
            )
            return

        self._envoy_builder = envoy_builder.EnvoyBuilder(self._source_manager)
        self._envoy_binary_path = self._envoy_builder.build_envoy_binary_from_source(
        )
def build_envoy_docker_image(manager: source_manager.SourceManager,
                             commit_hash: str) -> None:
  """Build an envoy image from source for the specified hash.

  If the build process fails, a CalledProcessError is raised by the
  cmd_exec module.

  Args:
    manager: A SourceManager object handling the Envoy source
    commit_hash: A string identifying the commit hash or tag for the image
      to be built

  Returns:
    None
  """

  builder = envoy_builder.EnvoyBuilder(manager)
  source_repo = manager.get_source_repository(
      proto_source.SourceRepository.SRCID_ENVOY
  )
  source_repo.commit_hash = commit_hash
  builder.build_envoy_image_from_source()