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

Proposed by Martin Packman
Status: Merged
Merged at revision: 1270
Proposed branch: lp:~gz/juju-ci-tools/restore_assess_debug_log
Merge into: lp:juju-ci-tools
Diff against target: 141 lines (+47/-12)
4 files modified
assess_log_rotation.py (+16/-0)
jujupy.py (+1/-1)
tests/test_assess_log_rotation.py (+27/-9)
tests/test_jujupy.py (+3/-2)
To merge this branch: bzr merge lp:~gz/juju-ci-tools/restore_assess_debug_log
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+285775@code.launchpad.net

Description of the change

Restore r1184 without assess_log_rotation addition

Code was useful and worth having in tree, even if we don't enable the additional testing. Also includes a bug fix for get_juju_output I want.

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

Thank you. I have a suggestion inline.

review: Approve (code)
1265. By Martin Packman

Change test_debug_log as suggested by sinzui in review

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_log_rotation.py'
2--- assess_log_rotation.py 2016-01-12 16:14:17 +0000
3+++ assess_log_rotation.py 2016-02-12 22:33:29 +0000
4@@ -32,14 +32,30 @@
5 super(LogRotateError, self).__init__(message)
6
7
8+def test_debug_log(client, timeout=180, lines=100):
9+ """After doing log rotation, we should be able to see debug-log output."""
10+ out = client.get_juju_output("debug-log", "--lines={}".format(lines),
11+ "--limit={}".format(lines), timeout=timeout)
12+ content = out.splitlines()
13+ if len(content) != lines:
14+ raise LogRotateError("We expected {} lines of output, got {}".format(
15+ lines, len(content)))
16+
17+
18 def test_unit_rotation(client):
19 """Tests unit log rotation."""
20+ # TODO: as part of testing that when a unit sending lots of logs triggers
21+ # unit log rotation, we should also test that all-machines.log and future
22+ # logsink.log get rotated.
23+ # It would also be possible to test that the logs database doesn't grow too
24+ # large.
25 test_rotation(client,
26 "/var/log/juju/unit-fill-logs-0.log",
27 "unit-fill-logs-0",
28 "fill-unit",
29 "unit-size",
30 "megs=300")
31+ # TODO: either call test_debug_log here or add a new assess entry for it.
32
33
34 def test_machine_rotation(client):
35
36=== modified file 'jujupy.py'
37--- jujupy.py 2016-02-12 21:31:30 +0000
38+++ jujupy.py 2016-02-12 22:33:29 +0000
39@@ -438,7 +438,7 @@
40 if proc.returncode != 0:
41 log.debug(sub_error)
42 e = subprocess.CalledProcessError(
43- proc.returncode, args[0], sub_error)
44+ proc.returncode, args[0], sub_output)
45 e.stderr = sub_error
46 if (
47 'Unable to connect to environment' in sub_error or
48
49=== modified file 'tests/test_assess_log_rotation.py'
50--- tests/test_assess_log_rotation.py 2015-12-15 16:21:27 +0000
51+++ tests/test_assess_log_rotation.py 2016-02-12 22:33:29 +0000
52@@ -1,22 +1,26 @@
53 from argparse import Namespace
54 from contextlib import contextmanager
55-from unittest import TestCase
56
57-from mock import patch
58+from mock import (
59+ Mock,
60+ patch,
61+)
62
63 from assess_log_rotation import (
64+ check_expected_backup,
65 check_for_extra_backup,
66- check_expected_backup,
67 check_log0,
68 LogRotateError,
69 make_client_from_args,
70 parse_args,
71+ test_debug_log,
72 )
73 from jujupy import (
74 EnvJujuClient,
75 _temp_env as temp_env,
76 yaml_loads,
77 )
78+from tests import TestCase
79
80 good_yaml = \
81 """
82@@ -148,6 +152,26 @@
83 "/var/log/juju/unit-fill-logs-0.log", big_obj)
84
85
86+class TestTestDebugLog(TestCase):
87+
88+ def test_happy_log(self):
89+ client = Mock()
90+ client.get_juju_output.return_value = '\n'*100
91+ # Ensure that no exception is raised
92+ test_debug_log(client, timeout=120)
93+ client.get_juju_output.assert_called_once_with(
94+ "debug-log", "--lines=100", "--limit=100", timeout=120)
95+
96+ def test_unhappy_log(self):
97+ client = Mock()
98+ client.get_juju_output.return_value = ''
99+ # Ensure that no exception is raised
100+ with self.assertRaises(LogRotateError):
101+ test_debug_log(client)
102+ client.get_juju_output.assert_called_once_with(
103+ "debug-log", "--lines=100", "--limit=100", timeout=180)
104+
105+
106 class TestParseArgs(TestCase):
107
108 def test_parse_args(self):
109@@ -165,12 +189,6 @@
110
111 class TestMakeClientFromArgs(TestCase):
112
113- def setUp(self):
114- super(TestMakeClientFromArgs, self).setUp()
115- patcher = patch('subprocess.Popen', side_effect=Exception)
116- patcher.start()
117- self.addCleanup(patcher.stop)
118-
119 @contextmanager
120 def make_client_cxt(self):
121 with temp_env({'environments': {'foo': {}}}):
122
123=== modified file 'tests/test_jujupy.py'
124--- tests/test_jujupy.py 2016-02-12 21:31:30 +0000
125+++ tests/test_jujupy.py 2016-02-12 22:33:29 +0000
126@@ -2591,12 +2591,13 @@
127
128 def test_get_juju_output_stderr(self):
129 env = SimpleEnvironment('foo')
130- fake_popen = FakePopen(None, 'Hello!', 1)
131+ fake_popen = FakePopen('Hello', 'Error!', 1)
132 client = EnvJujuClient1X(env, None, None)
133 with self.assertRaises(subprocess.CalledProcessError) as exc:
134 with patch('subprocess.Popen', return_value=fake_popen):
135 client.get_juju_output('bar')
136- self.assertEqual(exc.exception.stderr, 'Hello!')
137+ self.assertEqual(exc.exception.output, 'Hello')
138+ self.assertEqual(exc.exception.stderr, 'Error!')
139
140 def test_get_juju_output_accepts_timeout(self):
141 env = SimpleEnvironment('foo')

Subscribers

People subscribed via source and target branches