예제 #1
0
    def test_kill_job_with_instances_batched_maxerrors_output(self):
        """Test kill client-side API logic."""
        mock_context = FakeAuroraCommandContext()
        with contextlib.nested(
                patch('apache.aurora.client.cli.jobs.Job.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):
            api = mock_context.get_api('west')
            status_result = self.create_status_call_result()
            mock_context.add_expected_status_query_result(status_result)
            api.kill_job.return_value = self.create_error_response()

            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                cmd.execute([
                    'job', 'kill', '--max-total-failures=1',
                    '--config=%s' % fp.name, 'west/bozo/test/hello/0,2,4-13'
                ])

            assert mock_context.get_out() == []
            print(mock_context.get_err())
            assert mock_context.get_err() == [
                'Kill of shards [0, 2, 4, 5, 6] failed with error; see log for details',
                'Kill of shards [7, 8, 9, 10, 11] failed with error; see log for details',
                'Exceeded maximum number of errors while killing instances'
            ]
예제 #2
0
  def test_simple_successful_create_job_output(self):
    """Run a test of the "create" command against a mocked-out API:
    Verifies that the creation command generates the correct output.
    """
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context)):
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.PENDING))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      api = mock_context.get_api('west')
      api.create_job.return_value = self.get_createjob_response()

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
            fp.name])
        assert result == EXIT_OK
      assert mock_context.get_out() == [
          "job create succeeded: job url=http://something_or_other/scheduler/bozo/test/hello"]
      assert mock_context.get_err() == []
예제 #3
0
    def test_start_update_command_line_succeeds(self):
        mock_context = FakeAuroraCommandContext()
        with contextlib.nested(
                patch('apache.aurora.client.cli.update.Update.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):
            mock_api = mock_context.get_api('west')
            mock_api.start_job_update.return_value = self.create_simple_success_response(
            )
            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                result = cmd.execute(
                    ['update', 'start', self.TEST_JOBSPEC, fp.name])
                assert result == EXIT_OK

            assert mock_api.start_job_update.call_count == 1
            args, kwargs = mock_api.start_job_update.call_args
            assert isinstance(args[0], AuroraConfig)
            assert args[1] is None
            assert mock_context.get_out() == [
                "Scheduler-driven update of job west/bozo/test/hello has started."
            ]
            assert mock_context.get_err() == []
예제 #4
0
  def test_create_job_startup_fails(self):
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context)):
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.PENDING))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))

      # We need to override the side_effect behavior of check_status in the context.
      def check_status_side_effect(*args):
        return self.create_error_response()

      mock_context.get_api("west").check_status.side_effect = check_status_side_effect

      api = mock_context.get_api('west')
      api.create_job.return_value = self.get_createjob_response()

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
            fp.name])
        assert result == EXIT_COMMAND_FAILURE
      assert mock_context.get_out() == []
      assert mock_context.get_err() == ["Error occurred while creating job west/bozo/test/hello"]
