Commit e7816dd6 authored by Romain Courteaud's avatar Romain Courteaud

Desactivate public computer if it didn't contact for more than 10 minutes.

parent d053716e
...@@ -87,6 +87,9 @@ if can_allocate:\n ...@@ -87,6 +87,9 @@ if can_allocate:\n
can_allocate = False\n can_allocate = False\n
comment = \'Computer reported an error\'\n comment = \'Computer reported an error\'\n
# XXX TODO: compare creation date of #ok message\n # XXX TODO: compare creation date of #ok message\n
elif int(DateTime()) - int(DateTime(log_dict.get(\'created_at\'))) > 600:\n
can_allocate = False\n
comment = "Computer didn\'t contact for more than 10 minutes"\n
\n \n
if can_allocate:\n if can_allocate:\n
# Check the computer capacity.\n # Check the computer capacity.\n
......
...@@ -8,6 +8,7 @@ import json ...@@ -8,6 +8,7 @@ import json
from zExceptions import Unauthorized from zExceptions import Unauthorized
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.DateUtils import addToDate from Products.ERP5Type.DateUtils import addToDate
from App.Common import rfc1123_date
class TestSlapOSCorePromiseSlapOSModuleIdGeneratorAlarm(testSlapOSMixin): class TestSlapOSCorePromiseSlapOSModuleIdGeneratorAlarm(testSlapOSMixin):
def test_Module_assertIdGenerator(self): def test_Module_assertIdGenerator(self):
...@@ -1067,7 +1068,8 @@ class TestSlapOSUpdateComputerCapacityScopeAlarm(testSlapOSMixin): ...@@ -1067,7 +1068,8 @@ class TestSlapOSUpdateComputerCapacityScopeAlarm(testSlapOSMixin):
key_prefix='slap_tool', key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin') plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[self.computer.getReference()] = json.dumps({ memcached_dict[self.computer.getReference()] = json.dumps({
'text': '#access ok' 'text': '#access ok',
'created_at': rfc1123_date(DateTime())
}) })
transaction.commit() transaction.commit()
...@@ -1075,6 +1077,20 @@ class TestSlapOSUpdateComputerCapacityScopeAlarm(testSlapOSMixin): ...@@ -1075,6 +1077,20 @@ class TestSlapOSUpdateComputerCapacityScopeAlarm(testSlapOSMixin):
self.computer.Computer_checkAndUpdateCapacityScope() self.computer.Computer_checkAndUpdateCapacityScope()
self.assertEqual('open', self.computer.getCapacityScope()) self.assertEqual('open', self.computer.getCapacityScope())
def test_Computer_checkAndUpdateCapacityScope_with_old_access(self):
memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[self.computer.getReference()] = json.dumps({
'text': '#access ok',
'created_at': rfc1123_date(addToDate(DateTime(),
to_add={'minute': -11}))
})
self.computer.Computer_checkAndUpdateCapacityScope()
self.assertEqual('close', self.computer.getCapacityScope())
self.assertEqual("Computer didn't contact for more than 10 minutes",
self.computer.workflow_history['edit_workflow'][-1]['comment'])
def test_Computer_checkAndUpdateCapacityScope_no_capacity_quantity(self): def test_Computer_checkAndUpdateCapacityScope_no_capacity_quantity(self):
self._makeTree() self._makeTree()
self.computer.edit(capacity_quantity=1) self.computer.edit(capacity_quantity=1)
......
268 269
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment