def expect_start(self, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code,
                         messageDEPRECATED='test')
     response.result = Result(acquireLockResult=AcquireLockResult(
         lock=self._lock))
     self._scheduler.acquireLock(LockKey(job=self._job_key),
                                 self._session_key).AndReturn(response)
Exemple #2
0
    def _start(self):
        """Starts an update by applying an exclusive lock on a job being updated.

    Returns Response instance from the scheduler call.
    """
        resp = self._scheduler.acquireLock(LockKey(job=self._job_key))
        if resp.responseCode == ResponseCode.OK:
            self._lock = resp.result.acquireLockResult.lock
        return resp
Exemple #3
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)
Exemple #4
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)
            ]
Exemple #5
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]
Exemple #6
0
 def expect_start(self, response_code=ResponseCode.OK):
     response = make_response(response_code)
     response.result = Result(acquireLockResult=AcquireLockResult(
         lock=self._lock))
     self._scheduler.acquireLock(LockKey(job=self._job_key),
                                 self._session_key).AndReturn(response)