Ejemplo n.º 1
0
  def test_probe_hosts_with_list(self):
    """Tests successful execution of the sla_probe_hosts command with host list."""
    hosts = ['h0', 'h1']
    mock_options = self.setup_mock_options(hosts=','.join(hosts))
    mock_vector = self.create_mock_probe_hosts_vector([self.create_probe_hosts(2, 80, True, 0)])
    with contextlib.nested(
        patch('apache.aurora.client.commands.admin.AuroraClientAPI',
            new=create_autospec(spec=AuroraClientAPI)),
        patch('apache.aurora.client.commands.admin.print_results'),
        patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
        patch('twitter.common.app.get_options', return_value=mock_options)
    ) as (
        mock_api,
        mock_print_results,
        test_clusters,
        options):

      mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
      sla_probe_hosts(['west', '90', '200s'])

      mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
          mock_options.min_instance_count, hosts)
      mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, mock_options.grouping)
      mock_print_results.assert_called_once_with([
          'h0\twest/role/env/job0\t80.00\tTrue\t0',
          'h1\twest/role/env/job1\t80.00\tTrue\t0'
      ])
Ejemplo n.º 2
0
  def test_probe_hosts_with_file(self):
    """Tests successful execution of the sla_probe_hosts command with host filename."""
    mock_vector = self.create_mock_probe_hosts_vector([self.create_probe_hosts(1, 80, False, None)])
    with temporary_file() as fp:
      fp.write('h0')
      fp.flush()
      mock_options = self.setup_mock_options(filename=fp.name)
      with contextlib.nested(
          patch('apache.aurora.client.commands.admin.AuroraClientAPI',
              new=create_autospec(spec=AuroraClientAPI)),
          patch('apache.aurora.client.commands.admin.print_results'),
          patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
          patch('twitter.common.app.get_options', return_value=mock_options)
      ) as (
          mock_api,
          mock_print_results,
          test_clusters,
          options):

        mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
        sla_probe_hosts(['west', '90', '200s'])

        mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
          mock_options.min_instance_count, ['h0'])
        mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, mock_options.grouping)
        mock_print_results.assert_called_once_with([
            'h0\twest/role/env/job0\t80.00\tFalse\tn/a'
        ])
Ejemplo n.º 3
0
    def test_probe_hosts_with_file(self):
        """Tests successful execution of the sla_probe_hosts command with host filename."""
        mock_vector = self.create_mock_probe_hosts_vector(
            [self.create_probe_hosts(1, 80, False, None)])
        with temporary_file() as fp:
            fp.write('h0')
            fp.flush()
            mock_options = self.setup_mock_options(filename=fp.name)
            with contextlib.nested(
                    patch(
                        'apache.aurora.client.commands.admin.AuroraClientAPI',
                        new=Mock(spec=AuroraClientAPI)),
                    patch('apache.aurora.client.commands.admin.print_results'),
                    patch('apache.aurora.client.commands.admin.CLUSTERS',
                          new=self.TEST_CLUSTERS),
                    patch('twitter.common.app.get_options',
                          return_value=mock_options)) as (mock_api,
                                                          mock_print_results,
                                                          test_clusters,
                                                          options):

                mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
                sla_probe_hosts(['west', '90', '200s'])

                mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
                    mock_options.min_instance_count, ['h0'])
                mock_vector.probe_hosts.assert_called_once_with(
                    90.0, 200.0, mock_options.grouping)
                mock_print_results.assert_called_once_with(
                    ['h0\twest/role/env/job0\t80.00\tFalse\tn/a'])
Ejemplo n.º 4
0
    def test_probe_hosts_with_list(self):
        """Tests successful execution of the sla_probe_hosts command with host list."""
        hosts = ['h0', 'h1']
        mock_options = self.setup_mock_options(hosts=','.join(hosts))
        mock_vector = self.create_mock_probe_hosts_vector(
            [self.create_probe_hosts(2, 80, True, 0)])
        with contextlib.nested(
                patch('apache.aurora.client.commands.admin.AuroraClientAPI',
                      new=Mock(spec=AuroraClientAPI)),
                patch('apache.aurora.client.commands.admin.print_results'),
                patch('apache.aurora.client.commands.admin.CLUSTERS',
                      new=self.TEST_CLUSTERS),
                patch('twitter.common.app.get_options',
                      return_value=mock_options)) as (mock_api,
                                                      mock_print_results,
                                                      test_clusters, options):

            mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
            sla_probe_hosts(['west', '90', '200s'])

            mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
                mock_options.min_instance_count, hosts)
            mock_vector.probe_hosts.assert_called_once_with(
                90.0, 200.0, mock_options.grouping)
            mock_print_results.assert_called_once_with([
                'h0\twest/role/env/job0\t80.00\tTrue\t0',
                'h1\twest/role/env/job1\t80.00\tTrue\t0'
            ])
