Merge lp:~veebers/juju-ci-tools/modelmig-public-cloud-wait-for-model into lp:juju-ci-tools

Proposed by Christopher Lee
Status: Merged
Merged at revision: 1901
Proposed branch: lp:~veebers/juju-ci-tools/modelmig-public-cloud-wait-for-model
Merge into: lp:juju-ci-tools
Diff against target: 60 lines (+35/-4)
2 files modified
assess_model_migration.py (+6/-4)
tests/test_assess_model_migration.py (+29/-0)
To merge this branch: bzr merge lp:~veebers/juju-ci-tools/modelmig-public-cloud-wait-for-model
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+317903@code.launchpad.net

Commit message

Ignore 'cannot find model details' error when listing models.

Description of the change

Ignore 'cannot find model details' error when listing models.

The model has been migrated and the code is waiting for the model to be removed from the list of models. This error occurs sometimes when listing.

To post a comment you must log in.
1898. By Christopher Lee

Reduce exception logic.

1899. By Christopher Lee

Merge trunk

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

Thanks.

review: Approve

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-19 21:51:40 +0000
3+++ assess_model_migration.py 2017-02-21 22:06:00 +0000
4@@ -158,11 +158,13 @@
5 except CalledProcessError as e:
6 # It's possible that we've tried to get status from the model as
7 # it's being removed.
8- if 'cannot get model details' in e.stderr:
9+ # We can't consider the model gone yet until we don't get this
10+ # error and the model is no longer in the output.
11+ if 'cannot get model details' not in e.stderr:
12+ raise
13+ else:
14+ if model_name not in [m['name'] for m in models['models']]:
15 return True
16- raise
17- if model_name not in [m['name'] for m in models['models']]:
18- return True
19
20 try:
21 _wait_for_model_check(client, model_check, timeout)
22
23=== modified file 'tests/test_assess_model_migration.py'
24--- tests/test_assess_model_migration.py 2017-02-17 00:46:09 +0000
25+++ tests/test_assess_model_migration.py 2017-02-21 22:06:00 +0000
26@@ -512,6 +512,35 @@
27 amm.wait_until_model_disappears(
28 mock_client, 'test_model', timeout=60)
29
30+ def test_ignores_model_detail_exceptions(self):
31+ """ignore errors for model details as this might happen many times."""
32+ mock_client = _get_time_noop_mock_client()
33+ model_data = {'models': [{'name': ''}]}
34+
35+ exp = CalledProcessError(-1, 'blah')
36+ exp.stderr = 'cannot get model details'
37+ controller_client = Mock()
38+ controller_client.get_models.side_effect = [
39+ exp,
40+ model_data]
41+ mock_client.get_controller_client.return_value = controller_client
42+ with patch.object(amm, 'sleep') as mock_sleep:
43+ amm.wait_until_model_disappears(
44+ mock_client, 'test_model', timeout=60)
45+ mock_sleep.assert_called_once_with(1)
46+
47+ def test_fails_on_non_expected_exception(self):
48+ mock_client = _get_time_noop_mock_client()
49+
50+ exp = CalledProcessError(-1, 'blah')
51+ exp.stderr = '"" is not a valid tag'
52+ controller_client = Mock()
53+ controller_client.get_models.side_effect = [exp]
54+ mock_client.get_controller_client.return_value = controller_client
55+ with self.assertRaises(CalledProcessError):
56+ amm.wait_until_model_disappears(
57+ mock_client, 'test_model', timeout=60)
58+
59
60 class TestWaitForModel(TestCase):
61

Subscribers

People subscribed via source and target branches