Changeset 12060 for main/waeup.ikoba/trunk/src/waeup
- Timestamp:
- 25 Nov 2014, 18:44:01 (10 years ago)
- Location:
- main/waeup.ikoba/trunk
- Files:
-
- 1 deleted
- 8 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk
- Property svn:mergeinfo changed
/main/waeup.ikoba/branches/uli-payments (added) merged: 11970,11991-11994,11998-12003,12010-12014,12019,12021-12027,12029-12031,12041-12045
- Property svn:mergeinfo changed
-
main/waeup.ikoba/trunk/src/waeup/ikoba
- Property svn:mergeinfo changed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/ftesting.zcml
r11949 r12060 14 14 <ikoba:datacenter 15 15 path="../../../parts/test/datacenter" /> 16 17 <!-- Where can the Paypal config be found? --> 18 <ikoba:paypalconf 19 path="../../../etc/paypal-testing.conf" /> 16 20 17 21 <!-- Typical functional testing security setup --> -
main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py
r12032 r12060 1137 1137 ) 1138 1138 1139 1140 class IPayPalConfig(Interface): 1141 path = Path( 1142 title = u'Path', 1143 description = u"Path to config file for PayPal REST API.", 1144 required = True, 1145 ) 1146 1147 1139 1148 # 1140 1149 # Asynchronous job handling and related -
main/waeup.ikoba/trunk/src/waeup/ikoba/meta.zcml
r11949 r12060 17 17 /> 18 18 19 <meta:directive 20 namespace="http://namespaces.waeup.org/ikoba" 21 name="paypalconf" 22 schema=".zcml.IPayPalConfig" 23 handler=".zcml.paypal_conf" 24 /> 19 25 20 26 </configure> -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/tests/test_utils.py
r11997 r12060 29 29 30 30 def setUp(self): 31 self.max_pmem = psutil.phymem_usage().total32 31 self.max_vmem = psutil.virtual_memory().total 33 32 self.max_smem = psutil.swap_memory().total … … 124 123 utils.SYSTEM_MAX_LOAD['virt-mem'] = -(sys.maxint) # negative int 125 124 assert utils.expensive_actions_allowed() == False 126 127 def test_expensive_actions_allowed_physmem_none(self):128 # unset physmem maximum values make KofUtils ignore physmem values129 utils = self.get_cleared_util()130 utils.SYSTEM_MAX_LOAD['phys-mem'] = None131 assert utils.expensive_actions_allowed() == True132 # even not-set values won't block us133 del utils.SYSTEM_MAX_LOAD['phys-mem']134 assert utils.expensive_actions_allowed() == True135 136 @unittest.skipIf(137 psutil.phymem_usage().percent >= 99.99,138 reason="System physmem use over 99%. Cannot set higher allowed value.")139 def test_expensive_actions_allowed_physmem_ok(self):140 # We can react to high physmem values141 max_mem = psutil.phymem_usage().total142 utils = self.get_cleared_util()143 utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.99 # positive float144 assert utils.expensive_actions_allowed() == True145 utils.SYSTEM_MAX_LOAD['phys-mem'] = -0.01 # negative float146 assert utils.expensive_actions_allowed() == True147 utils.SYSTEM_MAX_LOAD['phys-mem'] = max_mem # positive int148 assert utils.expensive_actions_allowed() == True149 utils.SYSTEM_MAX_LOAD['phys-mem'] = -1 # negative int150 assert utils.expensive_actions_allowed() == True151 152 @unittest.skipIf(153 not psutil.phymem_usage().percent,154 reason="Can test physmem behavior only if actually using some")155 def test_expensive_actions_allowed_physmem_too_much(self):156 # We can react if too much physmem is used157 max_mem = psutil.phymem_usage().total158 utils = self.get_cleared_util()159 utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0 # positive float160 assert utils.expensive_actions_allowed() == False161 utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0 # negative float162 assert utils.expensive_actions_allowed() == False163 utils.SYSTEM_MAX_LOAD['phys-mem'] = 0 # positive int164 assert utils.expensive_actions_allowed() == False165 utils.SYSTEM_MAX_LOAD['phys-mem'] = -(max_mem) # negative int166 assert utils.expensive_actions_allowed() == False -
main/waeup.ikoba/trunk/src/waeup/ikoba/utils/utils.py
r12053 r12060 125 125 #: value. `cpu-load`, of course, accepts float values only. 126 126 #: `swap-mem` = Swap Memory, `virt-mem` = Virtual Memory, 127 #: ` phys-mem` = Physical Memory, `cpu-load` = CPU load in percent.127 #: `cpu-load` = CPU load in percent. 128 128 SYSTEM_MAX_LOAD = { 129 129 'swap-mem': None, 130 130 'virt-mem': None, 131 'phys-mem': None,132 131 'cpu-load': 100.0, 133 132 } … … 247 246 ('swap-mem', psutil.swap_memory), 248 247 ('virt-mem', psutil.virtual_memory), 249 ('phys-mem', psutil.phymem_usage),250 248 ): 251 249 max_val = max_values.get(key, None) -
main/waeup.ikoba/trunk/src/waeup/ikoba/zcml.py
r11949 r12060 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import os 18 19 from zope.component.zcml import handler 19 from waeup.ikoba.interfaces import IDataCenterConfig 20 from zope.configuration.exceptions import ConfigurationError 21 from waeup.ikoba.interfaces import IDataCenterConfig, IPayPalConfig 22 from waeup.ikoba.payments.paypal import configure_sdk 23 20 24 21 25 def data_center_conf(context, path): … … 44 48 """ 45 49 context.action( 46 discriminator =('utility', IDataCenterConfig, ''),47 callable =handler,48 args =('registerUtility',49 {'path':path}, IDataCenterConfig, '')50 discriminator=('utility', IDataCenterConfig, ''), 51 callable=handler, 52 args=('registerUtility', 53 {'path': path}, IDataCenterConfig, '') 50 54 ) 55 56 57 def paypal_handler(path): 58 """ZCML handler that registers paypal configuration. 59 60 We expect paypal credentials written down in a config file. The 61 path to this config file can be set with the ZCML `paypalconf` 62 directive, which is handled here and looks like this:: 63 64 <ikoba:paypalconf path='/some/path/to/paypal.conf' /> 65 66 This handler requires the given path to exist and to be a file. 67 68 If the file exists and is readable, a dict with ``path`` and other 69 values read from the configuration file is registered as a global 70 unnamed utility for the `IPayPalConfig` interface. 71 72 See :func:`waeup.ikoba.payments.paypal.configure_sdk for details 73 of the set dict. 74 """ 75 if not os.path.exists(path): 76 raise ConfigurationError("No such file: %s" % path) 77 if not os.path.isfile(path): 78 raise ConfigurationError("Not a regular file: %s" % path) 79 config_dict = configure_sdk(path) 80 return handler( 81 'registerUtility', config_dict, IPayPalConfig, '') 82 83 84 def paypal_conf(context, path): 85 """Handler for ZCML paypalconf directive. 86 87 This handler registers the `paypal_handler` above to perform the 88 real configuration action. 89 """ 90 context.action( 91 discriminator=('utility', IPayPalConfig, ''), 92 callable=paypal_handler, 93 args=(path, ) 94 )
Note: See TracChangeset for help on using the changeset viewer.