Пример #1
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.admin.admin.make_admin_client',
              return_value=create_autospec(spec=AuroraClientAPI)),
          patch('apache.aurora.admin.admin.print_results'),
          patch('apache.aurora.admin.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'
        ])
Пример #2
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.admin.admin.make_admin_client',
            return_value=create_autospec(spec=AuroraClientAPI)),
        patch('apache.aurora.admin.admin.print_results'),
        patch('apache.aurora.admin.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'
      ])
Пример #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.admin.admin.make_client',
                          new=create_autospec(spec=AuroraClientAPI)),
                    patch('apache.aurora.admin.admin.print_results'),
                    patch('apache.aurora.admin.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'])
Пример #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.admin.admin.make_client',
                      new=create_autospec(spec=AuroraClientAPI)),
                patch('apache.aurora.admin.admin.print_results'),
                patch('apache.aurora.admin.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'
            ])
Пример #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.'
Пример #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.'
Пример #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.'
Пример #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):

        try:
          sla_probe_hosts(['west', '50', '100s'])
        except SystemExit:
          pass
        else:
          assert 'Expected error is not raised.'