Example #1
0
  def test_safe_domain_exclude_hosts(self):
    """Test successful execution of the sla_list_safe_domain command with exclude hosts option."""
    mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
    with temporary_file() as fp:
      fp.write('h1')
      fp.flush()
      mock_options = self.setup_mock_options(exclude=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,
          mock_options):

        mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

        sla_list_safe_domain(['west', '50', '100s'])

        mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
        mock_print_results.assert_called_once_with(['h0', 'h2'])
Example #2
0
  def test_safe_domain_include_hosts_from_list(self):
    """Test successful execution of the sla_list_safe_domain command with include list option."""
    mock_vector = self.create_mock_vector(self.create_hosts(2, 80, 100))
    hosts = ['h0', 'h1']
    mock_options = self.setup_mock_options(include_list=','.join(hosts))
    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,
        mock_options):

      mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

      sla_list_safe_domain(['west', '50', '100s'])

      mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
          MIN_INSTANCE_COUNT, hosts)
      mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
      mock_print_results.assert_called_once_with(hosts)
Example #3
0
    def test_safe_domain_list_jobs(self):
        """Tests successful execution of the sla_list_safe_domain command with list_jobs option."""
        mock_options = self.setup_mock_options(list_jobs=True)
        mock_vector = self.create_mock_vector(self.create_hosts(3, 50, 100))
        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,
                                                      mock_options):

            mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
            sla_list_safe_domain(['west', '50', '100s'])

            mock_vector.get_safe_hosts.assert_called_once_with(
                50.0, 100.0, {}, DEFAULT_GROUPING)
            mock_print_results.assert_called_once_with([
                'h0\twest/role/env/job0\t50.00\t100',
                'h1\twest/role/env/job1\t50.00\t100',
                'h2\twest/role/env/job2\t50.00\t100'
            ])
Example #4
0
    def test_safe_domain_exclude_hosts(self):
        """Test successful execution of the sla_list_safe_domain command with exclude hosts option."""
        mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
        with temporary_file() as fp:
            fp.write('h1')
            fp.flush()
            mock_options = self.setup_mock_options(exclude=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,
                                                          mock_options):

                mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

                sla_list_safe_domain(['west', '50', '100s'])

                mock_vector.get_safe_hosts.assert_called_once_with(
                    50.0, 100.0, {}, DEFAULT_GROUPING)
                mock_print_results.assert_called_once_with(['h0', 'h2'])
Example #5
0
    def test_safe_domain_override_jobs(self):
        """Test successful execution of the sla_list_safe_domain command with override_jobs option."""
        mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
        with temporary_file() as fp:
            fp.write('west/role/env/job1 30 200s')
            fp.flush()
            mock_options = self.setup_mock_options(override=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,
                                                          mock_options):

                mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

                sla_list_safe_domain(['west', '50', '100s'])

                job_key = AuroraJobKey.from_path('west/role/env/job1')
                override = {job_key: JobUpTimeLimit(job_key, 30, 200)}
                mock_vector.get_safe_hosts.assert_called_once_with(
                    50.0, 100.0, override, DEFAULT_GROUPING)
                mock_print_results.assert_called_once_with(['h0', 'h1', 'h2'])
Example #6
0
    def test_safe_domain_include_hosts_from_list(self):
        """Test successful execution of the sla_list_safe_domain command with include list option."""
        mock_vector = self.create_mock_vector(self.create_hosts(2, 80, 100))
        hosts = ['h0', 'h1']
        mock_options = self.setup_mock_options(include_list=','.join(hosts))
        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,
                                                      mock_options):

            mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

            sla_list_safe_domain(['west', '50', '100s'])

            mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
                MIN_INSTANCE_COUNT, hosts)
            mock_vector.get_safe_hosts.assert_called_once_with(
                50.0, 100.0, {}, DEFAULT_GROUPING)
            mock_print_results.assert_called_once_with(hosts)
Example #7
0
  def test_safe_domain_override_jobs(self):
    """Test successful execution of the sla_list_safe_domain command with override_jobs option."""
    mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
    with temporary_file() as fp:
      fp.write('west/role/env/job1 30 200s')
      fp.flush()
      mock_options = self.setup_mock_options(override=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,
          mock_options):

        mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector

        sla_list_safe_domain(['west', '50', '100s'])

        job_key = AuroraJobKey.from_path('west/role/env/job1')
        override = {job_key: JobUpTimeLimit(job_key, 30, 200)}
        mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, override, DEFAULT_GROUPING)
        mock_print_results.assert_called_once_with(['h0', 'h1', 'h2'])
