Merge lp:~verterok/ubuntuone-client/really-disable-throttling into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Nicola Larosa
Approved revision: 278
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/really-disable-throttling
Merge into: lp:ubuntuone-client
Diff against target: 126 lines (+75/-12)
2 files modified
tests/syncdaemon/test_config.py (+64/-0)
ubuntuone/syncdaemon/dbus_interface.py (+11/-12)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/really-disable-throttling
Reviewer Review Type Date Requested Status
Nicola Larosa (community) Approve
Rick McBride (community) Approve
Review via email: mp+14908@code.launchpad.net

Commit message

Fix syncdaemon exposed DBus Config.disable_bandwidth_throttling method

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Fix a silly bug in Syncdaemon DBus Config exposed method to disable bandwidth throttling.

278. By Guillermo Gonzalez

fix typo s/thorttling/throttling/

Revision history for this message
Rick McBride (rmcbride) wrote :

Looks good, thanks for fixing the self._set_thorttling_enabled stuff. Autocompletion kept it consistent anyhow :)

review: Approve
Revision history for this message
Nicola Larosa (teknico) wrote :

Wow, hideous bug. Thanks for the tests too.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_config.py'
2--- tests/syncdaemon/test_config.py 2009-11-06 19:31:17 +0000
3+++ tests/syncdaemon/test_config.py 2009-11-17 21:45:22 +0000
4@@ -31,6 +31,7 @@
5 )
6 from contrib.testing.testcase import (
7 BaseTwistedTestCase,
8+ DBusTwistedTestCase,
9 )
10
11
12@@ -293,3 +294,66 @@
13 self.assertEquals('/hola', parser(bad_value))
14 self.assertRaises(AttributeError, parser, invalid_value)
15
16+
17+class TestDBusConfig(DBusTwistedTestCase):
18+
19+ def setUp(self):
20+ """Fake the user_config file, and setup all SD stuff"""
21+ self.old_get_config_files = config.get_config_files
22+ config.get_config_files = lambda: [os.path.join(os.environ['ROOT_DIR'],
23+ 'data', 'syncdaemon.conf')]
24+ return DBusTwistedTestCase.setUp(self)
25+
26+ def tearDown(self):
27+ """cleanup everything, also the config module globals"""
28+ config._user_config = None
29+ config.get_config_files = self.old_get_config_files
30+ return DBusTwistedTestCase.tearDown(self)
31+
32+ def test_get_throttling_limits(self):
33+ """Test getting throttling limits"""
34+ dbus_config = self.main.dbus_iface.config
35+ limits = dbus_config.get_throttling_limits()
36+ self.assertEquals(limits['download'], -1)
37+ self.assertEquals(limits['upload'], -1)
38+
39+ def test_set_throttling_limits(self):
40+ """Test setting throttling limits"""
41+ dbus_config = self.main.dbus_iface.config
42+ dbus_config.set_throttling_limits(10, 20)
43+ limits = dbus_config.get_throttling_limits()
44+ self.assertEquals(limits['download'], 10)
45+ self.assertEquals(limits['upload'], 20)
46+ conf = ConfigParser()
47+ conf.read(config.get_user_config().config_file)
48+ self.assertEquals(conf.get(config.THROTTLING, 'read_limit'), '10')
49+ self.assertEquals(conf.get(config.THROTTLING, 'write_limit'), '20')
50+
51+ def test_enable_bandwidth_throttling(self):
52+ """Test for enabling bandwidth throttling"""
53+ dbus_config = self.main.dbus_iface.config
54+ enabled = dbus_config.bandwidth_throttling_enabled()
55+ self.assertFalse(enabled)
56+ dbus_config.enable_bandwidth_throttling()
57+ enabled = dbus_config.bandwidth_throttling_enabled()
58+ self.assertTrue(enabled)
59+ conf = ConfigParser()
60+ conf.read(config.get_user_config().config_file)
61+ self.assertEquals(conf.get(config.THROTTLING, 'on'), 'True')
62+
63+ def test_disable_bandwidth_throttling(self):
64+ """Test for disabling bandwidth throttling"""
65+ dbus_config = self.main.dbus_iface.config
66+ enabled = dbus_config.bandwidth_throttling_enabled()
67+ self.assertFalse(enabled)
68+ # enable throttling
69+ dbus_config.enable_bandwidth_throttling()
70+ enabled = dbus_config.bandwidth_throttling_enabled()
71+ self.assertTrue(enabled)
72+ # now disable throttling and check
73+ dbus_config.disable_bandwidth_throttling()
74+ enabled = dbus_config.bandwidth_throttling_enabled()
75+ self.assertFalse(enabled)
76+ conf = ConfigParser()
77+ conf.read(config.get_user_config().config_file)
78+ self.assertEquals(conf.get(config.THROTTLING, 'on'), 'False')
79
80=== modified file 'ubuntuone/syncdaemon/dbus_interface.py'
81--- ubuntuone/syncdaemon/dbus_interface.py 2009-10-28 17:00:50 +0000
82+++ ubuntuone/syncdaemon/dbus_interface.py 2009-11-17 21:45:23 +0000
83@@ -889,12 +889,7 @@
84 error_handler=None):
85 """Enable bandwidth throttling."""
86 try:
87- # modify and save the config file
88- config = get_user_config()
89- config.set_throttling(True)
90- config.save()
91- # modify AQ settings
92- self.dbus_iface.action_queue.enable_throttling(True)
93+ self._set_throttling_enabled(True)
94 if reply_handler:
95 reply_handler()
96 # pylint: disable-msg=W0703
97@@ -911,12 +906,7 @@
98 error_handler=None):
99 """Disable bandwidth throttling."""
100 try:
101- # modify and save the config file
102- config = get_user_config()
103- config.set_throttling(True)
104- config.save()
105- # modify AQ settings
106- self.dbus_iface.action_queue.enable_throttling(False)
107+ self._set_throttling_enabled(False)
108 if reply_handler:
109 reply_handler()
110 # pylint: disable-msg=W0703
111@@ -926,6 +916,15 @@
112 else:
113 raise
114
115+ def _set_throttling_enabled(self, enabled):
116+ """set throttling enabled value and save the config"""
117+ # modify and save the config file
118+ config = get_user_config()
119+ config.set_throttling(enabled)
120+ config.save()
121+ # modify AQ settings
122+ self.dbus_iface.action_queue.enable_throttling(enabled)
123+
124 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
125 in_signature='', out_signature='b',
126 async_callbacks=('reply_handler', 'error_handler'))

Subscribers

People subscribed via source and target branches