예제 #5
0
    def test_killall_job_output(self):
        """Test kill output."""
        mock_context = FakeAuroraCommandContext()
        mock_scheduler_proxy = Mock()
        with contextlib.nested(
                patch('threading._Event.wait'),
                patch('apache.aurora.client.cli.jobs.Job.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):

            api = mock_context.get_api('west')
            mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_call_result(
            )
            api.kill_job.return_value = self.get_kill_job_response()
            mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response(
            )
            mock_context.add_expected_status_query_result(
                self.create_status_call_result(
                    self.create_mock_task(ScheduleStatus.KILLED)))
            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                cmd.execute([
                    'job', 'killall', '--no-batching',
                    '--config=%s' % fp.name, 'west/bozo/test/hello'
                ])
            assert mock_context.get_out() == ['job killall succeeded']
            assert mock_context.get_err() == []
예제 #6
0
    def test_kill_job_with_instances_batched_output(self):
        """Test kill client-side API logic."""
        mock_context = FakeAuroraCommandContext()
        with contextlib.nested(
                patch('threading._Event.wait'),
                patch('apache.aurora.client.cli.jobs.Job.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):
            api = mock_context.get_api('west')
            status_result = self.create_status_call_result()
            mock_context.add_expected_status_query_result(status_result)
            api.kill_job.return_value = self.get_kill_job_response()
            mock_context.add_expected_status_query_result(
                self.create_status_call_result(
                    self.create_mock_task(ScheduleStatus.KILLED)))

            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                cmd.execute([
                    'job', 'kill',
                    '--config=%s' % fp.name, 'west/bozo/test/hello/0,2,4-6'
                ])

        assert mock_context.get_out() == [
            'Successfully killed shards [0, 2, 4, 5, 6]', 'job kill succeeded'
        ]
        assert mock_context.get_err() == []
예제 #7
0
  def test_create_job_failed_output(self):
    """Test that a failed create generates the correct error messages"""
    mock_context = FakeAuroraCommandContext()
    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
      mock_context.add_expected_status_query_result(
          self.create_mock_status_query_result(ScheduleStatus.INIT))
      api = mock_context.get_api('west')
      api.create_job.return_value = self.get_failed_createjob_response()
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['job', 'create', '--wait-until=RUNNING',
            'west/bozo/test/hello', fp.name])
        assert result == EXIT_COMMAND_FAILURE

      # Check that create_job was called exactly once, with an AuroraConfig parameter.
      print("Out=%s\nErr=%s" % (mock_context.get_out(), mock_context.get_err()))
      assert mock_context.get_out() == []
      assert mock_context.get_err() == ["job create failed because of scheduler error"]
예제 #8
0
  def test_create_job_failed_output(self):
    """Test that a failed create generates the correct error messages"""
    mock_context = FakeAuroraCommandContext()
    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
      mock_context.add_expected_status_query_result(
          self.create_mock_status_query_result(ScheduleStatus.INIT))
      api = mock_context.get_api('west')
      api.create_job.return_value = self.get_failed_createjob_response()
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['job', 'create', '--wait-until=RUNNING',
            'west/bozo/test/hello', fp.name])
        assert result == EXIT_COMMAND_FAILURE

      # Check that create_job was called exactly once, with an AuroraConfig parameter.
      print("Out=%s\nErr=%s" % (mock_context.get_out(), mock_context.get_err()))
      assert mock_context.get_out() == []
      assert mock_context.get_err() == ["job create failed because of scheduler error"]
예제 #9
0
  def test_status_job_not_found(self):
    """Regression test: there was a crasher bug when metadata was None."""

    mock_context = FakeAuroraCommandContext()
    mock_api = mock_context.get_api('west')
    mock_api.check_status.return_value = self.create_empty_status()
    with contextlib.nested(
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context)):
      cmd = AuroraCommandLine()
      result = cmd.execute(['job', 'status', 'west/bozo/test/hello'])
      assert result == EXIT_INVALID_PARAMETER
      assert mock_context.get_err() == ["Found no jobs matching west/bozo/test/hello"]
예제 #10
0
    def test_status_job_not_found(self):
        """Regression test: there was a crasher bug when metadata was None."""

        mock_context = FakeAuroraCommandContext()
        mock_api = mock_context.get_api('west')
        mock_api.check_status.return_value = self.create_empty_status()
        with contextlib.nested(
                patch('apache.aurora.client.cli.jobs.Job.create_context',
                      return_value=mock_context)):
            cmd = AuroraCommandLine()
            result = cmd.execute(['job', 'status', 'west/bozo/test/hello'])
            assert result == EXIT_INVALID_PARAMETER
            assert mock_context.get_err() == ["No matching jobs found"]
예제 #11
0
  def test_kill_job_with_instances_batched_maxerrors_output(self):
    """Test kill client-side API logic."""
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
      api = mock_context.get_api('west')
      status_result = self.create_status_call_result()
      mock_context.add_expected_status_query_result(status_result)
      api.kill_job.return_value = self.create_error_response()

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        cmd.execute(['job', 'kill', '--max-total-failures=1', '--config=%s' % fp.name,
            'west/bozo/test/hello/0,2,4-13'])

      assert mock_context.get_out() == []
      print(mock_context.get_err())
      assert mock_context.get_err() == [
          'Kill of shards [0, 2, 4, 5, 6] failed with error; see log for details',
          'Kill of shards [7, 8, 9, 10, 11] failed with error; see log for details',
          'Exceeded maximum number of errors while killing instances']
예제 #12
0
  def test_pause_update_command_line_error(self):
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
      mock_api = mock_context.get_api('west')
      mock_api.pause_job_update.return_value = self.create_error_response()
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['beta-update', 'pause', self.TEST_JOBSPEC])
        assert result == EXIT_API_ERROR

      mock_api.pause_job_update.assert_called_with(self.TEST_JOBKEY)
      assert mock_context.get_out() == []
      assert mock_context.get_err() == [
          "Error: Failed to pause scheduler-driven update; see log for details"]
예제 #13
0
  def test_abort_update_command_line_succeeds(self):
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
      mock_api = mock_context.get_api('west')
      mock_api.abort_job_update.return_value = self.create_simple_success_response()
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['beta-update', 'abort', self.TEST_JOBSPEC])
        assert result == EXIT_OK

      mock_api.abort_job_update.assert_called_with(self.TEST_JOBKEY)
      assert mock_context.get_out() == [
          "Scheduler-driven update of job west/bozo/test/hello has been aborted."]
      assert mock_context.get_err() == []
