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
=== modified file 'assess_log_rotation.py'
--- assess_log_rotation.py 2016-01-12 16:14:17 +0000
+++ assess_log_rotation.py 2016-02-12 22:33:29 +0000
@@ -32,14 +32,30 @@
32 super(LogRotateError, self).__init__(message)32 super(LogRotateError, self).__init__(message)
3333
3434
35def test_debug_log(client, timeout=180, lines=100):
36 """After doing log rotation, we should be able to see debug-log output."""
37 out = client.get_juju_output("debug-log", "--lines={}".format(lines),
38 "--limit={}".format(lines), timeout=timeout)
39 content = out.splitlines()
40 if len(content) != lines:
41 raise LogRotateError("We expected {} lines of output, got {}".format(
42 lines, len(content)))
43
44
35def test_unit_rotation(client):45def test_unit_rotation(client):
36 """Tests unit log rotation."""46 """Tests unit log rotation."""
47 # TODO: as part of testing that when a unit sending lots of logs triggers
48 # unit log rotation, we should also test that all-machines.log and future
49 # logsink.log get rotated.
50 # It would also be possible to test that the logs database doesn't grow too
51 # large.
37 test_rotation(client,52 test_rotation(client,
38 "/var/log/juju/unit-fill-logs-0.log",53 "/var/log/juju/unit-fill-logs-0.log",
39 "unit-fill-logs-0",54 "unit-fill-logs-0",
40 "fill-unit",55 "fill-unit",
41 "unit-size",56 "unit-size",
42 "megs=300")57 "megs=300")
58 # TODO: either call test_debug_log here or add a new assess entry for it.
4359
4460
45def test_machine_rotation(client):61def test_machine_rotation(client):
4662
=== modified file 'jujupy.py'
--- jujupy.py 2016-02-12 21:31:30 +0000
+++ jujupy.py 2016-02-12 22:33:29 +0000
@@ -438,7 +438,7 @@
438 if proc.returncode != 0:438 if proc.returncode != 0:
439 log.debug(sub_error)439 log.debug(sub_error)
440 e = subprocess.CalledProcessError(440 e = subprocess.CalledProcessError(
441 proc.returncode, args[0], sub_error)441 proc.returncode, args[0], sub_output)
442 e.stderr = sub_error442 e.stderr = sub_error
443 if (443 if (
444 'Unable to connect to environment' in sub_error or444 'Unable to connect to environment' in sub_error or
445445
=== modified file 'tests/test_assess_log_rotation.py'
--- tests/test_assess_log_rotation.py 2015-12-15 16:21:27 +0000
+++ tests/test_assess_log_rotation.py 2016-02-12 22:33:29 +0000
@@ -1,22 +1,26 @@
1from argparse import Namespace1from argparse import Namespace
2from contextlib import contextmanager2from contextlib import contextmanager
3from unittest import TestCase
43
5from mock import patch4from mock import (
5 Mock,
6 patch,
7)
68
7from assess_log_rotation import (9from assess_log_rotation import (
10 check_expected_backup,
8 check_for_extra_backup,11 check_for_extra_backup,
9 check_expected_backup,
10 check_log0,12 check_log0,
11 LogRotateError,13 LogRotateError,
12 make_client_from_args,14 make_client_from_args,
13 parse_args,15 parse_args,
16 test_debug_log,
14)17)
15from jujupy import (18from jujupy import (
16 EnvJujuClient,19 EnvJujuClient,
17 _temp_env as temp_env,20 _temp_env as temp_env,
18 yaml_loads,21 yaml_loads,
19 )22 )
23from tests import TestCase
2024
21good_yaml = \25good_yaml = \
22 """26 """
@@ -148,6 +152,26 @@
148 "/var/log/juju/unit-fill-logs-0.log", big_obj)152 "/var/log/juju/unit-fill-logs-0.log", big_obj)
149153
150154
155class TestTestDebugLog(TestCase):
156
157 def test_happy_log(self):
158 client = Mock()
159 client.get_juju_output.return_value = '\n'*100
160 # Ensure that no exception is raised
161 test_debug_log(client, timeout=120)
162 client.get_juju_output.assert_called_once_with(
163 "debug-log", "--lines=100", "--limit=100", timeout=120)
164
165 def test_unhappy_log(self):
166 client = Mock()
167 client.get_juju_output.return_value = ''
168 # Ensure that no exception is raised
169 with self.assertRaises(LogRotateError):
170 test_debug_log(client)
171 client.get_juju_output.assert_called_once_with(
172 "debug-log", "--lines=100", "--limit=100", timeout=180)
173
174
151class TestParseArgs(TestCase):175class TestParseArgs(TestCase):
152176
153 def test_parse_args(self):177 def test_parse_args(self):
@@ -165,12 +189,6 @@
165189
166class TestMakeClientFromArgs(TestCase):190class TestMakeClientFromArgs(TestCase):
167191
168 def setUp(self):
169 super(TestMakeClientFromArgs, self).setUp()
170 patcher = patch('subprocess.Popen', side_effect=Exception)
171 patcher.start()
172 self.addCleanup(patcher.stop)
173
174 @contextmanager192 @contextmanager
175 def make_client_cxt(self):193 def make_client_cxt(self):
176 with temp_env({'environments': {'foo': {}}}):194 with temp_env({'environments': {'foo': {}}}):
177195
=== modified file 'tests/test_jujupy.py'
--- tests/test_jujupy.py 2016-02-12 21:31:30 +0000
+++ tests/test_jujupy.py 2016-02-12 22:33:29 +0000
@@ -2591,12 +2591,13 @@
25912591
2592 def test_get_juju_output_stderr(self):2592 def test_get_juju_output_stderr(self):
2593 env = SimpleEnvironment('foo')2593 env = SimpleEnvironment('foo')
2594 fake_popen = FakePopen(None, 'Hello!', 1)2594 fake_popen = FakePopen('Hello', 'Error!', 1)
2595 client = EnvJujuClient1X(env, None, None)2595 client = EnvJujuClient1X(env, None, None)
2596 with self.assertRaises(subprocess.CalledProcessError) as exc:2596 with self.assertRaises(subprocess.CalledProcessError) as exc:
2597 with patch('subprocess.Popen', return_value=fake_popen):2597 with patch('subprocess.Popen', return_value=fake_popen):
2598 client.get_juju_output('bar')2598 client.get_juju_output('bar')
2599 self.assertEqual(exc.exception.stderr, 'Hello!')2599 self.assertEqual(exc.exception.output, 'Hello')
2600 self.assertEqual(exc.exception.stderr, 'Error!')
26002601
2601 def test_get_juju_output_accepts_timeout(self):2602 def test_get_juju_output_accepts_timeout(self):
2602 env = SimpleEnvironment('foo')2603 env = SimpleEnvironment('foo')

Subscribers

People subscribed via source and target branches