コード例 #1
0
    def test_updater_simple(self):
        # Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
        # updates.
        mock_options = self.setup_mock_options()
        (mock_api, mock_scheduler) = self.create_mock_api()
        mock_health_check = self.setup_health_checks(mock_api)

        with contextlib.nested(
                patch('twitter.common.app.get_options',
                      return_value=mock_options),
                patch('twitter.aurora.client.api.SchedulerProxy',
                      return_value=mock_scheduler.scheduler),
                patch('twitter.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS),
                patch(
                    'twitter.aurora.client.api.instance_watcher.InstanceWatcherHealthCheck',
                    return_value=mock_health_check),
                patch('time.time',
                      side_effect=functools.partial(self.fake_time, self)),
                patch('time.sleep',
                      return_value=None)) as (options, scheduler_proxy_class,
                                              test_clusters,
                                              mock_health_check_factory,
                                              time_patch, sleep_patch):
            self.setup_mock_scheduler_for_simple_update(mock_api)
            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                update(['west/mchucarroll/test/hello', fp.name])

            # We don't check all calls. The updater should be able to change. What's important
            # is that we verify the key parts of the update process, to have some confidence
            # that update did the right things.
            # Every update should:
            # check its options, acquire an update lock, check status,
            # kill the old tasks, start new ones, wait for the new ones to healthcheck,
            # and finally release the lock.
            # The kill/start should happen in rolling batches.
            assert options.call_count == 2
            assert mock_scheduler.scheduler.acquireLock.call_count == 1
            self.assert_correct_killtask_calls(mock_scheduler.scheduler)
            self.assert_correct_addinstance_calls(mock_scheduler.scheduler)
            self.assert_correct_status_calls(mock_scheduler.scheduler)
            assert mock_scheduler.scheduler.releaseLock.call_count == 1
コード例 #2
0
ファイル: test_update.py プロジェクト: Empia/incubator-aurora
  def test_update_command_line_succeeds(self):
    mock_options = self.setup_mock_options()
    (mock_api, mock_scheduler) = self.create_mock_api()
    with contextlib.nested(
        patch('twitter.aurora.client.commands.core.make_client', return_value=mock_api),
        patch('twitter.common.app.get_options', return_value=mock_options),
        patch('twitter.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)
    ) as (make_client,
          options,
          test_clusters):
      mock_api.update_job.return_value = self.create_simple_success_response()

      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        update([self.TEST_JOBSPEC, fp.name])

      assert mock_api.update_job.call_count == 1
      args, kwargs = mock_api.update_job.call_args
      assert isinstance(args[0], AuroraConfig)
      assert args[1] == 3
      assert args[2] is None
コード例 #3
0
ファイル: test_update.py プロジェクト: Empia/incubator-aurora
  def test_updater_simple(self):
    # Test the client-side updater logic in its simplest case: everything succeeds, and no rolling
    # updates.
    mock_options = self.setup_mock_options()
    (mock_api, mock_scheduler) = self.create_mock_api()
    mock_health_check = self.setup_health_checks(mock_api)

    with contextlib.nested(
        patch('twitter.common.app.get_options', return_value=mock_options),
        patch('twitter.aurora.client.api.SchedulerProxy', return_value=mock_scheduler.scheduler),
        patch('twitter.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
        patch('twitter.aurora.client.api.instance_watcher.InstanceWatcherHealthCheck',
            return_value=mock_health_check),
        patch('time.time', side_effect=functools.partial(self.fake_time, self)),
        patch('time.sleep', return_value=None)

    ) as (options, scheduler_proxy_class, test_clusters, mock_health_check_factory,
          time_patch, sleep_patch):
      self.setup_mock_scheduler_for_simple_update(mock_api)
      with temporary_file() as fp:
        fp.write(self.get_valid_config())
        fp.flush()
        update(['west/mchucarroll/test/hello', fp.name])

      # We don't check all calls. The updater should be able to change. What's important
      # is that we verify the key parts of the update process, to have some confidence
      # that update did the right things.
      # Every update should:
      # check its options, acquire an update lock, check status,
      # kill the old tasks, start new ones, wait for the new ones to healthcheck,
      # and finally release the lock.
      # The kill/start should happen in rolling batches.
      assert options.call_count == 2
      assert mock_scheduler.scheduler.acquireLock.call_count == 1
      self.assert_correct_killtask_calls(mock_scheduler.scheduler)
      self.assert_correct_addinstance_calls(mock_scheduler.scheduler)
      self.assert_correct_status_calls(mock_scheduler.scheduler)
      assert mock_scheduler.scheduler.releaseLock.call_count == 1
コード例 #4
0
    def test_update_command_line_succeeds(self):
        mock_options = self.setup_mock_options()
        (mock_api, mock_scheduler) = self.create_mock_api()
        with contextlib.nested(
                patch('twitter.aurora.client.commands.core.make_client',
                      return_value=mock_api),
                patch('twitter.common.app.get_options',
                      return_value=mock_options),
                patch('twitter.aurora.client.factory.CLUSTERS',
                      new=self.TEST_CLUSTERS)) as (make_client, options,
                                                   test_clusters):
            mock_api.update_job.return_value = self.create_simple_success_response(
            )

            with temporary_file() as fp:
                fp.write(self.get_valid_config())
                fp.flush()
                update([self.TEST_JOBSPEC, fp.name])

            assert mock_api.update_job.call_count == 1
            args, kwargs = mock_api.update_job.call_args
            assert isinstance(args[0], AuroraConfig)
            assert args[1] == 3
            assert args[2] is None