Ignore:
Timestamp:
24 Sep 2014, 15:32:30 (10 years ago)
Author:
uli
Message:

Support more types of memory in env checks.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_utils.py

    r11817 r11819  
    102102        utils.SYSTEM_MAX_LOAD['virt-mem'] = -100.0  # negative number
    103103        assert utils.expensive_actions_allowed() == False
     104
     105    def test_expensive_actions_allowed_physmem_none(self):
     106        # unset physmem maximum values make KofUtils ignore physmem values
     107        utils = self.get_cleared_util()
     108        utils.SYSTEM_MAX_LOAD['phys-mem'] = None
     109        assert utils.expensive_actions_allowed() == True
     110        # even not-set values won't block us
     111        del utils.SYSTEM_MAX_LOAD['phys-mem']
     112        assert utils.expensive_actions_allowed() == True
     113
     114    @unittest.skipIf(
     115        psutil.phymem_usage().percent >= 99.0,
     116        reason="System physmem use over 99%. Cannot set higher allowed value.")
     117    def test_expensive_actions_allowed_physmem_ok(self):
     118        # We can react to high physmem values
     119        utils = self.get_cleared_util()
     120        utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.0    # positive number
     121        assert utils.expensive_actions_allowed() == True
     122        utils.SYSTEM_MAX_LOAD['phys-mem'] = -1.0    # negative number
     123        assert utils.expensive_actions_allowed() == True
     124
     125    @unittest.skipIf(
     126        not psutil.phymem_usage().percent,
     127        reason="Can test physmem behavior only if actually using some")
     128    def test_expensive_actions_allowed_physmem_too_much(self):
     129        # We can react if too much physmem is used
     130        utils = self.get_cleared_util()
     131        utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0     # positive number
     132        assert utils.expensive_actions_allowed() == False
     133        utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0  # negative number
     134        assert utils.expensive_actions_allowed() == False
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r11818 r11819  
    321321            ('swap-mem', psutil.swap_memory),
    322322            ('virt-mem', psutil.virtual_memory),
     323            ('phys-mem', psutil.phymem_usage),
    323324            ):
    324325            max_val = max_values.get(key, None)
Note: See TracChangeset for help on using the changeset viewer.