Ejemplo n.º 1
0
 def test_addInstances(self):
   self.mock_thrift_client.addInstances(
     IsA(JobKey),
     IgnoreArg(),
     IsA(Lock)).AndReturn(DEFAULT_RESPONSE)
   self.mox.ReplayAll()
   self.make_scheduler_proxy().addInstances(JobKey(), {}, Lock())
Ejemplo n.º 2
0
 def test_replaceCronTemplate(self):
     self.mock_thrift_client.replaceCronTemplate(
         IsA(JobConfiguration), IsA(Lock),
         IsA(SessionKey)).AndReturn(DEFAULT_RESPONSE)
     self.mox.ReplayAll()
     self.make_scheduler_proxy().replaceCronTemplate(
         JobConfiguration(), Lock())
Ejemplo n.º 3
0
 def create_acquire_lock_response(cls, code, msg, token, rolling):
     """Set up the response to a startUpdate API call."""
     start_update_response = cls.create_blank_response(code, msg)
     start_update_response.result = Result(
         acquireLockResult=AcquireLockResult(
             lock=Lock(key='foo', token='token')))
     return start_update_response
Ejemplo n.º 4
0
 def test_releaseLock(self):
   self.mock_thrift_client.releaseLock(
       IsA(Lock),
       IsA(LockValidation),
       SESSION).AndReturn(DEFAULT_RESPONSE)
   self.mox.ReplayAll()
   self.make_scheduler_proxy().releaseLock(Lock(), LockValidation())
Ejemplo n.º 5
0
 def assert_correct_killtask_calls(cls, api):
   assert api.killTasks.call_count == 20
   # Check the last call's parameters.
   api.killTasks.assert_called_with(
       TaskQuery(taskIds=None,
           jobKeys=[JobKey(role='bozo', environment='test', name='hello')],
           instanceIds=frozenset([19]),
           statuses=ACTIVE_STATES),
       Lock(key='foo', token='token'))
Ejemplo n.º 6
0
    def cancel_update(cls, scheduler, job_key):
        """Cancels an update process by removing an exclusive lock on a provided job.

    Arguments:
    scheduler -- scheduler instance to use.
    job_key -- job key to cancel update for.

    Returns a response object with cancel update result status.
    """
        return scheduler.releaseLock(
            Lock(key=LockKey(job=job_key.to_thrift())),
            LockValidation.UNCHECKED)
Ejemplo n.º 7
0
    def test_cancel_update_api_level(self):
        """Test kill client-side API logic."""
        (mock_api, mock_scheduler_proxy) = self.create_mock_api()
        mock_scheduler_proxy.releaseLock.return_value = self.get_release_lock_response(
        )
        with patch('apache.aurora.client.api.SchedulerProxy',
                   return_value=mock_scheduler_proxy):
            cmd = AuroraCommandLine()
            cmd.execute(['job', 'cancel-update', self.TEST_JOBSPEC])

            # All that cancel_update really does is release the update lock.
            # So that's all we really need to check.
            assert mock_scheduler_proxy.releaseLock.mock_calls == [
                call(Lock(key=LockKey(job=self.TEST_JOBKEY.to_thrift())),
                     LockValidation.UNCHECKED)
            ]
Ejemplo n.º 8
0
class TestGetLocksCommand(AuroraClientCommandTest):

    MESSAGE = 'test message'
    USER = '******'
    LOCKS = [
        Lock(key=LockKey(job=JobKey('role', 'env', 'name')),
             token='test token',
             user=USER,
             timestampMs='300',
             message=MESSAGE)
    ]

    @classmethod
    def create_response(cls, locks, response_code=None):
        response_code = ResponseCode.OK if response_code is None else response_code
        resp = Response(responseCode=response_code,
                        details=[ResponseDetail(message='test')])
        resp.result = Result(getLocksResult=GetLocksResult(locks=locks))
        return resp

    def test_get_locks(self):
        """Tests successful execution of the get_locks command."""
        mock_options = self.setup_mock_options()
        with contextlib.nested(
                patch('twitter.common.app.get_options',
                      return_value=mock_options),
                patch('apache.aurora.admin.admin.make_admin_client',
                      return_value=create_autospec(spec=AuroraClientAPI)),
                patch('apache.aurora.admin.admin.CLUSTERS',
                      new=self.TEST_CLUSTERS),
                patch('apache.aurora.admin.admin.print_results'),
        ) as (_, mock_make_admin_client, _, mock_print_results):

            api = mock_make_admin_client.return_value
            api.get_locks.return_value = self.create_response(self.LOCKS)

            get_locks([self.TEST_CLUSTER])

            assert api.get_locks.call_count == 1
            assert mock_print_results.call_count == 1
            assert "'message': '%s'" % self.MESSAGE in mock_print_results.call_args[
                0][0][0]
            assert "'user': '******'" % self.USER in mock_print_results.call_args[
                0][0][0]
Ejemplo n.º 9
0
 def test_acquireLock(self):
     self.mock_thrift_client.acquireLock(
         IsA(Lock), IsA(SessionKey)).AndReturn(DEFAULT_RESPONSE)
     self.mox.ReplayAll()
     self.make_scheduler_proxy().acquireLock(Lock())
 def test_releaseLock(self):
     self.mock_thrift_client.releaseLock(IsA(Lock), IsA(LockValidation),
                                         IsA(SessionKey))
     self.mox.ReplayAll()
     self.make_scheduler_proxy().releaseLock(Lock(), LockValidation())
 def test_acquireLock(self):
     self.mock_thrift_client.acquireLock(IsA(Lock), IsA(SessionKey))
     self.mox.ReplayAll()
     self.make_scheduler_proxy().acquireLock(Lock())
 def test_addInstances(self):
     self.mock_thrift_client.addInstances(IsA(JobKey), IgnoreArg(),
                                          IsA(Lock), IsA(SessionKey))
     self.mox.ReplayAll()
     self.make_scheduler_proxy().addInstances(JobKey(), {}, Lock())