예제 #14
0
  def test_start_update_command_line_succeeds(self):
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
      mock_api = mock_context.get_api('west')
      mock_api.start_job_update.return_value = self.create_simple_success_response()
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['beta-update', 'start', self.TEST_JOBSPEC, fp.name])
        assert result == EXIT_OK

      assert mock_api.start_job_update.call_count == 1
      args, kwargs = mock_api.start_job_update.call_args
      assert isinstance(args[0], AuroraConfig)
      assert args[1] is None
      assert mock_context.get_out() == [
          "Scheduler-driven update of job west/bozo/test/hello has started."]
      assert mock_context.get_err() == []
예제 #15
0
    def test_pause_update_command_line_error(self):
        mock_context = FakeAuroraCommandContext()
        with contextlib.nested(
                patch('apache.aurora.client.cli.update.Update.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):
            mock_api = mock_context.get_api('west')
            mock_api.pause_job_update.return_value = self.create_error_response(
            )
            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                result = cmd.execute(['update', 'pause', self.TEST_JOBSPEC])
                assert result == EXIT_API_ERROR

            mock_api.pause_job_update.assert_called_with(self.TEST_JOBKEY)
            assert mock_context.get_out() == []
            assert mock_context.get_err() == [
                "Error: Failed to pause scheduler-driven update; see log for details"
            ]
예제 #16
0
    def test_abort_update_command_line_succeeds(self):
        mock_context = FakeAuroraCommandContext()
        with contextlib.nested(
                patch('apache.aurora.client.cli.update.Update.create_context',
                      return_value=mock_context),
                patch('apache.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)):
            mock_api = mock_context.get_api('west')
            mock_api.abort_job_update.return_value = self.create_simple_success_response(
            )
            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                cmd = AuroraCommandLine()
                result = cmd.execute(['update', 'abort', self.TEST_JOBSPEC])
                assert result == EXIT_OK

            mock_api.abort_job_update.assert_called_with(self.TEST_JOBKEY)
            assert mock_context.get_out() == [
                "Scheduler-driven update of job west/bozo/test/hello has been aborted."
            ]
            assert mock_context.get_err() == []
예제 #17
0
  def test_failed_create_job_with_incomplete_bindings(self):
    """Run a test of the "create" command against a mocked-out API:
    Verifies that the creation command sends the right API RPCs, and performs the correct
    tests on the result."""

    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context)):

      # This is the real test: invoke create as if it had been called by the command line.
      with temporary_file() as fp:
        fp.write(self.get_unbound_test_config())
        fp.flush()
        cmd = AuroraCommandLine()
        result = cmd.execute(['job', 'create', '--wait-until=RUNNING',
            '--bind', 'cluster_binding=west',
           'west/bozo/test/hello',
            fp.name])
        assert result == EXIT_INVALID_CONFIGURATION
      assert mock_context.get_err() == [
          "TypeCheck(FAILED): MesosJob[update_config] failed: "
          "UpdateConfig[batch_size] failed: u'{{TEST_BATCH}}' not an integer"]
예제 #18
0
  def test_kill_job_with_instances_batched_output(self):
    """Test kill client-side API logic."""
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):
      api = mock_context.get_api('west')
      status_result = self.create_status_call_result()
      mock_context.add_expected_status_query_result(status_result)
      api.kill_job.return_value = self.get_kill_job_response()
      mock_context.add_expected_status_query_result(self.create_status_call_result(
          self.create_mock_task(ScheduleStatus.KILLED)))

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        cmd.execute(['job', 'kill', '--config=%s' % fp.name, 'west/bozo/test/hello/0,2,4-6'])

    assert mock_context.get_out() == ['Successfully killed shards [0, 2, 4, 5, 6]',
        'job kill succeeded']
    assert mock_context.get_err() == []
예제 #19
0
  def test_killall_job_output(self):
    """Test kill output."""
    mock_context = FakeAuroraCommandContext()
    mock_scheduler_proxy = Mock()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context),
        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)):

      api = mock_context.get_api('west')
      mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_call_result()
      api.kill_job.return_value = self.get_kill_job_response()
      mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
      mock_context.add_expected_status_query_result(self.create_status_call_result(
          self.create_mock_task(ScheduleStatus.KILLED)))
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        cmd.execute(['job', 'killall', '--no-batching', '--config=%s' % fp.name,
            'west/bozo/test/hello'])
      assert mock_context.get_out() == ['job killall succeeded']
      assert mock_context.get_err() == []
예제 #20
0
  def test_simple_successful_create_job_output(self):
    """Run a test of the "create" command against a mocked-out API:
    Verifies that the creation command generates the correct output.
    """
    mock_context = FakeAuroraCommandContext()
    with contextlib.nested(
        patch('threading._Event.wait'),
        patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context)):
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.PENDING))
      mock_context.add_expected_status_query_result(
        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
      api = mock_context.get_api('west')
      api.create_job.return_value = self.get_createjob_response()

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        cmd = AuroraCommandLine()
        cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
            fp.name])
      assert mock_context.get_out() == [
          "job create succeeded: job url=http://something_or_other/scheduler/bozo/test/hello"]
      assert mock_context.get_err() == []