Example #8
0
 def test_safe_domain_invalid_percentage(self):
   """Tests execution of the sla_list_safe_domain command with invalid percentage"""
   mock_options = self.setup_mock_options()
   with patch('twitter.common.app.get_options', return_value=mock_options):
     try:
       sla_list_safe_domain(['west', '0', '100s'])
     except SystemExit:
       pass
     else:
       assert 'Expected error is not raised.'
Example #9
0
 def test_safe_domain_invalid_percentage(self):
   """Tests execution of the sla_list_safe_domain command with invalid percentage"""
   mock_options = self.setup_mock_options()
   with patch('twitter.common.app.get_options', return_value=mock_options):
     try:
       sla_list_safe_domain(['west', '0', '100s'])
     except SystemExit:
       pass
     else:
       assert 'Expected error is not raised.'
Example #10
0
  def test_safe_domain_grouping_error(self):
    """Tests execution of the sla_list_safe_domain command invalid grouping"""
    mock_options = self.setup_mock_options(grouping='foo')
    with patch('twitter.common.app.get_options', return_value=mock_options):

      try:
        sla_list_safe_domain(['west', '50', '100s'])
      except SystemExit:
        pass
      else:
        assert 'Expected error is not raised.'
Example #11
0
  def test_safe_domain_hosts_error(self):
    """Tests execution of the sla_list_safe_domain command with both include file and list"""
    mock_options = self.setup_mock_options(include='file', include_list='list')
    with patch('twitter.common.app.get_options', return_value=mock_options):

      try:
        sla_list_safe_domain(['west', '50', '100s'])
      except SystemExit:
        pass
      else:
        assert 'Expected error is not raised.'
Example #12
0
  def test_safe_domain_grouping_error(self):
    """Tests execution of the sla_list_safe_domain command invalid grouping"""
    mock_options = self.setup_mock_options(grouping='foo')
    with patch('twitter.common.app.get_options', return_value=mock_options):

      try:
        sla_list_safe_domain(['west', '50', '100s'])
      except SystemExit:
        pass
      else:
        assert 'Expected error is not raised.'
Example #13
0
  def test_safe_domain_hosts_error(self):
    """Tests execution of the sla_list_safe_domain command with both include file and list"""
    mock_options = self.setup_mock_options(include='file', include_list='list')
    with patch('twitter.common.app.get_options', return_value=mock_options):

      try:
        sla_list_safe_domain(['west', '50', '100s'])
      except SystemExit:
        pass
      else:
        assert 'Expected error is not raised.'
Example #14
0
  def test_safe_domain_malformed_job_override(self):
    """Tests execution of the sla_list_safe_domain command with invalid job_override file"""
    with temporary_file() as fp:
      fp.write('30 200s')
      fp.flush()
      mock_options = self.setup_mock_options(override=fp.name)
      with patch('twitter.common.app.get_options', return_value=mock_options):

        try:
          sla_list_safe_domain(['west', '50', '100s'])
        except SystemExit:
          pass
        else:
          assert 'Expected error is not raised.'
Example #15
0
  def test_safe_domain_malformed_job_override(self):
    """Tests execution of the sla_list_safe_domain command with invalid job_override file"""
    with temporary_file() as fp:
      fp.write('30 200s')
      fp.flush()
      mock_options = self.setup_mock_options(override=fp.name)
      with patch('twitter.common.app.get_options', return_value=mock_options):

        try:
          sla_list_safe_domain(['west', '50', '100s'])
        except SystemExit:
          pass
        else:
          assert 'Expected error is not raised.'
Example #16
0
  def test_safe_domain_list_jobs(self):
    """Tests successful execution of the sla_list_safe_domain command with list_jobs option."""
    mock_options = self.setup_mock_options(list_jobs=True)
    mock_vector = self.create_mock_vector(self.create_hosts(3, 50, 100))
    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,
        mock_options):

      mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
      sla_list_safe_domain(['west', '50', '100s'])

      mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
      mock_print_results.assert_called_once_with([
          'h0\twest/role/env/job0\t50.00\t100',
          'h1\twest/role/env/job1\t50.00\t100',
          'h2\twest/role/env/job2\t50.00\t100'])