Commit 74183ece authored by Rafael Monnerat's avatar Rafael Monnerat

SlapTool: Save reported state on a property rather them on the message

  This allow us define if the instance is failing to change state (start/stop) or failing after started or stopped
parent 9e8062e6
......@@ -477,6 +477,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(computer_id)s</string>
<string>user</string>
......@@ -523,6 +525,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#access %(computer_id)s</string>
<string>user</string>
......@@ -574,6 +578,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error bang</string>
<string>user</string>
......@@ -659,6 +665,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(reference)s</string>
<string>user</string>
......@@ -725,6 +733,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string>available</string>
<string>text</string>
<string>#access software release %(url_string)s available</string>
<string>user</string>
......@@ -768,6 +778,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string>building</string>
<string>text</string>
<string>#building software release %(url_string)s</string>
<string>user</string>
......@@ -811,6 +823,8 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error while installing %(url_string)s</string>
<string>user</string>
......@@ -1146,6 +1160,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(instance_guid)s</string>
<string>user</string>
......@@ -1193,6 +1209,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(instance_guid)s</string>
<string>user</string>
......@@ -1561,6 +1579,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error while instanciating: The error</string>
<string>user</string>
......@@ -1603,6 +1623,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error while instanciating: The error</string>
<string>user</string>
......@@ -1647,6 +1669,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error while instanciating: The error</string>
<string>user</string>
......@@ -1701,6 +1725,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error bang called</string>
<string>user</string>
......@@ -1980,6 +2006,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string>stopped</string>
<string>text</string>
<string>#access Instance correctly stopped</string>
<string>user</string>
......@@ -2021,6 +2049,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string>started</string>
<string>text</string>
<string>#access Instance correctly started</string>
<string>user</string>
......@@ -2262,6 +2292,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(computer_id)s</string>
<string>user</string>
......@@ -2308,6 +2340,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#access %(computer_id)s</string>
<string>user</string>
......@@ -2358,6 +2392,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error bang</string>
<string>user</string>
......@@ -2409,6 +2445,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(instance_guid)s</string>
<string>user</string>
......@@ -2458,6 +2496,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error no data found for %(instance_guid)s</string>
<string>user</string>
......@@ -2763,6 +2803,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>state</string>
<string/>
<string>text</string>
<string>#error bang called</string>
<string>user</string>
......
......@@ -861,7 +861,7 @@ class SlapTool(BaseTool):
####################################################
def _logAccess(self, user_reference, context_reference, text):
def _logAccess(self, user_reference, context_reference, text, state=""):
memcached_dict = self.Base_getSlapToolMemcachedDict()
previous = self._getCachedAccessInfo(context_reference)
......@@ -872,13 +872,16 @@ class SlapTool(BaseTool):
if text.split(" ")[0] == previous_json.get("text", "").split(" ")[0]:
since = previous_json.get("since",
previous_json.get("created_at", rfc1123_date(DateTime())))
if state == "":
state = previous_json.get("state", "")
value = json.dumps({
'user': '%s' % user_reference,
'created_at': '%s' % created_at,
'text': '%s' % text,
'since': '%s' % since
'since': '%s' % since,
'state': state
})
memcached_dict[context_reference] = value
......@@ -999,7 +1002,7 @@ class SlapTool(BaseTool):
user = self.getPortalObject().portal_membership.\
getAuthenticatedMember().getUserName()
self._logAccess(user, software_installation_reference,
'#building software release %s' % url)
'#building software release %s' % url, "building")
@convertToREST
def _availableSoftwareRelease(self, url, computer_id):
......@@ -1012,7 +1015,7 @@ class SlapTool(BaseTool):
user = self.getPortalObject().portal_membership.\
getAuthenticatedMember().getUserName()
self._logAccess(user, software_installation_reference,
'#access software release %s available' % url)
'#access software release %s available' % url, "available")
@convertToREST
def _destroyedSoftwareRelease(self, url, computer_id):
......@@ -1117,6 +1120,7 @@ class SlapTool(BaseTool):
"user": "SlapOS Master",
'created_at': '%s' % last_modified,
'since': '%s' % last_modified,
'state': "",
"text": "#error no data found"
}
else:
......@@ -1124,6 +1128,7 @@ class SlapTool(BaseTool):
"user": "SlapOS Master",
'created_at': '%s' % last_modified,
'since': '%s' % last_modified,
'state': "",
"text": "#error no data found for %s" % context_reference
}
# Prepare for xml marshalling
......@@ -1154,7 +1159,7 @@ class SlapTool(BaseTool):
user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
self._logAccess(user, instance.getReference(),
'#access Instance correctly started')
'#access Instance correctly started', "started")
@convertToREST
def _stoppedComputerPartition(self, computer_id, computer_partition_id):
......@@ -1167,7 +1172,7 @@ class SlapTool(BaseTool):
user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
self._logAccess(user, instance.getReference(),
'#access Instance correctly stopped')
'#access Instance correctly stopped', "stopped")
@convertToREST
def _destroyedComputerPartition(self, computer_id, computer_partition_id):
......
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