Merge lp:~veebers/juju-ci-tools/migration-check-all-model-names into lp:juju-ci-tools

Proposed by Christopher Lee
Status: Needs review
Proposed branch: lp:~veebers/juju-ci-tools/migration-check-all-model-names
Merge into: lp:juju-ci-tools
Prerequisite: lp:~veebers/juju-ci-tools/migration-log-check-fix
Diff against target: 140 lines (+49/-22)
4 files modified
assess_model_migration.py (+4/-2)
jujupy.py (+6/-4)
tests/test_assess_model_migration.py (+13/-16)
tests/test_jujupy.py (+26/-0)
To merge this branch: bzr merge lp:~veebers/juju-ci-tools/migration-check-all-model-names
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Needs Information
Review via email: mp+313330@code.launchpad.net

Description of the change

Need to check '--all' model names as other user models don't show up by default.

When getting model details (as superuser) for models that are owned by other
users need to pass the --all flag.

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

Is is possible to support --all in EnvJujuClient? See inline.

review: Needs Information (code)
1816. By Christopher Lee

Add argument to get_models so it returns models for all users.

1817. By Christopher Lee

Use jujupy supplied model listing.

Unmerged revisions

1817. By Christopher Lee

Use jujupy supplied model listing.

1816. By Christopher Lee

Add argument to get_models so it returns models for all users.

1815. By Christopher Lee

Merged migration-log-check-fix into migration-superuser-models.

1814. By Christopher Lee

Update unit tests, some still need work.

1813. By Christopher Lee

Merged migration-log-check-fix into migration-superuser-models.

1812. By Christopher Lee

Fix model name checks.

1811. By Christopher Lee

Get all model names from controller to check against.

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 2016-12-16 00:00:45 +0000
3+++ assess_model_migration.py 2016-12-16 00:00:45 +0000
4@@ -109,7 +109,7 @@
5 with client.check_timeouts():
6 with client.ignore_soft_deadline():
7 for _ in until_timeout(timeout):
8- models = client.get_controller_client().get_models()
9+ models = client.get_models(all_users=True)
10 if model_name in [m['name'] for m in models['models']]:
11 return
12 sleep(1)
13@@ -256,9 +256,11 @@
14 log.info('Showing all models available.')
15 source_client.controller_juju('models', ('--all',))
16
17+ # User qualified name for use with migration command.
18 user_qualified_model_name = qualified_model_name(
19 attempt_client.env.environment,
20 attempt_client.env.user_name)
21+ unqualified_model_name = attempt_client.env.environment
22
23 source_client.controller_juju(
24 'migrate',
25@@ -267,7 +269,7 @@
26 migration_client = dest_client.clone(
27 dest_client.env.clone(user_qualified_model_name))
28 wait_for_model(
29- migration_client, user_qualified_model_name)
30+ migration_client, unqualified_model_name)
31 migration_client.wait_for_started()
32
33
34
35=== modified file 'jujupy.py'
36--- jujupy.py 2016-12-15 20:14:48 +0000
37+++ jujupy.py 2016-12-16 00:00:45 +0000
38@@ -2159,15 +2159,17 @@
39 """List the models registered with the current controller."""
40 self.controller_juju('list-models', ())
41
42- def get_models(self):
43+ def get_models(self, all_users=False):
44 """return a models dict with a 'models': [] key-value pair.
45
46 The server has 120 seconds to respond because this method is called
47 often when tearing down a controller-less deployment.
48 """
49- output = self.get_juju_output(
50- 'list-models', '-c', self.env.controller.name, '--format', 'yaml',
51- include_e=False, timeout=120)
52+ args = [
53+ 'list-models', '-c', self.env.controller.name, '--format', 'yaml']
54+ if all_users:
55+ args.append('--all')
56+ output = self.get_juju_output(*args, include_e=False, timeout=120)
57 models = yaml.safe_load(output)
58 return models
59
60
61=== modified file 'tests/test_assess_model_migration.py'
62--- tests/test_assess_model_migration.py 2016-12-16 00:00:45 +0000
63+++ tests/test_assess_model_migration.py 2016-12-16 00:00:45 +0000
64@@ -428,26 +428,23 @@
65 amm.wait_for_model(mock_client, 'TestModelName')
66
67 def test_returns_when_model_found(self):
68- controller_client = Mock()
69- controller_client.get_models.return_value = dict(
70- models=[
71- dict(name='TestModelName')])
72 mock_client = _get_time_noop_mock_client()
73- mock_client.get_controller_client.return_value = controller_client
74- amm.wait_for_model(mock_client, 'TestModelName')
75+ with patch.object(
76+ amm, 'get_all_model_names',
77+ autospec=True, return_value=['TestModelName']) as m_gamn:
78+ amm.wait_for_model(mock_client, 'TestModelName')
79+ m_gamn.assert_called_once_with(mock_client)
80
81 def test_pauses_between_failed_matches(self):
82- controller_client = Mock()
83- controller_client.get_models.side_effect = [
84- dict(models=[]), # Failed check
85- dict(models=[dict(name='TestModelName')]), # Successful check
86- ]
87+ attempts = ['', 'TestModelName']
88 mock_client = _get_time_noop_mock_client()
89- mock_client.get_controller_client.return_value = controller_client
90-
91- with patch.object(amm, 'sleep') as mock_sleep:
92- amm.wait_for_model(mock_client, 'TestModelName')
93- mock_sleep.assert_called_once_with(1)
94+ with patch.object(
95+ amm, 'get_all_model_names',
96+ autospec=True, side_effect=attempts) as m_gamn:
97+ with patch.object(amm, 'sleep') as mock_sleep:
98+ amm.wait_for_model(mock_client, 'TestModelName')
99+ mock_sleep.assert_called_once_with(1)
100+ self.assertEqual(m_gamn.call_count, 2)
101
102 def test_suppresses_deadline(self):
103 client = EnvJujuClient(JujuData('local', juju_home=''), None, None)
104
105=== modified file 'tests/test_jujupy.py'
106--- tests/test_jujupy.py 2016-12-15 16:37:15 +0000
107+++ tests/test_jujupy.py 2016-12-16 00:00:45 +0000
108@@ -2022,6 +2022,32 @@
109 }
110 self.assertEqual(expected_models, models)
111
112+ def test_get_models_supplies_all_user_models(self):
113+ data = """\
114+ models:
115+ - name: foo
116+ model-uuid: aaaa
117+ owner: admin
118+ - name: bar
119+ model-uuid: bbbb
120+ owner: admin
121+ current-model: foo
122+ """
123+ client = EnvJujuClient(JujuData('baz'), None, None)
124+ with patch.object(client, 'get_juju_output',
125+ return_value=data) as gjo_mock:
126+ models = client.get_models(all_users=True)
127+ gjo_mock.assert_called_once_with(
128+ 'list-models', '-c', 'baz', '--format', 'yaml', '--all',
129+ include_e=False, timeout=120)
130+ expected_models = {
131+ 'models': [
132+ {'name': 'foo', 'model-uuid': 'aaaa', 'owner': 'admin'},
133+ {'name': 'bar', 'model-uuid': 'bbbb', 'owner': 'admin'}],
134+ 'current-model': 'foo'
135+ }
136+ self.assertEqual(expected_models, models)
137+
138 def test_iter_model_clients(self):
139 data = """\
140 models:

Subscribers

People subscribed via source and target branches