Ejemplo n.º 5
0
  def test_probe_grouping_error(self):
    """Tests execution of the sla_probe_hosts command with invalid grouping."""
    mock_options = self.setup_mock_options(hosts='h0', grouping='foo')
    with patch('twitter.common.app.get_options', return_value=mock_options):

      try:
        sla_probe_hosts(['west', '50', '100s'])
      except SystemExit:
        pass
      else:
        assert 'Expected error is not raised.'
Ejemplo n.º 6
0
    def test_probe_grouping_error(self):
        """Tests execution of the sla_probe_hosts command with invalid grouping."""
        mock_options = self.setup_mock_options(hosts='h0', grouping='foo')
        with patch('twitter.common.app.get_options',
                   return_value=mock_options):

            try:
                sla_probe_hosts(['west', '50', '100s'])
            except SystemExit:
                pass
            else:
                assert 'Expected error is not raised.'
Ejemplo n.º 7
0
  def test_probe_hosts_error(self):
    """Tests execution of the sla_probe_hosts command with both host and filename provided."""
    with temporary_file() as fp:
      fp.write('h0')
      fp.flush()
      mock_options = self.setup_mock_options(hosts='h0', filename=fp.name)
      with patch('twitter.common.app.get_options', return_value=mock_options):

        try:
          sla_probe_hosts(['west', '50', '100s'])
        except SystemExit:
          pass
        else:
          assert 'Expected error is not raised.'
Ejemplo n.º 8
0
    def test_probe_hosts_error(self):
        """Tests execution of the sla_probe_hosts command with both host and filename provided."""
        with temporary_file() as fp:
            fp.write("h0")
            fp.flush()
            mock_options = self.setup_mock_options(hosts="h0", filename=fp.name)
            with patch("twitter.common.app.get_options", return_value=mock_options) as (mock_options):

                try:
                    sla_probe_hosts(["west", "50", "100s"])
                except SystemExit:
                    pass
                else:
                    assert "Expected error is not raised."
Ejemplo n.º 9
0
    def test_probe_hosts_error(self):
        """Tests execution of the sla_probe_hosts command with both host and filename provided."""
        with temporary_file() as fp:
            fp.write('h0')
            fp.flush()
            mock_options = self.setup_mock_options(hosts='h0',
                                                   filename=fp.name)
            with patch('twitter.common.app.get_options',
                       return_value=mock_options):

                try:
                    sla_probe_hosts(['west', '50', '100s'])
                except SystemExit:
                    pass
                else:
                    assert 'Expected error is not raised.'
Ejemplo n.º 10
0
    def test_probe_hosts_with_file(self):
        """Tests successful execution of the sla_probe_hosts command with host filename."""
        mock_vector = self.create_mock_vector(self.create_probe_hosts(1, 80, False, None))
        with temporary_file() as fp:
            fp.write("h0")
            fp.flush()
            mock_options = self.setup_mock_options(filename=fp.name)
            with contextlib.nested(
                patch("apache.aurora.client.commands.admin.AuroraClientAPI", new=Mock(spec=AuroraClientAPI)),
                patch("apache.aurora.client.commands.admin.print_results"),
                patch("apache.aurora.client.commands.admin.CLUSTERS", new=self.TEST_CLUSTERS),
                patch("twitter.common.app.get_options", return_value=mock_options),
            ) as (mock_api, mock_print_results, test_clusters, mock_options):

                mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
                sla_probe_hosts(["west", "90", "200s"])

                mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(["h0"])
                mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, ["h0"])
                mock_print_results.assert_called_once_with(["h0\twest/role/env/job0\t80.00\tFalse\tn/a"])
Ejemplo n.º 11
0
    def test_probe_hosts_with_list(self):
        """Tests successful execution of the sla_probe_hosts command with host list."""
        hosts = ["h0", "h1"]
        mock_options = self.setup_mock_options(hosts=",".join(hosts))
        mock_vector = self.create_mock_vector(self.create_probe_hosts(2, 80, True, 0))
        with contextlib.nested(
            patch("apache.aurora.client.commands.admin.AuroraClientAPI", new=Mock(spec=AuroraClientAPI)),
            patch("apache.aurora.client.commands.admin.print_results"),
            patch("apache.aurora.client.commands.admin.CLUSTERS", new=self.TEST_CLUSTERS),
            patch("twitter.common.app.get_options", return_value=mock_options),
        ) as (mock_api, mock_print_results, test_clusters, mock_options):

            mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
            sla_probe_hosts(["west", "90", "200s"])

            mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(hosts)
            mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, hosts)
            mock_print_results.assert_called_once_with(
                ["h0\twest/role/env/job0\t80.00\tTrue\t0", "h1\twest/role/env/job1\t80.00\tTrue\t0"]
            )