Пример #1
0
 def test_disambiguate_args_or_die_unambiguous_with_no_config(self):
     expected = (self._api,
                 AuroraJobKey(self.CLUSTER.name, self.ROLE, self.ENV,
                              self.NAME), None)
     result = LiveJobDisambiguator.disambiguate_args_or_die(
         [self.JOB_PATH], None, client_factory=lambda *_: self._api)
     assert result == expected
Пример #2
0
 def assert_cancel_update_called(cls, mock_api):
     # Running cancel update should result in calling the API cancel_update
     # method once, with an AuroraJobKey parameter.
     assert mock_api.cancel_update.call_count == 1
     assert mock_api.cancel_update.called_with(AuroraJobKey(
         cls.TEST_CLUSTER, cls.TEST_ROLE, cls.TEST_ENV, cls.TEST_JOB),
                                               config=None)
Пример #3
0
  def test_simple_successful_kill_job(self):
    """Run a test of the "kill" command against a mocked-out API:
    Verifies that the kill command sends the right API RPCs, and performs the correct
    tests on the result."""
    mock_options = self.setup_mock_options()
    mock_config = Mock()
    mock_api_factory = self.setup_mock_api_factory()
    with contextlib.nested(
        patch('twitter.aurora.client.commands.core.make_client_factory',
            return_value=mock_api_factory),
        patch('twitter.common.app.get_options', return_value=mock_options),
        patch('twitter.aurora.client.commands.core.get_job_config', return_value=mock_config)) as (
            mock_make_client_factory,
            options, mock_get_job_config):
      mock_api = mock_api_factory.return_value

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        kill(['west/mchucarroll/test/hello', fp.name], mock_options)

      # Now check that the right API calls got made.
      self.assert_kill_job_called(mock_api)
      mock_api.kill_job.assert_called_with(
        AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
            name=self.TEST_JOB), None, config=mock_config)
      self.assert_scheduler_called(mock_api)
      assert mock_make_client_factory.call_count == 1
Пример #4
0
 def query_matches(self):
     resp = self._client.get_jobs(self._role)
     check_and_log_response(resp)
     return set(
         AuroraJobKey(self._client.cluster.name, j.key.role,
                      j.key.environment, j.key.name)
         for j in resp.result.getJobsResult.configs
         if j.key.name == self._name)
Пример #5
0
    def _disambiguate_or_die(cls, client, role, env, name):
        # Returns a single AuroraJobKey if one can be found given the args, potentially
        # querying the scheduler. Calls die() with an appropriate error message otherwise.
        try:
            disambiguator = cls(client, role, env, name)
        except ValueError as e:
            die(e)

        if not disambiguator.ambiguous:
            return AuroraJobKey(client.cluster.name, role, env, name)

        deprecation_warning(
            "Job ambiguously specified - querying the scheduler to disambiguate"
        )
        matches = disambiguator.query_matches()
        if len(matches) == 1:
            (match, ) = matches
            log.info("Found job %s" % match)
            return match
        elif len(matches) == 0:
            die("No jobs found")
        else:
            die("Multiple jobs match (%s) - disambiguate by using the CLUSTER/ROLE/ENV/NAME form"
                % ",".join(str(m) for m in matches))
Пример #6
0
from twitter.aurora.client.api.restarter import Restarter
from twitter.aurora.client.api.instance_watcher import InstanceWatcher
from twitter.aurora.client.api.updater_util import UpdaterConfig
from twitter.aurora.common.aurora_job_key import AuroraJobKey

from gen.twitter.aurora.AuroraSchedulerManager import Client as scheduler_client
from gen.twitter.aurora.ttypes import *

from mox import IgnoreArg, MoxTestBase

# test space
from twitter.aurora.client.fake_scheduler_proxy import FakeSchedulerProxy

SESSION_KEY = 'test_session'
CLUSTER = 'smfd'
JOB = AuroraJobKey(CLUSTER, 'johndoe', 'test', 'test_job')
HEALTH_CHECK_INTERVAL_SECONDS = 5
UPDATER_CONFIG = UpdaterConfig(
    2,  # batch_size
    23,  # restart_threshold
    45,  #watch_secs
    0,  # max_per_instance_failures
    0  # max_total_failures
)


class TestRestarter(MoxTestBase):
    def setUp(self):
        super(TestRestarter, self).setUp()

        self.mock_scheduler = self.mox.CreateMock(scheduler_client)
Пример #7
0
 def job_key(self):
     return AuroraJobKey(self.cluster(), self.role(), self.environment(),
                         self.name())