示例#1
0
 def test_pulse_interval_unset(self):
     config = UpdaterConfig(
         UpdateConfig(batch_size=1,
                      watch_secs=1,
                      max_per_shard_failures=1,
                      max_total_failures=1))
     assert config.to_thrift_update_settings(
     ).blockIfNoPulsesAfterMs is None
 def test_pulse_interval_too_low(self):
   threshold = UpdaterConfig.MIN_PULSE_INTERVAL_SECONDS
   with raises(ValueError) as e:
     UpdaterConfig(UpdateConfig(batch_size=1,
                                watch_secs=1,
                                max_per_shard_failures=1,
                                max_total_failures=1,
                                pulse_interval_secs=threshold - 1))
   assert 'Pulse interval seconds must be at least %s seconds.' % threshold in e.value.message
示例#3
0
def test_update_config_passes_with_min_requirement_values():
    base_job = Job(
        name='hello_world',
        role='john_doe',
        cluster='test-cluster',
        update_config=UpdateConfig(watch_secs=26),
        health_check_config=HealthCheckConfig(max_consecutive_failures=1),
        task=Task(name='main',
                  processes=[],
                  resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))

    config._validate_update_config(AuroraConfig(base_job))
示例#4
0
def test_update_config_passes_with_watch_secs_zero():
    base_job = Job(name='hello_world',
                   role='john_doe',
                   cluster='test-cluster',
                   update_config=UpdateConfig(watch_secs=0),
                   task=Task(name='main',
                             processes=[],
                             resources=Resources(cpu=0.1,
                                                 ram=64 * MB,
                                                 disk=64 * MB)))

    config._validate_update_config(AuroraConfig(base_job))
示例#5
0
def test_update_config_fails_insufficient_watch_secs_equal_to_target():
    base_job = Job(
        name='hello_world',
        role='john_doe',
        cluster='test-cluster',
        update_config=UpdateConfig(watch_secs=25),
        health_check_config=HealthCheckConfig(max_consecutive_failures=1),
        task=Task(name='main',
                  processes=[],
                  resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))

    with pytest.raises(SystemExit):
        config._validate_update_config(AuroraConfig(base_job))
示例#6
0
def test_update_config_fails_insufficient_watch_secs_less_than_target():
    base_job = Job(name='hello_world',
                   role='john_doe',
                   cluster='test-cluster',
                   update_config=UpdateConfig(watch_secs=10),
                   task=Task(name='main',
                             processes=[],
                             resources=Resources(cpu=0.1,
                                                 ram=64 * MB,
                                                 disk=64 * MB)))

    with pytest.raises(SystemExit):
        config._validate_update_config(AuroraConfig(base_job))
示例#7
0
    def test_batch_size_and_update_strategy(self):
        """Test setting a batch size along with an update strategy.
       This combination should result in a fast fail.
    """

        with raises(ValueError) as e:
            UpdaterConfig(
                UpdateConfig(batch_size=2,
                             update_strategy=self.UPDATE_STRATEGIES(
                                 PystachioBatchUpdateStrategy(batch_size=3))))

        assert ('Ambiguous update configuration. Cannot combine '
                'update strategy with batch size. Please set batch'
                'size inside of update strategy instead.' in e.value.message)
示例#8
0
    def test_wait_for_batch_completion_and_update_strategy(self):
        """Test setting wait_for_batch_completion along with an update strategy.
       This combination should result in a fast fail.
    """

        with raises(ValueError) as e:
            UpdaterConfig(
                UpdateConfig(wait_for_batch_completion=True,
                             update_strategy=self.UPDATE_STRATEGIES(
                                 PystachioBatchUpdateStrategy(batch_size=3))))

        assert ('Ambiguous update configuration. Cannot combine '
                'wait_batch_completion with an '
                'explicit update strategy.' in e.value.message)
示例#9
0
 def mock_job_config(cls, error=None):
     config = create_autospec(spec=AuroraConfig, instance=True)
     update_config = UpdateConfig(batch_size=1,
                                  watch_secs=50,
                                  max_per_shard_failures=2,
                                  max_total_failures=1)
     if error:
         config.update_config.side_effect = error
     else:
         config.update_config.return_value = update_config
     mock_task_config = create_autospec(spec=JobConfiguration,
                                        instance=True)
     mock_task_config.taskConfig = TaskConfig()
     config.job.return_value = mock_task_config
     config.instances.return_value = 5
     return config
示例#10
0
    def test_to_thrift_update_settings_no_strategy_queue(self):
        """Test to_thrift produces an expected thrift update settings configuration
       from a Pystachio update object that doesn't include an update strategy.

       The configuration in this test should be converted to a
       QueueJobUpdateStrategy.
    """

        config = UpdaterConfig(UpdateConfig())

        thrift_update_config = config.to_thrift_update_settings()

        update_settings = copy.deepcopy(self.EXPECTED_JOB_UPDATE_SETTINGS)
        update_settings.updateStrategy = JobUpdateStrategy(
            batchStrategy=None,
            queueStrategy=QueueJobUpdateStrategy(groupSize=1),
            varBatchStrategy=None)

        assert thrift_update_config == update_settings
示例#11
0
    def test_to_thrift_update_settings_no_strategy_batch(self):
        """Test to_thrift produces an expected thrift update settings configuration
       from a Pystachio update object that doesn't include an update strategy.

       The configuration in this test should be converted to a
       BatchJobUpdateStrategy.
    """

        config = UpdaterConfig(UpdateConfig(wait_for_batch_completion=True))

        thrift_update_config = config.to_thrift_update_settings()

        update_settings = copy.deepcopy(self.EXPECTED_JOB_UPDATE_SETTINGS)
        update_settings.updateStrategy = JobUpdateStrategy(
            batchStrategy=BatchJobUpdateStrategy(groupSize=1,
                                                 autopauseAfterBatch=False),
            queueStrategy=None,
            varBatchStrategy=None)
        update_settings.waitForBatchCompletion = True

        assert thrift_update_config == update_settings
示例#12
0
    def test_to_thrift_update_settings_strategy(self):
        """Test to_thrift produces an expected thrift update settings configuration
       from a Pystachio update object.
    """

        config = UpdaterConfig(
            UpdateConfig(update_strategy=self.UPDATE_STRATEGIES(
                PystachioVariableBatchUpdateStrategy(
                    batch_sizes=[1, 2, 3, 4], autopause_after_batch=True))))

        thrift_update_config = config.to_thrift_update_settings()

        update_settings = copy.deepcopy(self.EXPECTED_JOB_UPDATE_SETTINGS)

        update_settings.updateStrategy = JobUpdateStrategy(
            batchStrategy=None,
            queueStrategy=None,
            varBatchStrategy=VariableBatchJobUpdateStrategy(
                groupSizes=(1, 2, 3, 4), autopauseAfterBatch=True))

        assert thrift_update_config == update_settings