Merge lp:~gz/juju-ci-tools/recovery_detect_correct_1638893 into lp:juju-ci-tools

Proposed by Martin Packman
Status: Merged
Merged at revision: 1707
Proposed branch: lp:~gz/juju-ci-tools/recovery_detect_correct_1638893
Merge into: lp:juju-ci-tools
Diff against target: 58 lines (+32/-1)
2 files modified
assess_recovery.py (+3/-1)
tests/test_assess_recovery.py (+29/-0)
To merge this branch: bzr merge lp:~gz/juju-ci-tools/recovery_detect_correct_1638893
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Curtis Hovey (community) code Approve
Review via email: mp+309940@code.launchpad.net

Commit message

Fix assess_recovery log collection failure when status fails

Description of the change

Values in the known_hosts dict must be addresses. The detect_bootstrap_machine function in assess_recovery.py could set the address of machine 0 as 'None' which would break log collection (and then controller teardown) on a particular error path.

This branch adds test coverage and does not assign to known_hosts if no address is present. I think, but am not certain, that this is what we want over also clearing an existing 0 address in this case.

Also have the option of defending against a known_hosts dict with bad values in the log collection code, I feel it's better to just hold callers to passing correct data.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)
Revision history for this message
Aaron Bentley (abentley) wrote :

Thanks. This seems to fix the specific bug, but there is a class of bugs where dump_all_logs raises an exception, and we should also address that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_recovery.py'
2--- assess_recovery.py 2016-10-22 02:03:03 +0000
3+++ assess_recovery.py 2016-11-03 12:39:42 +0000
4@@ -151,7 +151,9 @@
5 try:
6 yield
7 except Exception as e:
8- bs_manager.known_hosts['0'] = parse_new_state_server_from_error(e)
9+ address = parse_new_state_server_from_error(e)
10+ if address is not None:
11+ bs_manager.known_hosts['0'] = address
12 raise
13
14
15
16=== modified file 'tests/test_assess_recovery.py'
17--- tests/test_assess_recovery.py 2016-10-22 02:03:03 +0000
18+++ tests/test_assess_recovery.py 2016-11-03 12:39:42 +0000
19@@ -11,6 +11,7 @@
20 assess_recovery,
21 check_token,
22 delete_controller_members,
23+ detect_bootstrap_machine,
24 main,
25 parse_args,
26 restore_missing_state_server,
27@@ -322,3 +323,31 @@
28 side_effect=['1', '0']):
29 with self.assertRaises(JujuAssertionError):
30 check_token(client, 'foo')
31+
32+
33+class TestDetectBootstrapMachine(TestCase):
34+
35+ def test_no_error(self):
36+ fake_manager = object()
37+ with detect_bootstrap_machine(fake_manager):
38+ pass
39+
40+ def test_error_with_address(self):
41+ fake_manager = Mock(spec_set=['known_hosts'])
42+ fake_manager.known_hosts = {}
43+ error = Exception('Attempting to connect to 127.0.0.1:22')
44+ with self.assertRaises(Exception) as ctx:
45+ with detect_bootstrap_machine(fake_manager):
46+ raise error
47+ self.assertIs(ctx.exception, error)
48+ self.assertEqual(fake_manager.known_hosts, {'0': '127.0.0.1'})
49+
50+ def test_error_without_address(self):
51+ fake_manager = Mock(spec_set=['known_hosts'])
52+ fake_manager.known_hosts = {}
53+ error = Exception('Some other error')
54+ with self.assertRaises(Exception) as ctx:
55+ with detect_bootstrap_machine(fake_manager):
56+ raise error
57+ self.assertIs(ctx.exception, error)
58+ self.assertEqual(fake_manager.known_hosts, {})

Subscribers

People subscribed via source and target branches