Ejemplo n.º 1
0
    def test_update_config_changed_on_env_change(self, *_):
        # given
        HardwarePreset.create(name='foo',
                              cpu_cores=1,
                              memory=1200000,
                              disk=2000000)

        # then
        assert self.config.max_resource_size == 0  # initial
        assert not HardwarePresets.update_config(DEFAULT, self.config)
        assert self.config.max_resource_size == 7e9
        assert not HardwarePresets.update_config(DEFAULT, self.config)
        assert not HardwarePresets.update_config(DEFAULT, self.config)

        # when env changes (disk space shrinks)
        with patch('golem.core.hardware.free_partition_space',
                   return_value=5e9):
            # then
            assert HardwarePresets.update_config(DEFAULT, self.config)
            assert self.config.max_resource_size == 5e9
            assert not HardwarePresets.update_config(DEFAULT, self.config)

        # when env changes again (back to previous state) than
        assert HardwarePresets.update_config(DEFAULT, self.config)
        assert self.config.max_resource_size == 7e9
        assert not HardwarePresets.update_config(DEFAULT, self.config)
Ejemplo n.º 2
0
    def test_update_config_lower_bounds(self, *_):
        # given
        HardwarePreset.create(name='min', cpu_cores=-7, memory=-1, disk=-1)

        # when
        config_changed = HardwarePresets.update_config('min', self.config)

        # then
        assert not config_changed
        assert self.config.hardware_preset_name == 'min'
        assert self.config.num_cores == MIN_CPU_CORES
        assert self.config.max_memory_size == MIN_MEMORY_SIZE
        assert self.config.max_resource_size == MIN_DISK_SPACE
Ejemplo n.º 3
0
    def test_update_config(self, *_):
        # given
        HardwarePreset.create(name='foo',
                              cpu_cores=1,
                              memory=1200000,
                              disk=2000000)

        # when
        config_changed = HardwarePresets.update_config('foo', self.config)

        # then
        assert not config_changed
        assert self.config.hardware_preset_name == 'foo'
        assert self.config.num_cores == 1
        assert self.config.max_memory_size == 1200000
        assert self.config.max_resource_size == 2000000
Ejemplo n.º 4
0
    def test_update_config_not_changed(self, *_):
        # given
        HardwarePreset.create(name='foo',
                              cpu_cores=1,
                              memory=1200000,
                              disk=2000000)

        # then
        assert not HardwarePresets.update_config(DEFAULT, self.config)
        assert not HardwarePresets.update_config(DEFAULT, self.config)
        assert not HardwarePresets.update_config(DEFAULT, self.config)
        assert HardwarePresets.update_config(CUSTOM, self.config)
        assert not HardwarePresets.update_config(CUSTOM, self.config)
        assert HardwarePresets.update_config(DEFAULT, self.config)
        assert HardwarePresets.update_config('foo', self.config)
        assert not HardwarePresets.update_config('foo', self.config)
Ejemplo n.º 5
0
    def test_update_config_upper_bounds(self, *_):
        # given
        HardwarePreset.create(name='max',
                              cpu_cores=1e9,
                              memory=1e18,
                              disk=1e18)
        caps = HardwarePresets.caps()

        # when
        config_changed = HardwarePresets.update_config('max', self.config)

        # then
        assert not config_changed
        assert self.config.hardware_preset_name == 'max'
        assert self.config.num_cores == caps['cpu_cores']
        assert self.config.max_memory_size == caps['memory']
        assert self.config.max_resource_size == caps['disk']