Merge lp:~veebers/juju-ci-tools/modelmig_public_clouds_logs into lp:juju-ci-tools

Proposed by Christopher Lee
Status: Merged
Merged at revision: 1888
Proposed branch: lp:~veebers/juju-ci-tools/modelmig_public_clouds_logs
Merge into: lp:juju-ci-tools
Prerequisite: lp:~veebers/juju-ci-tools/modelmig_testing_in_public_clouds
Diff against target: 97 lines (+58/-8)
2 files modified
assess_model_migration.py (+29/-6)
tests/test_assess_model_migration.py (+29/-2)
To merge this branch: bzr merge lp:~veebers/juju-ci-tools/modelmig_public_clouds_logs
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+317380@code.launchpad.net

Commit message

Add timeout wait-check for logs migration to give them time to migrate in the public could.

Description of the change

Add timeout wait-check for logs migration to give them time to migrate in the public could.

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

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_model_migration.py'
2--- assess_model_migration.py 2017-02-15 20:12:30 +0000
3+++ assess_model_migration.py 2017-02-15 20:12:31 +0000
4@@ -394,18 +394,41 @@
5 raise JujuAssertionError('Appliction units reside on the same machine')
6
7
8-def ensure_model_logs_are_migrated(source_client, dest_client):
9+def ensure_model_logs_are_migrated(source_client, dest_client, timeout=60):
10+ """Ensure logs are migrated when a model is migrated between controllers.
11+
12+ :param source_client: ModelClient representing source controller to create
13+ model on and migrate that model from.
14+ :param dest_client: ModelClient for destination controller to migrate to.
15+ :param timeout: int seconds to wait for logs to appear in migrated model.
16+ """
17 new_model_client = deploy_dummy_source_to_new_model(
18 source_client, 'log-migration')
19 before_migration_logs = new_model_client.get_juju_output(
20 'debug-log', '--no-tail', '-l', 'DEBUG')
21 log.info('Attempting migration process')
22 migrated_model = migrate_model_to_controller(new_model_client, dest_client)
23- after_migration_logs = migrated_model.get_juju_output(
24- 'debug-log', '--no-tail', '--replay', '-l', 'DEBUG')
25- if before_migration_logs not in after_migration_logs:
26- raise JujuAssertionError('Logs failed to be migrated.')
27- log.info('SUCCESS: logs migrated.')
28+
29+ assert_logs_appear_in_client_model(
30+ migrated_model, before_migration_logs, timeout)
31+
32+
33+def assert_logs_appear_in_client_model(client, expected_logs, timeout):
34+ """Assert that `expected_logs` appear in client logs within timeout.
35+
36+ :param client: ModelClient object to query logs of.
37+ :param expected_logs: string containing log contents to check for.
38+ :param timeout: int seconds to wait for before raising JujuAssertionError.
39+ """
40+ for _ in until_timeout(timeout):
41+ current_logs = client.get_juju_output(
42+ 'debug-log', '--no-tail', '--replay', '-l', 'DEBUG')
43+ if expected_logs in current_logs:
44+ log.info('SUCCESS: logs migrated.')
45+ return
46+ sleep(1)
47+ raise JujuAssertionError(
48+ 'Logs failed to be migrated after {}'.format(timeout))
49
50
51 def ensure_migration_rolls_back_on_failure(source_client, dest_client):
52
53=== modified file 'tests/test_assess_model_migration.py'
54--- tests/test_assess_model_migration.py 2017-02-15 20:12:30 +0000
55+++ tests/test_assess_model_migration.py 2017-02-15 20:12:31 +0000
56@@ -437,8 +437,6 @@
57
58
59 class TestWaitForModel(TestCase):
60- # Check that it returns an error if the model never comes up.
61- # Pass in a timeout for the model check
62 def test_raises_exception_when_timeout_occurs(self):
63 mock_client = _get_time_noop_mock_client()
64 with patch.object(until_timeout, 'next', side_effect=StopIteration()):
65@@ -876,3 +874,32 @@
66 m_am.assert_called_once_with(mig_client, app, resource_string)
67
68 self.assertEqual(m_rollback.call_count, 0)
69+
70+
71+class TestAssertLogsAppearInClientModel(TestCase):
72+
73+ def test_raises_exception_when_timeout_occurs(self):
74+ mock_client = Mock()
75+ with patch.object(until_timeout, 'next', side_effect=StopIteration()):
76+ with self.assertRaises(JujuAssertionError):
77+ amm.assert_logs_appear_in_client_model(
78+ mock_client, 'test logs', timeout=60)
79+
80+ def test_returns_early_when_logs_found(self):
81+ mock_client = Mock()
82+ mock_client.get_juju_output.return_value = 'test logs'
83+ with patch.object(amm, 'sleep', autospec=True) as m_sleep:
84+ amm.assert_logs_appear_in_client_model(
85+ mock_client, 'test logs', timeout=60)
86+ self.assertEqual(m_sleep.call_count, 0)
87+
88+ def test_tries_multiple_times_to_get_log_output(self):
89+ mock_client = Mock()
90+ mock_client.get_juju_output.side_effect = ['', 'test logs']
91+ with patch.object(
92+ until_timeout, 'next',
93+ side_effect=[None, None, StopIteration()]):
94+ with patch.object(amm, 'sleep', autospec=True) as m_sleep:
95+ amm.assert_logs_appear_in_client_model(
96+ mock_client, 'test logs', timeout=60)
97+ self.assertEqual(m_sleep.call_count, 1)

Subscribers

People subscribed via source and target branches