Merge lp:~al-maisan/landscape-client/missing-context into lp:~landscape/landscape-client/trunk

Proposed by Muharem Hrnjadovic
Status: Merged
Approved by: Jamu Kakar
Approved revision: 300
Merged at revision: 298
Proposed branch: lp:~al-maisan/landscape-client/missing-context
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 111 lines (+39/-10)
2 files modified
landscape/broker/exchange.py (+3/-4)
landscape/broker/tests/test_exchange.py (+36/-6)
To merge this branch: bzr merge lp:~al-maisan/landscape-client/missing-context
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
Free Ekanayaka (community) Approve
Review via email: mp+38939@code.launchpad.net

Description of the change

This branch introduces the following change: response messages to the server for which no message context could be found are considered obsolete and dropped (as opposed to being sent).

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Thanks for looking into this Muharem.

This is a reasonable workaround, and probably a fix that should be landed regardless of the attached bug. However we should also try to understand what happened exactly that led to this situation. I'll try to do that as a brain break.

+1!

review: Approve
Revision history for this message
Jamu Kakar (jkakar) wrote :

This looks fine I think. I'm slightly concerned about it, because it
may hide bugs in the future, but I think it's probably okay, +1.

review: Approve
Revision history for this message
Jamu Kakar (jkakar) wrote :

I wonder if it'd be better to report back to the server that the
operation is not understandable by the client...? Or maybe even to
just report that the operation-id was discarded so that we have this
information and can monitor how often it happens.

Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

On 10/21/2010 10:32 PM, Jamu Kakar wrote:
> I wonder if it'd be better to report back to the server that the
> operation is not understandable by the client...? Or maybe even to
> just report that the operation-id was discarded so that we have this
> information and can monitor how often it happens.
>
That's a good idea, I have filed bug
https://bugs.edge.launchpad.net/landscape-client/+bug/665005

Best regards

--
Muharem Hrnjadovic <email address hidden>
Public key id : B2BBFCFC
Key fingerprint : A5A3 CC67 2B87 D641 103F 5602 219F 6B60 B2BB FCFC

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/exchange.py'
2--- landscape/broker/exchange.py 2010-04-30 10:36:51 +0000
3+++ landscape/broker/exchange.py 2010-10-20 14:34:40 +0000
4@@ -23,7 +23,7 @@
5
6 def __init__(self, reactor, store, transport, registration_info,
7 exchange_store,
8- exchange_interval=60*60,
9+ exchange_interval=60 * 60,
10 urgent_exchange_interval=10,
11 monitor_interval=None,
12 max_messages=100,
13@@ -80,7 +80,7 @@
14 logging.warning(
15 "No message context for message with operation-id: %s"
16 % operation_id)
17- return False
18+ return True
19
20 # Compare the current secure ID with the one that was in effect when
21 # the request message was received.
22@@ -99,8 +99,7 @@
23 """
24 if self._message_is_obsolete(message):
25 logging.info(
26- "Response message with operation-id %s was discarded "
27- "because the client's secure ID has changed in the meantime"
28+ "Obsolete response message with operation-id %s was discarded."
29 % message.get('operation-id'))
30 return None
31
32
33=== modified file 'landscape/broker/tests/test_exchange.py'
34--- landscape/broker/tests/test_exchange.py 2010-04-30 16:14:09 +0000
35+++ landscape/broker/tests/test_exchange.py 2010-10-20 14:34:40 +0000
36@@ -240,6 +240,7 @@
37 self.mstore.add({"type": "data", "data": 2})
38 self.mstore.add({"type": "data", "data": 3})
39 # next one, server will respond with 1!
40+
41 def desynched_send_data(payload, computer_id=None, message_api=None):
42 self.transport.next_expected_sequence = 1
43 return {"next-expected-sequence": 1}
44@@ -303,7 +304,7 @@
45 self.wait_for_exchange(urgent=True)
46 self.assertEquals(len(self.transport.payloads), 1)
47 self.wait_for_exchange(urgent=True)
48- self.assertEquals(len(self.transport.payloads), 1) # no change
49+ self.assertEquals(len(self.transport.payloads), 1) # no change
50
51 def test_ancient_causes_resynchronize(self):
52 """
53@@ -569,9 +570,9 @@
54 # schedule a regular exchange.
55 # Let's make sure that that *original* impending-exchange event has
56 # been cancelled:
57- self.reactor.advance(60 * 60 # time till exchange
58- - 10 # time till notification
59- - 20) # time that we've already advanced
60+ self.reactor.advance(60 * 60 # time till exchange
61+ - 10 # time till notification
62+ - 20) # time that we've already advanced
63 self.assertEquals(events, [True])
64 # Ok, so no new events means that the original call was
65 # cancelled. great.
66@@ -846,8 +847,8 @@
67 self.assertEquals([], messages)
68 self.assertIs(None, message_id)
69 expected_log_entry = (
70- "Response message with operation-id 234567 was discarded because "
71- "the client's secure ID has changed in the meantime")
72+ "Obsolete response message with operation-id 234567 was "
73+ "discarded.")
74 self.assertTrue(expected_log_entry in self.logfile.getvalue())
75
76 # The MessageContext was removed after utilisation.
77@@ -855,6 +856,35 @@
78 self.assertTrue(len(ids_after) == len(ids_before) - 1)
79 self.assertFalse('234567' in ids_after)
80
81+ def test_response_messages_without_context_are_discarded(self):
82+ """
83+ A response message for which no incoming message context could be
84+ found will be discarded as opposed to being sent to the server.
85+ """
86+ # Receive the message below from the server.
87+ msg = {"type": "type-R", "whatever": 5678, "operation-id": 234567}
88+ server_message = [msg]
89+ self.transport.responses.append(server_message)
90+ self.exchanger.exchange()
91+
92+ # Remove the message context so that the response message gets
93+ # discarded.
94+ self.exchange_store.get_message_context(msg['operation-id']).remove()
95+ self.assertFalse('234567' in self.exchange_store.all_operation_ids())
96+
97+ self.mstore.set_accepted_types(["resynchronize"])
98+ message_id = self.exchanger.send(
99+ {"type": "resynchronize", "operation-id": 234567})
100+ self.exchanger.exchange()
101+ self.assertEquals(2, len(self.transport.payloads))
102+ messages = self.transport.payloads[1]["messages"]
103+ self.assertEquals([], messages)
104+ self.assertIs(None, message_id)
105+ expected_log_entry = (
106+ "Obsolete response message with operation-id 234567 was "
107+ "discarded.")
108+ self.assertTrue(expected_log_entry in self.logfile.getvalue())
109+
110
111 class AcceptedTypesMessageExchangeTest(LandscapeTest):
112

Subscribers

People subscribed via source and target branches

to all changes: