Merge lp:~doanac/utah/mir-bug into lp:utah

Proposed by Andy Doan
Status: Merged
Merged at revision: 974
Proposed branch: lp:~doanac/utah/mir-bug
Merge into: lp:utah
Diff against target: 65 lines (+42/-0)
2 files modified
tests/test_rsyslog.py (+38/-0)
utah/provisioning/rsyslog.py (+4/-0)
To merge this branch: bzr merge lp:~doanac/utah/mir-bug
Reviewer Review Type Date Requested Status
UTAH Dev Pending
Review via email: mp+176545@code.launchpad.net

Description of the change

This fixes a subtle problem with our fast-forward logic in the rsyslog module

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

The changes look good and the test cases work.

Just for my own curiosity, I tried to check that the changes were not needed if the pattern are just strings (which are converted to arrays internally), but that didn't work. Shouldn't that have worked?

=== modified file 'tests/test_rsyslog.py'
--- tests/test_rsyslog.py 2013-07-23 22:21:19 +0000
+++ tests/test_rsyslog.py 2013-07-24 16:55:22 +0000
@@ -162,16 +162,16 @@
         steps = [
             {
                 "message": "test_future",
- "pattern": [".*"],
+ "pattern": ".*",
                 "booted": True,
             },
             {
                 "message": "hit skipped",
- "pattern": ["hit skipped"],
+ "pattern": "hit skipped",
             },
             {
                 "message": "this will hit step three",
- "pattern": [".*this will hit step three"],
+ "pattern": ".*this will hit step three",
             },
         ]

=== modified file 'utah/provisioning/rsyslog.py'
--- utah/provisioning/rsyslog.py 2013-07-23 22:21:19 +0000
+++ utah/provisioning/rsyslog.py 2013-07-24 16:53:14 +0000
@@ -216,12 +216,8 @@

                 if not isinstance(pattern, list):
                     pattern = [pattern]
- else:
- pattern = pattern[:] # create a copy so we don't alter
                 if not isinstance(fail_pattern, list):
                     fail_pattern = [fail_pattern]
- else:
- fail_pattern = fail_pattern[:]
                 pattern.extend(fail_pattern)
                 future_pats = self._future_patterns(steps, x)
                 pattern.extend(future_pats)

Revision history for this message
Andy Doan (doanac) wrote :

On 07/24/2013 11:59 AM, Javier Collado wrote:
> Just for my own curiosity, I tried to check that the changes were not needed if the pattern are just strings (which are converted to arrays internally), but that didn't work. Shouldn't that have worked?

hmm- that type test fails when I run it at home?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_rsyslog.py'
2--- tests/test_rsyslog.py 2013-06-24 21:56:46 +0000
3+++ tests/test_rsyslog.py 2013-07-23 22:47:23 +0000
4@@ -157,6 +157,44 @@
5
6 self.assertTrue(self.test_future_booted, 'booted callback not made')
7
8+ def test_future_array(self):
9+ """Test handling a missing message if the pattern is an array."""
10+ steps = [
11+ {
12+ "message": "test_future",
13+ "pattern": [".*"],
14+ "booted": True,
15+ },
16+ {
17+ "message": "hit skipped",
18+ "pattern": ["hit skipped"],
19+ },
20+ {
21+ "message": "this will hit step three",
22+ "pattern": [".*this will hit step three"],
23+ },
24+ ]
25+
26+ messages = [
27+ 'this will hit step one',
28+ 'this will hit step three',
29+ ]
30+
31+ r = RSyslog("utah-test", self.logdir)
32+ threading.Thread(target=self.producer, args=(r.port, messages)).start()
33+
34+ def booted_cb(match):
35+ self.test_future_booted = True
36+
37+ self.test_future_booted = False
38+ with patch.object(r.logger, 'warn') as mock_method:
39+ r._wait_for_steps(steps, 5, self.logfile, {'booted': booted_cb})
40+ mock_method.assert_called_with(
41+ 'Expected pattern missed, matched future pattern: %s',
42+ steps[2]['pattern'][0])
43+
44+ self.assertTrue(self.test_future_booted, 'booted callback not made')
45+
46 def test_callbacks(self):
47 """Make sure wait_for_steps works."""
48 steps = [
49
50=== modified file 'utah/provisioning/rsyslog.py'
51--- utah/provisioning/rsyslog.py 2013-06-12 17:14:15 +0000
52+++ utah/provisioning/rsyslog.py 2013-07-23 22:47:23 +0000
53@@ -216,8 +216,12 @@
54
55 if not isinstance(pattern, list):
56 pattern = [pattern]
57+ else:
58+ pattern = pattern[:] # create a copy so we don't alter
59 if not isinstance(fail_pattern, list):
60 fail_pattern = [fail_pattern]
61+ else:
62+ fail_pattern = fail_pattern[:]
63 pattern.extend(fail_pattern)
64 future_pats = self._future_patterns(steps, x)
65 pattern.extend(future_pats)

Subscribers

People subscribed via source and target branches

to all changes: