Merge lp:~bigkevmcd/landscape-client/218388-limit-free-space-messages into lp:~landscape/landscape-client/trunk

Proposed by Kevin McDermott
Status: Merged
Merge reported by: Kevin McDermott
Merged at revision: not available
Proposed branch: lp:~bigkevmcd/landscape-client/218388-limit-free-space-messages
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 115 lines (+74/-5)
2 files modified
landscape/monitor/mountinfo.py (+8/-3)
landscape/monitor/tests/test_mountinfo.py (+66/-2)
To merge this branch: bzr merge lp:~bigkevmcd/landscape-client/218388-limit-free-space-messages
Reviewer Review Type Date Requested Status
Thomas Herve (community) Approve
Free Ekanayaka (community) Approve
Review via email: mp+18251@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

This provides a hard limit on the number of free space items...

I picked a fairly arbitrary number to limit it to...

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Nice fix, +1!

[1]

+ MAX_FREE_SPACE_ITEMS_TO_EXCHANGE = 200
+

This is only about cosmetics, but in general I don't think we upper-case class attributes, even if meant to be constant (well, and that's a bit already implied by the fact that they are class attributes, or at least it should be a hint). So I'd suggest to lower-case it to max_free_space_items_to_exchange.

review: Approve
201. By Kevin McDermott

Change MAX_FREE_SPACE... to max_free_space... from Free's review.

Revision history for this message
Thomas Herve (therve) wrote :

Looks good, +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'landscape/monitor/mountinfo.py'
--- landscape/monitor/mountinfo.py 2009-10-06 16:27:23 +0000
+++ landscape/monitor/mountinfo.py 2010-01-29 12:20:31 +0000
@@ -12,6 +12,8 @@
1212
13 persist_name = "mount-info"13 persist_name = "mount-info"
1414
15 max_free_space_items_to_exchange = 200
16
15 def __init__(self, interval=300, monitor_interval=60*60,17 def __init__(self, interval=300, monitor_interval=60*60,
16 mounts_file="/proc/mounts", create_time=time.time,18 mounts_file="/proc/mounts", create_time=time.time,
17 statvfs=None, hal_manager=None, mtab_file="/etc/mtab"):19 statvfs=None, hal_manager=None, mtab_file="/etc/mtab"):
@@ -69,8 +71,12 @@
6971
70 def create_free_space_message(self):72 def create_free_space_message(self):
71 if self._free_space:73 if self._free_space:
72 message = {"type": "free-space", "free-space": self._free_space}74 items_to_exchange = self._free_space[
73 self._free_space = []75 :self.max_free_space_items_to_exchange]
76 message = {"type": "free-space",
77 "free-space": items_to_exchange}
78 self._free_space = self._free_space[
79 self.max_free_space_items_to_exchange:]
74 return message80 return message
75 return None81 return None
7682
@@ -214,4 +220,3 @@
214 if "bind" in options.split(","):220 if "bind" in options.split(","):
215 bound_points.add(mount_point)221 bound_points.add(mount_point)
216 return bound_points222 return bound_points
217
218223
=== modified file 'landscape/monitor/tests/test_mountinfo.py'
--- landscape/monitor/tests/test_mountinfo.py 2009-10-06 14:20:01 +0000
+++ landscape/monitor/tests/test_mountinfo.py 2010-01-29 12:20:31 +0000
@@ -240,8 +240,8 @@
240240
241 message = [d for d in messages if d["type"] == "free-space"][0]241 message = [d for d in messages if d["type"] == "free-space"][0]
242 free_space = message["free-space"]242 free_space = message["free-space"]
243 for i in range(1, 1):243 for i in range(len(free_space)):
244 self.assertEquals(free_space[i][0], i * step_size)244 self.assertEquals(free_space[i][0], (i + 1) * step_size)
245 self.assertEquals(free_space[i][1], "/")245 self.assertEquals(free_space[i][1], "/")
246 self.assertEquals(free_space[i][2], 409600)246 self.assertEquals(free_space[i][2], 409600)
247247
@@ -728,3 +728,67 @@
728 plugin.run()728 plugin.run()
729 message3 = plugin.create_mount_info_message()729 message3 = plugin.create_mount_info_message()
730 self.assertIdentical(message3, None)730 self.assertIdentical(message3, None)
731
732 def test_exchange_limits_exchanged_free_space_messages(self):
733 """
734 In order not to overload the server, the client should stagger the
735 exchange of free-space messages.
736 """
737 def statvfs(path):
738 return (4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0)
739
740 filename = self.makeFile("""\
741/dev/hda1 / ext3 rw 0 0
742""")
743 plugin = self.get_mount_info(mounts_file=filename, statvfs=statvfs,
744 create_time=self.reactor.time,
745 mtab_file=filename)
746 # Limit the test exchange to 5 items.
747 plugin.max_free_space_items_to_exchange = 5
748 step_size = self.monitor.step_size
749 self.monitor.add(plugin)
750
751 # Exchange should trigger a flush of the persist database
752 registry_mocker = self.mocker.replace(plugin.registry)
753 registry_mocker.flush()
754 self.mocker.result(None)
755 self.mocker.replay()
756
757 # Generate 10 data points
758 self.reactor.advance(step_size * 10)
759 self.monitor.exchange()
760
761 messages = self.mstore.get_pending_messages()
762 self.assertEquals(len(messages), 3)
763
764 message = [d for d in messages if d["type"] == "free-space"][0]
765 free_space = message["free-space"]
766 free_space_items = len(free_space)
767 self.assertEquals(free_space_items, 5)
768 for i in range(free_space_items):
769 self.assertEquals(free_space[i][0], (i + 1) * step_size)
770 self.assertEquals(free_space[i][1], "/")
771 self.assertEquals(free_space[i][2], 409600)
772
773 # The second exchange should pick up the remaining items.
774 self.mstore.delete_all_messages()
775 self.monitor.exchange()
776
777 messages = self.mstore.get_pending_messages()
778 self.assertEquals(len(messages), 1)
779
780 message = [d for d in messages if d["type"] == "free-space"][0]
781 free_space = message["free-space"]
782 free_space_items = len(free_space)
783 self.assertEquals(free_space_items, 5)
784 for i in range(free_space_items):
785 # Note (i+6) we've already retrieved the first 5 items.
786 self.assertEquals(free_space[i][0], (i + 6) * step_size)
787 self.assertEquals(free_space[i][1], "/")
788 self.assertEquals(free_space[i][2], 409600)
789
790 # Third exchange should not get any further free-space messages
791 self.mstore.delete_all_messages()
792 self.monitor.exchange()
793 messages = self.mstore.get_pending_messages()
794 self.assertEquals(len(messages), 0)

Subscribers

People subscribed via source and target branches

to all changes: