def test_build_nighthawk_binaries(mock_pull, mock_copy_source,
                                  mock_run_command):
  """Verify the calls made to build nighthawk binaries"""

  mock_pull.return_value = True
  mock_copy_source.return_value = None
  mock_run_command.side_effect = [
      'bazel clean output',
      'bazel nighthawk build output ...'
  ]
  calls = [
      mock.call(_BAZEL_CLEAN_CMD, mock.ANY),
      mock.call("bazel build --jobs 4 -c dbg //:nighthawk", mock.ANY)
  ]
  manager = _generate_default_source_manager()

  source_repo = manager.get_source_repository(
      proto_source.SourceRepository.SourceIdentity.SRCID_NIGHTHAWK
  )
  source_repo.bazel_options.add(parameter="--jobs 4")
  source_repo.bazel_options.add(parameter="-c dbg")

  builder = nighthawk_builder.NightHawkBuilder(manager)
  builder.build_nighthawk_binaries()

  mock_run_command.assert_has_calls(calls)
def build_nighthawk_binary_image_from_source(
    manager: source_manager.SourceManager) -> None:
  """Build the nighthawk binary image from source

  Args:
    manager: A SourceManager object that is a wrapper for git operations.
      The source manager can navigate the commit hashes or tags to determine
      the endpoints for the benchmark
  """

  # TODO: Inject the builder object into this method
  builder = nighthawk_builder.NightHawkBuilder(manager)
  builder.build_nighthawk_binary_image()
示例#3
0
    def _prepare_nighthawk(self) -> None:
        """Prepare the nighthawk source for the benchmark.

    Checks out the nighthawk source if necessary, builds the client
    and server binaries

    """

        self._nighthawk_builder = nighthawk_builder.NightHawkBuilder(
            self._source_manager)
        self._nighthawk_builder.build_nighthawk_binaries()
        self._nighthawk_builder.build_nighthawk_benchmarks()

        nighthawk_source = self._source_manager.get_source_tree(
            proto_source.SourceRepository.SourceIdentity.SRCID_NIGHTHAWK)
        self._benchmark_dir = nighthawk_source.get_source_directory()
def test_prepare_nighthawk_source_fail(mock_get_source_tree):
  """Verify an exception is raised if the source identity is invalid"""

  envoy_source_repo = proto_source.SourceRepository(
      identity=proto_source.SourceRepository.SourceIdentity.SRCID_ENVOY,
      source_path='/some_random_envoy_directory',
      commit_hash='doesnt_matter'
  )

  mock_get_source_tree.return_value = envoy_source_repo
  manager = _generate_default_source_manager()
  builder = nighthawk_builder.NightHawkBuilder(manager)

  with pytest.raises(nighthawk_builder.NightHawkBuilderError) as builder_error:
    builder.prepare_nighthawk_source()

  assert str(builder_error.value) == \
      "This module supports building NightHawk Only"
def test_prepare_nighthawk_source(mock_pull, mock_copy_source,
                                  mock_get_source_dir):
  """Verify that we are able to get a source tree on disk to build NightHawk"""

  mock_pull.return_value = False
  mock_copy_source.return_value = None
  mock_get_source_dir.return_value = '/tmp/nighthawk_source_dir'

  manager = _generate_default_source_manager()
  builder = nighthawk_builder.NightHawkBuilder(manager)

  with mock.patch("src.lib.cmd_exec.run_command",
                  mock.MagicMock(return_value="Cleaned...")) as mock_cmd:
    builder.prepare_nighthawk_source()

  params = cmd_exec.CommandParameters(cwd='/tmp/nighthawk_source_dir')
  mock_cmd.assert_called_once_with(_BAZEL_CLEAN_CMD, params)
  mock_pull.assert_called_once()
  mock_copy_source.assert_called_once()
示例#6
0
    def _prepare_nighthawk(self) -> None:
        """Prepare the nighthawk source for the benchmark.

    Checks out the nighthawk source if necessary, builds the client
    and server binaries

    """
        manager = source_manager.SourceManager(self._control)

        # This builder needs to be a self object so that the temporary cache
        # directory is not prematurely cleaned up
        self._nighthawk_builder = nighthawk_builder.NightHawkBuilder(manager)

        # FIXME: We build this for each envoy image that we test.
        self._nighthawk_builder.build_nighthawk_benchmarks()

        nighthawk_source = manager.get_source_tree(
            proto_source.SourceRepository.SourceIdentity.SRCID_NIGHTHAWK)
        self._benchmark_dir = nighthawk_source.get_source_directory()
        log.debug(f"NightHawk benchmark dir {self._benchmark_dir}")
def test_build_nighthawk_binary_image(mock_pull, mock_run_command):
  """Verify that we can build the nighthawk benchmark image"""

  mock_pull.return_value = True
  mock_run_command.side_effect = [
      'bazel clean output ...',
      'bazel build benchmarks output ...',
      'bazel benchmark image build output ...'
  ]
  calls = [
      mock.call(_BAZEL_CLEAN_CMD, mock.ANY),
      mock.call("bazel build -c opt //:nighthawk", mock.ANY),
      mock.call(constants.NH_BINARY_IMAGE_SCRIPT, mock.ANY)
  ]

  manager = _generate_default_source_manager()
  builder = nighthawk_builder.NightHawkBuilder(manager)
  builder.build_nighthawk_binary_image()

  mock_run_command.assert_has_calls(calls)
  mock_pull.assert_called_once()