Merge lp:~nataliabidart/ubuntuone-client/better-info-logs-stable-1-2 into lp:ubuntuone-client/stable-1-2

Proposed by Natalia Bidart on 2010-05-11
Status: Merged
Approved by: Natalia Bidart on 2010-05-18
Approved revision: 508
Merged at revision: 510
Proposed branch: lp:~nataliabidart/ubuntuone-client/better-info-logs-stable-1-2
Merge into: lp:ubuntuone-client/stable-1-2
Diff against target: 187 lines (+92/-11) 4 files modified
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/better-info-logs-stable-1-2
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve on 2010-05-12
Tim Cole (community) 2010-05-11 Approve on 2010-05-11
Review via email: mp+25101@code.launchpad.net

Commit Message

Improving logging when performing delete actions.

Description of the Change

Improving logging when performing delete actions.

To post a comment you must log in.
Tim Cole (tcole) :
review: Approve
Rick McBride (rmcbride) :
review: Approve

Preview Diff

1=== modified file 'tests/syncdaemon/test_eq_inotify.py'
2--- tests/syncdaemon/test_eq_inotify.py 2010-03-26 15:58:49 +0000
3+++ tests/syncdaemon/test_eq_inotify.py 2010-05-11 20:54:28 +0000
4@@ -221,6 +221,12 @@
5 def setUp(self):
6 """Setup the test."""
7 BaseEQTestCase.setUp(self)
8+
9+ # add a Memento handler to the logger
10+ self.handler = testcase.MementoHandler()
11+ self.handler.setLevel(logging.INFO)
12+ self.eq.log.addHandler(self.handler)
13+
14 # create the deferred for the tests
15 self._deferred = defer.Deferred()
16
17@@ -366,8 +372,17 @@
18 def handle_FS_FILE_DELETE(innerself, path):
19 if path != testfile:
20 self.finished_error("received a wrong path")
21- else:
22- self.finished_ok()
23+ return
24+
25+ check = len(self.handler.records) == 1 and \
26+ 'FS_FILE_DELETE' in self.handler.records[0].message and\
27+ testfile in self.handler.records[0].message and \
28+ self.handler.records[0].levelno == logging.INFO
29+ if not check:
30+ self.finished_error("FS_FILE_DELETE must appear in INFO.")
31+ return
32+
33+ self.finished_ok()
34
35 self.eq.inotify_add_watch(self.root_dir)
36 self.eq.subscribe(HitMe())
37@@ -387,8 +402,17 @@
38 def handle_FS_DIR_DELETE(innerself, path):
39 if path != testdir:
40 self.finished_error("received a wrong path")
41- else:
42- self.finished_ok()
43+ return
44+
45+ check = len(self.handler.records) == 1 and \
46+ 'FS_DIR_DELETE' in self.handler.records[0].message and\
47+ testdir in self.handler.records[0].message and \
48+ self.handler.records[0].levelno == logging.INFO
49+ if not check:
50+ self.finished_error("FS_DIR_DELETE must appear in INFO.")
51+ return
52+
53+ self.finished_ok()
54
55 self.eq.inotify_add_watch(self.root_dir)
56 self.eq.subscribe(HitMe())
57
58=== modified file 'tests/syncdaemon/test_sync.py'
59--- tests/syncdaemon/test_sync.py 2010-04-23 15:23:09 +0000
60+++ tests/syncdaemon/test_sync.py 2010-05-11 20:54:28 +0000
61@@ -33,8 +33,10 @@
62 MementoHandler, DummyClass
63 )
64
65+from contrib.testing import testcase
66 from ubuntuone.syncdaemon.dbus_interface import DBusInterface
67 from ubuntuone.syncdaemon.filesystem_manager import FileSystemManager
68+from ubuntuone.syncdaemon.fsm import fsm as fsm_module
69 from ubuntuone.syncdaemon.main import Main
70 from ubuntuone.syncdaemon.sync import FSKey, Sync, SyncStateMachineRunner
71 from ubuntuone.syncdaemon.volume_manager import Share
72@@ -303,3 +305,53 @@
73
74 self.ssmr.delete_file(event='AQ_DOWNLOAD_ERROR', params=None,
75 server_hash='')
76+
77+class FakedState(object):
78+ """A faked state."""
79+
80+ def __init__(self, action_func):
81+ self.action_func = action_func
82+ self.values = []
83+
84+ def get_transition(self, event_name, parameters):
85+ """A fake get_transition."""
86+ class A(object): pass
87+ result = A()
88+ result.action_func = self.action_func
89+ result.target = self.values
90+ return result
91+
92+
93+class StateMachineRunnerTestCase(BaseTwistedTestCase):
94+ """Test suite for StateMachineRunner."""
95+
96+ def setUp(self):
97+ """Init."""
98+ BaseTwistedTestCase.setUp(self)
99+
100+ logger = logging.getLogger('ubuntuone.SyncDaemon.sync')
101+ self.smr = fsm_module.StateMachineRunner(None, logger)
102+ self.handler = testcase.MementoHandler()
103+ self.handler.setLevel(logging.INFO)
104+ logger.addHandler(self.handler)
105+
106+ def test_on_event_logs_info(self):
107+ """Test proper logging in on_event."""
108+ event_name = 'TEST_EVENT'
109+ parameters = object()
110+ action_func = 'SOME_ACTION_FUNC'
111+ setattr(self.smr, action_func, lambda *_: None)
112+ self.patch(self.smr, 'get_state', lambda: FakedState(action_func))
113+ self.smr.on_event(event_name=event_name, parameters=parameters)
114+
115+ # assert over logging
116+ self.assertTrue(len(self.handler.records), 1)
117+
118+ record = self.handler.records[0]
119+ self.assertEqual(record.levelno, logging.INFO)
120+
121+ msg = record.message
122+ error = '%s must be in record.message (%s)'
123+ self.assertTrue(event_name in msg, error % (event_name, msg))
124+ self.assertTrue(str(parameters) in msg, error % (parameters, msg))
125+ self.assertTrue(action_func in msg, error % (action_func, msg))
126
127=== modified file 'ubuntuone/syncdaemon/event_queue.py'
128--- ubuntuone/syncdaemon/event_queue.py 2010-04-12 17:58:20 +0000
129+++ ubuntuone/syncdaemon/event_queue.py 2010-05-11 20:54:28 +0000
130@@ -577,7 +577,7 @@
131 return False
132
133 def handle_dir_delete(self, fullpath):
134- """ handle the case of move a dir to a non-watched directory """
135+ """Handle the case of move a dir to a non-watched directory."""
136 paths = self.eq.fs.get_paths_starting_with(fullpath,
137 include_base=False)
138 paths.sort(reverse=True)
139@@ -739,8 +739,13 @@
140 The signature for each event is forced on each method, not in this
141 'push' arguments.
142 """
143- self.log.debug("push_event: %s, args:%s, kw:%s",
144- event_name, args, kwargs)
145+ log_msg = "push_event: %s, args:%s, kw:%s"
146+ if event_name.endswith('DELETE'):
147+ # log every DELETE in INFO level
148+ self.log.info(log_msg, event_name, args, kwargs)
149+ else:
150+ self.log.debug(log_msg, event_name, args, kwargs)
151+
152 # get the event parameters
153 try:
154 event_params = EVENTS[event_name]
155
156=== modified file 'ubuntuone/syncdaemon/fsm/fsm.py'
157--- ubuntuone/syncdaemon/fsm/fsm.py 2010-01-22 17:25:09 +0000
158+++ ubuntuone/syncdaemon/fsm/fsm.py 2010-05-11 20:54:28 +0000
159@@ -131,7 +131,8 @@
160 self.log.debug("passing")
161 else:
162 # pylint: disable-msg=W0703
163- self.log.debug("Calling %s"%action_func_name)
164+ self.log.info("Calling %s (got %s:%s)",
165+ action_func_name, event_name, parameters)
166 try:
167 af(event_name, parameters, *args)
168 except Exception, e:
169@@ -158,7 +159,7 @@
170 enter_state.values, event_name, parameters,
171 out_state.values, transition.target))
172 raise ValueError("Incorrect out state")
173- self.log.debug("Called %s"%action_func_name)
174+ self.log.debug("Called %s", action_func_name)
175 return action_func_name
176
177 def get_state(self):
178@@ -193,8 +194,7 @@
179 # fsm_parser depends on python-uno for reading ods documents
180 # this shouldnt be called with an .ods file on production
181 # environments
182- from ubuntuone.syncdaemon.fsm import \
183- fsm_parser
184+ from ubuntuone.syncdaemon.fsm import fsm_parser
185 spec = fsm_parser.parse(input_data)
186 elif input_data.endswith(".py"):
187 result = {}

Subscribers

People subscribed via source and target branches