Merge lp:~veebers/juju-ci-tools/introduce_commandcomplete into lp:juju-ci-tools
- introduce_commandcomplete
- Merge into trunk
Proposed by
Christopher Lee
Status: | Merged |
---|---|
Merged at revision: | 1982 |
Proposed branch: | lp:~veebers/juju-ci-tools/introduce_commandcomplete |
Merge into: | lp:juju-ci-tools |
Prerequisite: | lp:~veebers/juju-ci-tools/introduce-commandtime |
Diff against target: |
1126 lines (+169/-116) 11 files modified
assess_container_networking.py (+3/-2) jujupy/client.py (+37/-18) jujupy/fake.py (+3/-1) jujupy/tests/test_client.py (+57/-54) jujupy/tests/test_version_client.py (+25/-24) jujupy/version_client.py (+18/-8) tests/__init__.py (+12/-3) tests/test_assess_block.py (+2/-1) tests/test_assess_bootstrap.py (+2/-1) tests/test_assess_user_grant_revoke.py (+2/-1) tests/test_deploy_stack.py (+8/-3) |
To merge this branch: | bzr merge lp:~veebers/juju-ci-tools/introduce_commandcomplete |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Curtis Hovey (community) | code | Approve | |
Review via email: mp+320754@code.launchpad.net |
This proposal supersedes a proposal from 2017-03-23.
Commit message
Description of the change
Introduce CommandComplete to command wrappers (deploy etc.)
Introduces the CompleteComplete return to command wrappers and updates test to match the new return behaviour.
Sorry for the massive diff, most changes are touching lines for patching of ModelClient.juju() return.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'assess_container_networking.py' |
2 | --- assess_container_networking.py 2017-03-23 04:50:58 +0000 |
3 | +++ assess_container_networking.py 2017-03-23 04:50:58 +0000 |
4 | @@ -248,8 +248,9 @@ |
5 | |
6 | d = re.search(r'^default\s+via\s+([\d\.]+)\s+', routes, re.MULTILINE) |
7 | if d: |
8 | - rc, _ = client.juju('ssh', ('--proxy', target, |
9 | - 'ping -c1 -q ' + d.group(1)), check=False) |
10 | + rc, _ = client.juju( |
11 | + 'ssh', |
12 | + ('--proxy', target, 'ping -c1 -q ' + d.group(1)), check=False) |
13 | if rc != 0: |
14 | raise ValueError('%s unable to ping default route' % target) |
15 | else: |
16 | |
17 | === modified file 'jujupy/client.py' |
18 | --- jujupy/client.py 2017-03-23 04:50:58 +0000 |
19 | +++ jujupy/client.py 2017-03-23 04:50:58 +0000 |
20 | @@ -1938,22 +1938,28 @@ |
21 | def kill_controller(self, check=False): |
22 | """Kill a controller and its models. Hard kill option. |
23 | |
24 | - :return: Subprocess's exit code.""" |
25 | - return self.juju( |
26 | + :return: Tuple: Subprocess's exit code, CommandComplete object. |
27 | + """ |
28 | + retvar, ct = self.juju( |
29 | 'kill-controller', (self.env.controller.name, '-y'), |
30 | include_e=False, check=check, timeout=get_teardown_timeout(self)) |
31 | + return retvar, CommandComplete(BaseCondition(), ct) |
32 | |
33 | def destroy_controller(self, all_models=False): |
34 | """Destroy a controller and its models. Soft kill option. |
35 | |
36 | :param all_models: If true will attempt to destroy all the |
37 | controller's models as well. |
38 | - :raises: subprocess.CalledProcessError if the operation fails.""" |
39 | + :raises: subprocess.CalledProcessError if the operation fails. |
40 | + :return: Tuple: Subprocess's exit code, CommandComplete object. |
41 | + """ |
42 | args = (self.env.controller.name, '-y') |
43 | if all_models: |
44 | args += ('--destroy-all-models',) |
45 | - return self.juju('destroy-controller', args, include_e=False, |
46 | - timeout=get_teardown_timeout(self)) |
47 | + retvar, ct = self.juju( |
48 | + 'destroy-controller', args, include_e=False, |
49 | + timeout=get_teardown_timeout(self)) |
50 | + return retvar, CommandComplete(BaseCondition(), ct) |
51 | |
52 | def tear_down(self): |
53 | """Tear down the client as cleanly as possible. |
54 | @@ -2038,7 +2044,8 @@ |
55 | |
56 | def set_model_constraints(self, constraints): |
57 | constraint_strings = self._dict_as_option_strings(constraints) |
58 | - return self.juju('set-model-constraints', constraint_strings) |
59 | + retvar, ct = self.juju('set-model-constraints', constraint_strings) |
60 | + return retvar, CommandComplete(BaseCondition(), ct) |
61 | |
62 | def get_model_config(self): |
63 | """Return the value of the environment's configured options.""" |
64 | @@ -2053,11 +2060,13 @@ |
65 | def set_env_option(self, option, value): |
66 | """Set the value of the option in the environment.""" |
67 | option_value = "%s=%s" % (option, value) |
68 | - return self.juju('model-config', (option_value,)) |
69 | + retvar, ct = self.juju('model-config', (option_value,)) |
70 | + return CommandComplete(BaseCondition(), ct) |
71 | |
72 | def unset_env_option(self, option): |
73 | """Unset the value of the option in the environment.""" |
74 | - return self.juju('model-config', ('--reset', option,)) |
75 | + retvar, ct = self.juju('model-config', ('--reset', option,)) |
76 | + return CommandComplete(BaseCondition(), ct) |
77 | |
78 | @staticmethod |
79 | def _format_cloud_region(cloud=None, region=None): |
80 | @@ -2141,7 +2150,8 @@ |
81 | |
82 | def controller_juju(self, command, args): |
83 | args = ('-c', self.env.controller.name) + args |
84 | - return self.juju(command, args, include_e=False) |
85 | + retvar, ct = self.juju(command, args, include_e=False) |
86 | + return CommandComplete(BaseCondition(), ct) |
87 | |
88 | def get_juju_timings(self): |
89 | stringified_timings = {} |
90 | @@ -2178,11 +2188,13 @@ |
91 | args.extend(['--bind', bind]) |
92 | if alias is not None: |
93 | args.extend([alias]) |
94 | - return self.juju('deploy', tuple(args)) |
95 | + retvar, ct = self.juju('deploy', tuple(args)) |
96 | + return CommandComplete(BaseCondition(), ct) |
97 | |
98 | def attach(self, service, resource): |
99 | args = (service, resource) |
100 | - return self.juju('attach', args) |
101 | + retvar, ct = self.juju('attach', args) |
102 | + return retvar, CommandComplete(BaseCondition(), ct) |
103 | |
104 | def list_resources(self, service_or_unit, details=True): |
105 | args = ('--format', 'yaml', service_or_unit) |
106 | @@ -2883,11 +2895,14 @@ |
107 | args = ('generate-tools', '-d', source_dir) |
108 | if stream is not None: |
109 | args += ('--stream', stream) |
110 | - return self.juju('metadata', args, include_e=False) |
111 | + retvar, ct = self.juju('metadata', args, include_e=False) |
112 | + return retvar, CommandComplete(BaseCondition(), ct) |
113 | |
114 | def add_cloud(self, cloud_name, cloud_file): |
115 | - return self.juju('add-cloud', ("--replace", cloud_name, cloud_file), |
116 | - include_e=False) |
117 | + retvar, ct = self.juju( |
118 | + 'add-cloud', ("--replace", cloud_name, cloud_file), |
119 | + include_e=False) |
120 | + return retvar, CommandComplete(BaseCondition(), ct) |
121 | |
122 | def add_cloud_interactive(self, cloud_name, cloud): |
123 | child = self.expect('add-cloud', include_e=False) |
124 | @@ -2997,11 +3012,13 @@ |
125 | |
126 | def disable_command(self, command_set, message=''): |
127 | """Disable a command-set.""" |
128 | - return self.juju('disable-command', (command_set, message)) |
129 | + retvar, ct = self.juju('disable-command', (command_set, message)) |
130 | + return retvar, CommandComplete(BaseCondition(), ct) |
131 | |
132 | def enable_command(self, args): |
133 | """Enable a command-set.""" |
134 | - return self.juju('enable-command', args) |
135 | + retvar, ct = self.juju('enable-command', args) |
136 | + return CommandComplete(BaseCondition(), ct) |
137 | |
138 | def sync_tools(self, local_dir=None, stream=None, source=None): |
139 | """Copy tools into a local directory or model.""" |
140 | @@ -3011,10 +3028,12 @@ |
141 | if source is not None: |
142 | args += ('--source', source) |
143 | if local_dir is None: |
144 | - return self.juju('sync-tools', args) |
145 | + retvar, ct = self.juju('sync-tools', args) |
146 | + return retvar, CommandComplete(BaseCondition(), ct) |
147 | else: |
148 | args += ('--local-dir', local_dir) |
149 | - return self.juju('sync-tools', args, include_e=False) |
150 | + retvar, ct = self.juju('sync-tools', args, include_e=False) |
151 | + return retvar, CommandComplete(BaseCondition(), ct) |
152 | |
153 | def switch(self, model=None, controller=None): |
154 | """Switch between models.""" |
155 | |
156 | === modified file 'jujupy/fake.py' |
157 | --- jujupy/fake.py 2017-03-23 04:50:58 +0000 |
158 | +++ jujupy/fake.py 2017-03-23 04:50:58 +0000 |
159 | @@ -878,6 +878,7 @@ |
160 | num = int(parsed.n or 1) |
161 | self.deploy(model_state, parsed.charm_name, num, |
162 | parsed.service_name, parsed.series) |
163 | + return (0, CommandTime(command, args)) |
164 | if command == 'remove-application': |
165 | model_state.destroy_service(*args) |
166 | if command == 'add-relation': |
167 | @@ -926,8 +927,9 @@ |
168 | self.controller_state.destroy() |
169 | if command == 'kill-controller': |
170 | if self.controller_state.state == 'not-bootstrapped': |
171 | - return |
172 | + return (0, CommandTime(command, args)) |
173 | self.controller_state.destroy(kill=True) |
174 | + return (0, CommandTime(command, args)) |
175 | if command == 'destroy-model': |
176 | if not self.is_feature_enabled('jes'): |
177 | raise JESNotSupported() |
178 | |
179 | === modified file 'jujupy/tests/test_client.py' |
180 | --- jujupy/tests/test_client.py 2017-03-23 04:50:58 +0000 |
181 | +++ jujupy/tests/test_client.py 2017-03-23 04:50:58 +0000 |
182 | @@ -101,6 +101,7 @@ |
183 | from tests import ( |
184 | assert_juju_call, |
185 | client_past_deadline, |
186 | + make_fake_juju_return, |
187 | FakeHomeTestCase, |
188 | FakePopen, |
189 | observable_temp_file, |
190 | @@ -705,7 +706,7 @@ |
191 | env = JujuData('foo', {'type': 'foo', 'region': 'baz'}) |
192 | client = ModelClient(env, '2.0-zeta1', None) |
193 | with observable_temp_file() as config_file: |
194 | - with patch.object(client, 'juju') as mock: |
195 | + with patch_juju_call(client) as mock: |
196 | client.bootstrap(upload_tools=True) |
197 | mock.assert_called_with( |
198 | 'bootstrap', ( |
199 | @@ -718,7 +719,7 @@ |
200 | env = JujuData('foo', {'type': 'foo', 'region': 'baz'}) |
201 | client = ModelClient(env, '2.0-zeta1', None) |
202 | with observable_temp_file() as config_file: |
203 | - with patch.object(client, 'juju') as mock: |
204 | + with patch_juju_call(client) as mock: |
205 | client.bootstrap(credential='credential_name') |
206 | mock.assert_called_with( |
207 | 'bootstrap', ( |
208 | @@ -731,7 +732,7 @@ |
209 | def test_bootstrap_bootstrap_series(self): |
210 | env = JujuData('foo', {'type': 'bar', 'region': 'baz'}) |
211 | client = ModelClient(env, '2.0-zeta1', None) |
212 | - with patch.object(client, 'juju') as mock: |
213 | + with patch_juju_call(client) as mock: |
214 | with observable_temp_file() as config_file: |
215 | client.bootstrap(bootstrap_series='angsty') |
216 | mock.assert_called_with( |
217 | @@ -745,7 +746,7 @@ |
218 | def test_bootstrap_auto_upgrade(self): |
219 | env = JujuData('foo', {'type': 'bar', 'region': 'baz'}) |
220 | client = ModelClient(env, '2.0-zeta1', None) |
221 | - with patch.object(client, 'juju') as mock: |
222 | + with patch_juju_call(client) as mock: |
223 | with observable_temp_file() as config_file: |
224 | client.bootstrap(auto_upgrade=True) |
225 | mock.assert_called_with( |
226 | @@ -758,7 +759,7 @@ |
227 | def test_bootstrap_no_gui(self): |
228 | env = JujuData('foo', {'type': 'bar', 'region': 'baz'}) |
229 | client = ModelClient(env, '2.0-zeta1', None) |
230 | - with patch.object(client, 'juju') as mock: |
231 | + with patch_juju_call(client) as mock: |
232 | with observable_temp_file() as config_file: |
233 | client.bootstrap(no_gui=True) |
234 | mock.assert_called_with( |
235 | @@ -771,7 +772,7 @@ |
236 | def test_bootstrap_metadata(self): |
237 | env = JujuData('foo', {'type': 'bar', 'region': 'baz'}) |
238 | client = ModelClient(env, '2.0-zeta1', None) |
239 | - with patch.object(client, 'juju') as mock: |
240 | + with patch_juju_call(client) as mock: |
241 | with observable_temp_file() as config_file: |
242 | client.bootstrap(metadata_source='/var/test-source') |
243 | mock.assert_called_with( |
244 | @@ -865,7 +866,7 @@ |
245 | client = ModelClient(model_data, None, None) |
246 | with patch.object(client, 'get_jes_command', |
247 | return_value=jes_command): |
248 | - with patch.object(controller_client, 'juju') as ccj_mock: |
249 | + with patch_juju_call(controller_client) as ccj_mock: |
250 | with observable_temp_file() as config_file: |
251 | controller_client.add_model(model_data) |
252 | ccj_mock.assert_called_once_with( |
253 | @@ -877,7 +878,7 @@ |
254 | client.bootstrap() |
255 | client.env.controller.explicit_region = True |
256 | model = client.env.clone('new-model') |
257 | - with patch.object(client._backend, 'juju') as juju_mock: |
258 | + with patch_juju_call(client._backend) as juju_mock: |
259 | with observable_temp_file() as config_file: |
260 | client.add_model(model) |
261 | juju_mock.assert_called_once_with('add-model', ( |
262 | @@ -889,7 +890,7 @@ |
263 | def test_add_model_by_name(self): |
264 | client = fake_juju_client() |
265 | client.bootstrap() |
266 | - with patch.object(client._backend, 'juju') as juju_mock: |
267 | + with patch_juju_call(client._backend) as juju_mock: |
268 | with observable_temp_file() as config_file: |
269 | client.add_model('new-model') |
270 | juju_mock.assert_called_once_with('add-model', ( |
271 | @@ -931,7 +932,7 @@ |
272 | |
273 | def test_kill_controller(self): |
274 | client = ModelClient(JujuData('foo', {'type': 'ec2'}), None, None) |
275 | - with patch.object(client, 'juju') as juju_mock: |
276 | + with patch_juju_call(client) as juju_mock: |
277 | client.kill_controller() |
278 | juju_mock.assert_called_once_with( |
279 | 'kill-controller', ('foo', '-y'), check=False, include_e=False, |
280 | @@ -939,7 +940,7 @@ |
281 | |
282 | def test_kill_controller_check(self): |
283 | client = ModelClient(JujuData('foo', {'type': 'ec2'}), None, None) |
284 | - with patch.object(client, 'juju') as juju_mock: |
285 | + with patch_juju_call(client) as juju_mock: |
286 | client.kill_controller(check=True) |
287 | juju_mock.assert_called_once_with( |
288 | 'kill-controller', ('foo', '-y'), check=True, include_e=False, |
289 | @@ -949,7 +950,7 @@ |
290 | client = ModelClient(JujuData('foo', {'type': 'azure'}), None, None) |
291 | with patch.object(client, 'get_jes_command', |
292 | return_value=jes_command): |
293 | - with patch.object(client, 'juju') as juju_mock: |
294 | + with patch_juju_call(client) as juju_mock: |
295 | client.kill_controller() |
296 | juju_mock.assert_called_once_with( |
297 | kill_command, ('foo', '-y'), check=False, include_e=False, |
298 | @@ -957,7 +958,7 @@ |
299 | |
300 | def test_kill_controller_gce(self): |
301 | client = ModelClient(JujuData('foo', {'type': 'gce'}), None, None) |
302 | - with patch.object(client, 'juju') as juju_mock: |
303 | + with patch_juju_call(client) as juju_mock: |
304 | client.kill_controller() |
305 | juju_mock.assert_called_once_with( |
306 | 'kill-controller', ('foo', '-y'), check=False, include_e=False, |
307 | @@ -965,7 +966,7 @@ |
308 | |
309 | def test_destroy_controller(self): |
310 | client = ModelClient(JujuData('foo', {'type': 'ec2'}), None, None) |
311 | - with patch.object(client, 'juju') as juju_mock: |
312 | + with patch_juju_call(client) as juju_mock: |
313 | client.destroy_controller() |
314 | juju_mock.assert_called_once_with( |
315 | 'destroy-controller', ('foo', '-y'), include_e=False, |
316 | @@ -973,7 +974,7 @@ |
317 | |
318 | def test_destroy_controller_all_models(self): |
319 | client = ModelClient(JujuData('foo', {'type': 'ec2'}), None, None) |
320 | - with patch.object(client, 'juju') as juju_mock: |
321 | + with patch_juju_call(client) as juju_mock: |
322 | client.destroy_controller(all_models=True) |
323 | juju_mock.assert_called_once_with( |
324 | 'destroy-controller', ('foo', '-y', '--destroy-all-models'), |
325 | @@ -991,7 +992,9 @@ |
326 | side_effect=raise_error) as mock: |
327 | yield mock |
328 | else: |
329 | - with patch.object(target, attribute, autospec=True) as mock: |
330 | + with patch.object( |
331 | + target, attribute, autospec=True, |
332 | + return_value=make_fake_juju_return()) as mock: |
333 | yield mock |
334 | |
335 | with patch_raise(client, 'destroy_controller', destroy_raises |
336 | @@ -1222,21 +1225,21 @@ |
337 | def test_deploy_non_joyent(self): |
338 | env = ModelClient( |
339 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
340 | - with patch.object(env, 'juju') as mock_juju: |
341 | + with patch_juju_call(env) as mock_juju: |
342 | env.deploy('mondogb') |
343 | mock_juju.assert_called_with('deploy', ('mondogb',)) |
344 | |
345 | def test_deploy_joyent(self): |
346 | env = ModelClient( |
347 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
348 | - with patch.object(env, 'juju') as mock_juju: |
349 | + with patch_juju_call(env) as mock_juju: |
350 | env.deploy('mondogb') |
351 | mock_juju.assert_called_with('deploy', ('mondogb',)) |
352 | |
353 | def test_deploy_repository(self): |
354 | env = ModelClient( |
355 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
356 | - with patch.object(env, 'juju') as mock_juju: |
357 | + with patch_juju_call(env) as mock_juju: |
358 | env.deploy('/home/jrandom/repo/mongodb') |
359 | mock_juju.assert_called_with( |
360 | 'deploy', ('/home/jrandom/repo/mongodb',)) |
361 | @@ -1244,7 +1247,7 @@ |
362 | def test_deploy_to(self): |
363 | env = ModelClient( |
364 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
365 | - with patch.object(env, 'juju') as mock_juju: |
366 | + with patch_juju_call(env) as mock_juju: |
367 | env.deploy('mondogb', to='0') |
368 | mock_juju.assert_called_with( |
369 | 'deploy', ('mondogb', '--to', '0')) |
370 | @@ -1252,7 +1255,7 @@ |
371 | def test_deploy_service(self): |
372 | env = ModelClient( |
373 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
374 | - with patch.object(env, 'juju') as mock_juju: |
375 | + with patch_juju_call(env) as mock_juju: |
376 | env.deploy('local:mondogb', service='my-mondogb') |
377 | mock_juju.assert_called_with( |
378 | 'deploy', ('local:mondogb', 'my-mondogb',)) |
379 | @@ -1260,14 +1263,14 @@ |
380 | def test_deploy_force(self): |
381 | env = ModelClient( |
382 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
383 | - with patch.object(env, 'juju') as mock_juju: |
384 | + with patch_juju_call(env) as mock_juju: |
385 | env.deploy('local:mondogb', force=True) |
386 | mock_juju.assert_called_with('deploy', ('local:mondogb', '--force',)) |
387 | |
388 | def test_deploy_series(self): |
389 | env = ModelClient( |
390 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
391 | - with patch.object(env, 'juju') as mock_juju: |
392 | + with patch_juju_call(env) as mock_juju: |
393 | env.deploy('local:blah', series='xenial') |
394 | mock_juju.assert_called_with( |
395 | 'deploy', ('local:blah', '--series', 'xenial')) |
396 | @@ -1275,14 +1278,14 @@ |
397 | def test_deploy_multiple(self): |
398 | env = ModelClient( |
399 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
400 | - with patch.object(env, 'juju') as mock_juju: |
401 | + with patch_juju_call(env) as mock_juju: |
402 | env.deploy('local:blah', num=2) |
403 | mock_juju.assert_called_with( |
404 | 'deploy', ('local:blah', '-n', '2')) |
405 | |
406 | def test_deploy_resource(self): |
407 | env = ModelClient(JujuData('foo', {'type': 'local'}), None, None) |
408 | - with patch.object(env, 'juju') as mock_juju: |
409 | + with patch_juju_call(env) as mock_juju: |
410 | env.deploy('local:blah', resource='foo=/path/dir') |
411 | mock_juju.assert_called_with( |
412 | 'deploy', ('local:blah', '--resource', 'foo=/path/dir')) |
413 | @@ -1290,7 +1293,7 @@ |
414 | def test_deploy_storage(self): |
415 | env = EnvJujuClient1X( |
416 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
417 | - with patch.object(env, 'juju') as mock_juju: |
418 | + with patch_juju_call(env) as mock_juju: |
419 | env.deploy('mondogb', storage='rootfs,1G') |
420 | mock_juju.assert_called_with( |
421 | 'deploy', ('mondogb', '--storage', 'rootfs,1G')) |
422 | @@ -1298,27 +1301,27 @@ |
423 | def test_deploy_constraints(self): |
424 | env = EnvJujuClient1X( |
425 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
426 | - with patch.object(env, 'juju') as mock_juju: |
427 | + with patch_juju_call(env) as mock_juju: |
428 | env.deploy('mondogb', constraints='virt-type=kvm') |
429 | mock_juju.assert_called_with( |
430 | 'deploy', ('mondogb', '--constraints', 'virt-type=kvm')) |
431 | |
432 | def test_deploy_bind(self): |
433 | env = ModelClient(JujuData('foo', {'type': 'local'}), None, None) |
434 | - with patch.object(env, 'juju') as mock_juju: |
435 | + with patch_juju_call(env) as mock_juju: |
436 | env.deploy('mydb', bind='backspace') |
437 | mock_juju.assert_called_with('deploy', ('mydb', '--bind', 'backspace')) |
438 | |
439 | def test_deploy_aliased(self): |
440 | env = ModelClient(JujuData('foo', {'type': 'local'}), None, None) |
441 | - with patch.object(env, 'juju') as mock_juju: |
442 | + with patch_juju_call(env) as mock_juju: |
443 | env.deploy('local:blah', alias='blah-blah') |
444 | mock_juju.assert_called_with( |
445 | 'deploy', ('local:blah', 'blah-blah')) |
446 | |
447 | def test_attach(self): |
448 | env = ModelClient(JujuData('foo', {'type': 'local'}), None, None) |
449 | - with patch.object(env, 'juju') as mock_juju: |
450 | + with patch_juju_call(env) as mock_juju: |
451 | env.attach('foo', resource='foo=/path/dir') |
452 | mock_juju.assert_called_with('attach', ('foo', 'foo=/path/dir')) |
453 | |
454 | @@ -1386,7 +1389,7 @@ |
455 | def test_deploy_bundle_2x(self): |
456 | client = ModelClient(JujuData('an_env', None), |
457 | '1.23-series-arch', None) |
458 | - with patch.object(client, 'juju') as mock_juju: |
459 | + with patch_juju_call(client) as mock_juju: |
460 | client.deploy_bundle('bundle:~juju-qa/some-bundle') |
461 | mock_juju.assert_called_with( |
462 | 'deploy', ('bundle:~juju-qa/some-bundle'), timeout=3600) |
463 | @@ -1394,7 +1397,7 @@ |
464 | def test_deploy_bundle_template(self): |
465 | client = ModelClient(JujuData('an_env', None), |
466 | '1.23-series-arch', None) |
467 | - with patch.object(client, 'juju') as mock_juju: |
468 | + with patch_juju_call(client) as mock_juju: |
469 | client.deploy_bundle('bundle:~juju-qa/some-{container}-bundle') |
470 | mock_juju.assert_called_with( |
471 | 'deploy', ('bundle:~juju-qa/some-lxd-bundle'), timeout=3600) |
472 | @@ -1402,7 +1405,7 @@ |
473 | def test_upgrade_charm(self): |
474 | env = ModelClient( |
475 | JujuData('foo', {'type': 'local'}), '2.34-74', None) |
476 | - with patch.object(env, 'juju') as mock_juju: |
477 | + with patch_juju_call(env) as mock_juju: |
478 | env.upgrade_charm('foo-service', |
479 | '/bar/repository/angsty/mongodb') |
480 | mock_juju.assert_called_once_with( |
481 | @@ -1412,7 +1415,7 @@ |
482 | def test_remove_service(self): |
483 | env = ModelClient( |
484 | JujuData('foo', {'type': 'local'}), '1.234-76', None) |
485 | - with patch.object(env, 'juju') as mock_juju: |
486 | + with patch_juju_call(env) as mock_juju: |
487 | env.remove_service('mondogb') |
488 | mock_juju.assert_called_with('remove-application', ('mondogb',)) |
489 | |
490 | @@ -1581,7 +1584,7 @@ |
491 | |
492 | def test_remove_machine(self): |
493 | client = fake_juju_client() |
494 | - with patch.object(client._backend, 'juju') as juju_mock: |
495 | + with patch_juju_call(client._backend) as juju_mock: |
496 | condition = client.remove_machine('0') |
497 | call = backend_call( |
498 | client, 'remove-machine', ('0',), 'name:name') |
499 | @@ -1590,7 +1593,7 @@ |
500 | |
501 | def test_remove_machine_force(self): |
502 | client = fake_juju_client() |
503 | - with patch.object(client._backend, 'juju') as juju_mock: |
504 | + with patch_juju_call(client._backend) as juju_mock: |
505 | client.remove_machine('0', force=True) |
506 | call = backend_call( |
507 | client, 'remove-machine', ('--force', '0'), 'name:name') |
508 | @@ -1985,7 +1988,7 @@ |
509 | |
510 | def test_list_models(self): |
511 | client = ModelClient(JujuData('foo'), None, None) |
512 | - with patch.object(client, 'juju') as j_mock: |
513 | + with patch_juju_call(client) as j_mock: |
514 | client.list_models() |
515 | j_mock.assert_called_once_with( |
516 | 'list-models', ('-c', 'foo'), include_e=False) |
517 | @@ -2197,7 +2200,7 @@ |
518 | |
519 | def test_list_controllers(self): |
520 | client = ModelClient(JujuData('foo'), None, None) |
521 | - with patch.object(client, 'juju') as j_mock: |
522 | + with patch_juju_call(client) as j_mock: |
523 | client.list_controllers() |
524 | j_mock.assert_called_once_with('list-controllers', (), include_e=False) |
525 | |
526 | @@ -2665,7 +2668,7 @@ |
527 | |
528 | def test_set_model_constraints(self): |
529 | client = ModelClient(JujuData('bar', {}), None, '/foo') |
530 | - with patch.object(client, 'juju') as juju_mock: |
531 | + with patch_juju_call(client) as juju_mock: |
532 | client.set_model_constraints({'bar': 'baz'}) |
533 | juju_mock.assert_called_once_with('set-model-constraints', |
534 | ('bar=baz',)) |
535 | @@ -2951,7 +2954,7 @@ |
536 | def test_restore_backup(self): |
537 | env = JujuData('qux') |
538 | client = ModelClient(env, None, '/foobar/baz') |
539 | - with patch.object(client, 'juju') as gjo_mock: |
540 | + with patch_juju_call(client) as gjo_mock: |
541 | client.restore_backup('quxx') |
542 | gjo_mock.assert_called_once_with( |
543 | 'restore-backup', |
544 | @@ -3233,7 +3236,7 @@ |
545 | |
546 | def test_set_config(self): |
547 | client = ModelClient(JujuData('bar', {}), None, '/foo') |
548 | - with patch.object(client, 'juju') as juju_mock: |
549 | + with patch_juju_call(client) as juju_mock: |
550 | client.set_config('foo', {'bar': 'baz'}) |
551 | juju_mock.assert_called_once_with('config', ('foo', 'bar=baz')) |
552 | |
553 | @@ -3288,7 +3291,7 @@ |
554 | |
555 | def test_upgrade_mongo(self): |
556 | client = ModelClient(JujuData('bar', {}), None, '/foo') |
557 | - with patch.object(client, 'juju') as juju_mock: |
558 | + with patch_juju_call(client) as juju_mock: |
559 | client.upgrade_mongo() |
560 | juju_mock.assert_called_once_with('upgrade-mongo', ()) |
561 | |
562 | @@ -3333,7 +3336,7 @@ |
563 | default_model = fake_client.model_name |
564 | default_controller = fake_client.env.controller.name |
565 | |
566 | - with patch.object(fake_client, 'juju', return_value=True): |
567 | + with patch_juju_call(fake_client): |
568 | fake_client.revoke(username) |
569 | fake_client.juju.assert_called_with('revoke', |
570 | ('-c', default_controller, |
571 | @@ -3413,7 +3416,7 @@ |
572 | env = JujuData('foo') |
573 | username = 'fakeuser' |
574 | client = ModelClient(env, None, None) |
575 | - with patch.object(client, 'juju') as mock: |
576 | + with patch_juju_call(client) as mock: |
577 | client.disable_user(username) |
578 | mock.assert_called_with( |
579 | 'disable-user', ('-c', 'foo', 'fakeuser'), include_e=False) |
580 | @@ -3422,7 +3425,7 @@ |
581 | env = JujuData('foo') |
582 | username = 'fakeuser' |
583 | client = ModelClient(env, None, None) |
584 | - with patch.object(client, 'juju') as mock: |
585 | + with patch_juju_call(client) as mock: |
586 | client.enable_user(username) |
587 | mock.assert_called_with( |
588 | 'enable-user', ('-c', 'foo', 'fakeuser'), include_e=False) |
589 | @@ -3430,7 +3433,7 @@ |
590 | def test_logout(self): |
591 | env = JujuData('foo') |
592 | client = ModelClient(env, None, None) |
593 | - with patch.object(client, 'juju') as mock: |
594 | + with patch_juju_call(client) as mock: |
595 | client.logout() |
596 | mock.assert_called_with( |
597 | 'logout', ('-c', 'foo'), include_e=False) |
598 | @@ -3670,32 +3673,32 @@ |
599 | |
600 | def test_disable_command(self): |
601 | client = ModelClient(JujuData('foo'), None, None) |
602 | - with patch.object(client, 'juju', autospec=True) as mock: |
603 | + with patch_juju_call(client) as mock: |
604 | client.disable_command('all', 'message') |
605 | mock.assert_called_once_with('disable-command', ('all', 'message')) |
606 | |
607 | def test_enable_command(self): |
608 | client = ModelClient(JujuData('foo'), None, None) |
609 | - with patch.object(client, 'juju', autospec=True) as mock: |
610 | + with patch_juju_call(client) as mock: |
611 | client.enable_command('all') |
612 | mock.assert_called_once_with('enable-command', 'all') |
613 | |
614 | def test_sync_tools(self): |
615 | client = ModelClient(JujuData('foo'), None, None) |
616 | - with patch.object(client, 'juju', autospec=True) as mock: |
617 | + with patch_juju_call(client) as mock: |
618 | client.sync_tools() |
619 | mock.assert_called_once_with('sync-tools', ()) |
620 | |
621 | def test_sync_tools_local_dir(self): |
622 | client = ModelClient(JujuData('foo'), None, None) |
623 | - with patch.object(client, 'juju', autospec=True) as mock: |
624 | + with patch_juju_call(client) as mock: |
625 | client.sync_tools('/agents') |
626 | mock.assert_called_once_with('sync-tools', ('--local-dir', '/agents'), |
627 | include_e=False) |
628 | |
629 | def test_generate_tool(self): |
630 | client = ModelClient(JujuData('foo'), None, None) |
631 | - with patch.object(client, 'juju', autospec=True) as mock: |
632 | + with patch_juju_call(client) as mock: |
633 | client.generate_tool('/agents') |
634 | mock.assert_called_once_with('metadata', |
635 | ('generate-tools', '-d', '/agents'), |
636 | @@ -3703,7 +3706,7 @@ |
637 | |
638 | def test_generate_tool_with_stream(self): |
639 | client = ModelClient(JujuData('foo'), None, None) |
640 | - with patch.object(client, 'juju', autospec=True) as mock: |
641 | + with patch_juju_call(client) as mock: |
642 | client.generate_tool('/agents', "testing") |
643 | mock.assert_called_once_with( |
644 | 'metadata', ('generate-tools', '-d', '/agents', |
645 | @@ -3711,7 +3714,7 @@ |
646 | |
647 | def test_add_cloud(self): |
648 | client = ModelClient(JujuData('foo'), None, None) |
649 | - with patch.object(client, 'juju', autospec=True) as mock: |
650 | + with patch_juju_call(client) as mock: |
651 | client.add_cloud('localhost', 'cfile') |
652 | mock.assert_called_once_with('add-cloud', |
653 | ('--replace', 'localhost', 'cfile'), |
654 | @@ -3720,7 +3723,7 @@ |
655 | def test_switch(self): |
656 | def run_switch_test(expect, model=None, controller=None): |
657 | client = ModelClient(JujuData('foo'), None, None) |
658 | - with patch.object(client, 'juju', autospec=True) as mock: |
659 | + with patch_juju_call(client) as mock: |
660 | client.switch(model=model, controller=controller) |
661 | mock.assert_called_once_with('switch', (expect,), include_e=False) |
662 | run_switch_test('default', 'default') |
663 | |
664 | === modified file 'jujupy/tests/test_version_client.py' |
665 | --- jujupy/tests/test_version_client.py 2017-03-23 04:50:58 +0000 |
666 | +++ jujupy/tests/test_version_client.py 2017-03-23 04:50:58 +0000 |
667 | @@ -69,6 +69,7 @@ |
668 | ) |
669 | from tests import ( |
670 | assert_juju_call, |
671 | + patch_juju_call, |
672 | FakeHomeTestCase, |
673 | FakePopen, |
674 | observable_temp_file, |
675 | @@ -432,7 +433,7 @@ |
676 | def test_upgrade_juju_nonlocal(self): |
677 | client = EnvJujuClient1X( |
678 | SimpleEnvironment('foo', {'type': 'nonlocal'}), '1.234-76', None) |
679 | - with patch.object(client, 'juju') as juju_mock: |
680 | + with patch_juju_call(client) as juju_mock: |
681 | client.upgrade_juju() |
682 | juju_mock.assert_called_with( |
683 | 'upgrade-juju', ('--version', '1.234')) |
684 | @@ -440,7 +441,7 @@ |
685 | def test_upgrade_juju_local(self): |
686 | client = EnvJujuClient1X( |
687 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
688 | - with patch.object(client, 'juju') as juju_mock: |
689 | + with patch_juju_call(client) as juju_mock: |
690 | client.upgrade_juju() |
691 | juju_mock.assert_called_with( |
692 | 'upgrade-juju', ('--version', '1.234', '--upload-tools',)) |
693 | @@ -448,7 +449,7 @@ |
694 | def test_upgrade_juju_no_force_version(self): |
695 | client = EnvJujuClient1X( |
696 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
697 | - with patch.object(client, 'juju') as juju_mock: |
698 | + with patch_juju_call(client) as juju_mock: |
699 | client.upgrade_juju(force_version=False) |
700 | juju_mock.assert_called_with( |
701 | 'upgrade-juju', ('--upload-tools',)) |
702 | @@ -485,14 +486,14 @@ |
703 | def test_bootstrap(self): |
704 | env = SimpleEnvironment('foo') |
705 | client = EnvJujuClient1X(env, None, None) |
706 | - with patch.object(client, 'juju') as mock: |
707 | + with patch_juju_call(client) as mock: |
708 | client.bootstrap() |
709 | mock.assert_called_with('bootstrap', ('--constraints', 'mem=2G')) |
710 | |
711 | def test_bootstrap_upload_tools(self): |
712 | env = SimpleEnvironment('foo') |
713 | client = EnvJujuClient1X(env, None, None) |
714 | - with patch.object(client, 'juju') as mock: |
715 | + with patch_juju_call(client) as mock: |
716 | client.bootstrap(upload_tools=True) |
717 | mock.assert_called_with( |
718 | 'bootstrap', ('--upload-tools', '--constraints', 'mem=2G')) |
719 | @@ -508,7 +509,7 @@ |
720 | env.update_config({ |
721 | 'default-series': 'angsty', |
722 | }) |
723 | - with patch.object(client, 'juju') as mock: |
724 | + with patch_juju_call(client) as mock: |
725 | client.bootstrap(bootstrap_series='angsty') |
726 | mock.assert_called_with('bootstrap', ('--constraints', 'mem=2G')) |
727 | |
728 | @@ -650,7 +651,7 @@ |
729 | def test_kill_controller_check(self): |
730 | client = EnvJujuClient1X( |
731 | SimpleEnvironment('foo', {'type': 'ec2'}), None, None) |
732 | - with patch.object(client, 'juju') as juju_mock: |
733 | + with patch_juju_call(client) as juju_mock: |
734 | client.kill_controller(check=True) |
735 | juju_mock.assert_called_once_with( |
736 | 'destroy-environment', ('foo', '--force', '-y'), check=True, |
737 | @@ -659,7 +660,7 @@ |
738 | def test_destroy_controller(self): |
739 | client = EnvJujuClient1X( |
740 | SimpleEnvironment('foo', {'type': 'ec2'}), None, None) |
741 | - with patch.object(client, 'juju') as juju_mock: |
742 | + with patch_juju_call(client) as juju_mock: |
743 | client.destroy_controller() |
744 | juju_mock.assert_called_once_with( |
745 | 'destroy-environment', ('foo', '-y'), |
746 | @@ -823,21 +824,21 @@ |
747 | def test_deploy_non_joyent(self): |
748 | env = EnvJujuClient1X( |
749 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
750 | - with patch.object(env, 'juju') as mock_juju: |
751 | + with patch_juju_call(env) as mock_juju: |
752 | env.deploy('mondogb') |
753 | mock_juju.assert_called_with('deploy', ('mondogb',)) |
754 | |
755 | def test_deploy_joyent(self): |
756 | env = EnvJujuClient1X( |
757 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
758 | - with patch.object(env, 'juju') as mock_juju: |
759 | + with patch_juju_call(env) as mock_juju: |
760 | env.deploy('mondogb') |
761 | mock_juju.assert_called_with('deploy', ('mondogb',)) |
762 | |
763 | def test_deploy_repository(self): |
764 | env = EnvJujuClient1X( |
765 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
766 | - with patch.object(env, 'juju') as mock_juju: |
767 | + with patch_juju_call(env) as mock_juju: |
768 | env.deploy('mondogb', '/home/jrandom/repo') |
769 | mock_juju.assert_called_with( |
770 | 'deploy', ('mondogb', '--repository', '/home/jrandom/repo')) |
771 | @@ -845,7 +846,7 @@ |
772 | def test_deploy_to(self): |
773 | env = EnvJujuClient1X( |
774 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
775 | - with patch.object(env, 'juju') as mock_juju: |
776 | + with patch_juju_call(env) as mock_juju: |
777 | env.deploy('mondogb', to='0') |
778 | mock_juju.assert_called_with( |
779 | 'deploy', ('mondogb', '--to', '0')) |
780 | @@ -853,7 +854,7 @@ |
781 | def test_deploy_service(self): |
782 | env = EnvJujuClient1X( |
783 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
784 | - with patch.object(env, 'juju') as mock_juju: |
785 | + with patch_juju_call(env) as mock_juju: |
786 | env.deploy('local:mondogb', service='my-mondogb') |
787 | mock_juju.assert_called_with( |
788 | 'deploy', ('local:mondogb', 'my-mondogb',)) |
789 | @@ -861,7 +862,7 @@ |
790 | def test_upgrade_charm(self): |
791 | client = EnvJujuClient1X( |
792 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
793 | - with patch.object(client, 'juju') as mock_juju: |
794 | + with patch_juju_call(client) as mock_juju: |
795 | client.upgrade_charm('foo-service', |
796 | '/bar/repository/angsty/mongodb') |
797 | mock_juju.assert_called_once_with( |
798 | @@ -871,7 +872,7 @@ |
799 | def test_remove_service(self): |
800 | client = EnvJujuClient1X( |
801 | SimpleEnvironment('foo', {'type': 'local'}), '1.234-76', None) |
802 | - with patch.object(client, 'juju') as mock_juju: |
803 | + with patch_juju_call(client) as mock_juju: |
804 | client.remove_service('mondogb') |
805 | mock_juju.assert_called_with('destroy-service', ('mondogb',)) |
806 | |
807 | @@ -1358,7 +1359,7 @@ |
808 | |
809 | def test_set_model_constraints(self): |
810 | client = EnvJujuClient1X(SimpleEnvironment('bar', {}), None, '/foo') |
811 | - with patch.object(client, 'juju') as juju_mock: |
812 | + with patch_juju_call(client) as juju_mock: |
813 | client.set_model_constraints({'bar': 'baz'}) |
814 | juju_mock.assert_called_once_with('set-constraints', ('bar=baz',)) |
815 | |
816 | @@ -1602,7 +1603,7 @@ |
817 | def test_enable_ha(self): |
818 | env = SimpleEnvironment('qux') |
819 | client = EnvJujuClient1X(env, None, '/foobar/baz') |
820 | - with patch.object(client, 'juju', autospec=True) as eha_mock: |
821 | + with patch_juju_call(client) as eha_mock: |
822 | client.enable_ha() |
823 | eha_mock.assert_called_once_with('ensure-availability', ('-n', '3')) |
824 | |
825 | @@ -1679,7 +1680,7 @@ |
826 | def test_deploy_bundle_1x(self): |
827 | client = EnvJujuClient1X(SimpleEnvironment('an_env', None), |
828 | '1.23-series-arch', None) |
829 | - with patch.object(client, 'juju') as mock_juju: |
830 | + with patch_juju_call(client) as mock_juju: |
831 | client.deploy_bundle('bundle:~juju-qa/some-bundle') |
832 | mock_juju.assert_called_with( |
833 | 'deployer', ('--debug', '--deploy-delay', '10', '--timeout', |
834 | @@ -1688,7 +1689,7 @@ |
835 | def test_deploy_bundle_template(self): |
836 | client = EnvJujuClient1X(SimpleEnvironment('an_env', None), |
837 | '1.23-series-arch', None) |
838 | - with patch.object(client, 'juju') as mock_juju: |
839 | + with patch_juju_call(client) as mock_juju: |
840 | client.deploy_bundle('bundle:~juju-qa/some-{container}-bundle') |
841 | mock_juju.assert_called_with( |
842 | 'deployer', ( |
843 | @@ -1933,14 +1934,14 @@ |
844 | def test_add_space(self): |
845 | client = EnvJujuClient1X(SimpleEnvironment(None, {'type': 'local'}), |
846 | '1.23-series-arch', None) |
847 | - with patch.object(client, 'juju', autospec=True) as juju_mock: |
848 | + with patch_juju_call(client) as juju_mock: |
849 | client.add_space('foo-space') |
850 | juju_mock.assert_called_once_with('space create', ('foo-space')) |
851 | |
852 | def test_add_subnet(self): |
853 | client = EnvJujuClient1X(SimpleEnvironment(None, {'type': 'local'}), |
854 | '1.23-series-arch', None) |
855 | - with patch.object(client, 'juju', autospec=True) as juju_mock: |
856 | + with patch_juju_call(client) as juju_mock: |
857 | client.add_subnet('bar-subnet', 'foo-space') |
858 | juju_mock.assert_called_once_with('subnet add', |
859 | ('bar-subnet', 'foo-space')) |
860 | @@ -1954,7 +1955,7 @@ |
861 | |
862 | def test_set_config(self): |
863 | client = EnvJujuClient1X(SimpleEnvironment('bar', {}), None, '/foo') |
864 | - with patch.object(client, 'juju') as juju_mock: |
865 | + with patch_juju_call(client) as juju_mock: |
866 | client.set_config('foo', {'bar': 'baz'}) |
867 | juju_mock.assert_called_once_with('set', ('foo', 'bar=baz')) |
868 | |
869 | @@ -2075,13 +2076,13 @@ |
870 | |
871 | def test_disable_command(self): |
872 | client = EnvJujuClient1X(SimpleEnvironment('foo'), None, None) |
873 | - with patch.object(client, 'juju', autospec=True) as mock: |
874 | + with patch_juju_call(client) as mock: |
875 | client.disable_command('all', 'message') |
876 | mock.assert_called_once_with('block all', ('message', )) |
877 | |
878 | def test_enable_command(self): |
879 | client = EnvJujuClient1X(SimpleEnvironment('foo'), None, None) |
880 | - with patch.object(client, 'juju', autospec=True) as mock: |
881 | + with patch_juju_call(client) as mock: |
882 | client.enable_command('all') |
883 | mock.assert_called_once_with('unblock', 'all') |
884 | |
885 | |
886 | === modified file 'jujupy/version_client.py' |
887 | --- jujupy/version_client.py 2017-03-23 04:50:58 +0000 |
888 | +++ jujupy/version_client.py 2017-03-23 04:50:58 +0000 |
889 | @@ -9,6 +9,8 @@ |
890 | import yaml |
891 | |
892 | from jujupy.client import ( |
893 | + BaseCondition, |
894 | + CommandComplete, |
895 | Controller, |
896 | _DEFAULT_BUNDLE_TIMEOUT, |
897 | get_cache_path, |
898 | @@ -356,7 +358,8 @@ |
899 | |
900 | def set_model_constraints(self, constraints): |
901 | constraint_strings = self._dict_as_option_strings(constraints) |
902 | - return self.juju('set-constraints', constraint_strings) |
903 | + retvar, ct = self.juju('set-constraints', constraint_strings) |
904 | + return retvar, CommandComplete(BaseCondition(), ct) |
905 | |
906 | def set_config(self, service, options): |
907 | option_strings = ['{}={}'.format(*item) for item in options.items()] |
908 | @@ -377,11 +380,13 @@ |
909 | def set_env_option(self, option, value): |
910 | """Set the value of the option in the environment.""" |
911 | option_value = "%s=%s" % (option, value) |
912 | - return self.juju('set-env', (option_value,)) |
913 | + retvar, ct = self.juju('set-env', (option_value,)) |
914 | + return retvar, CommandComplete(BaseCondition(), ct) |
915 | |
916 | def unset_env_option(self, option): |
917 | """Unset the value of the option in the environment.""" |
918 | - return self.juju('set-env', ('{}='.format(option),)) |
919 | + retvar, ct = self.juju('set-env', ('{}='.format(option),)) |
920 | + return retvar, CommandComplete(BaseCondition(), ct) |
921 | |
922 | def get_model_defaults(self, model_key, cloud=None, region=None): |
923 | log.info('No model-defaults stored for client (attempted get).') |
924 | @@ -480,18 +485,20 @@ |
925 | """Destroy the environment, with force. Hard kill option. |
926 | |
927 | :return: Subprocess's exit code.""" |
928 | - return self.juju( |
929 | + retvar, ct = self.juju( |
930 | 'destroy-environment', (self.env.environment, '--force', '-y'), |
931 | check=check, include_e=False, timeout=get_teardown_timeout(self)) |
932 | + return retvar, CommandComplete(BaseCondition(), ct) |
933 | |
934 | def destroy_controller(self, all_models=False): |
935 | """Destroy the environment, with force. Soft kill option. |
936 | |
937 | :param all_models: Ignored. |
938 | :raises: subprocess.CalledProcessError if the operation fails.""" |
939 | - return self.juju( |
940 | + retvar, ct = self.juju( |
941 | 'destroy-environment', (self.env.environment, '-y'), |
942 | include_e=False, timeout=get_teardown_timeout(self)) |
943 | + return retvar, CommandComplete(BaseCondition(), ct) |
944 | |
945 | def destroy_environment(self, force=True, delete_jenv=False): |
946 | if force: |
947 | @@ -555,7 +562,8 @@ |
948 | args.extend(['--storage', storage]) |
949 | if constraints is not None: |
950 | args.extend(['--constraints', constraints]) |
951 | - return self.juju('deploy', tuple(args)) |
952 | + retvar, ct = self.juju('deploy', tuple(args)) |
953 | + return retvar, CommandComplete(BaseCondition(), ct) |
954 | |
955 | def upgrade_charm(self, service, charm_path=None): |
956 | args = (service,) |
957 | @@ -644,11 +652,13 @@ |
958 | |
959 | def disable_command(self, command_set, message=''): |
960 | """Disable a command-set.""" |
961 | - return self.juju('block {}'.format(command_set), (message, )) |
962 | + retvar, ct = self.juju('block {}'.format(command_set), (message, )) |
963 | + return retvar, CommandComplete(BaseCondition(), ct) |
964 | |
965 | def enable_command(self, args): |
966 | """Enable a command-set.""" |
967 | - return self.juju('unblock', args) |
968 | + retvar, ct = self.juju('unblock', args) |
969 | + return retvar, CommandComplete(BaseCondition(), ct) |
970 | |
971 | |
972 | class EnvJujuClient22(EnvJujuClient1X): |
973 | |
974 | === modified file 'tests/__init__.py' |
975 | --- tests/__init__.py 2017-03-23 04:50:58 +0000 |
976 | +++ tests/__init__.py 2017-03-23 04:50:58 +0000 |
977 | @@ -20,6 +20,7 @@ |
978 | from unittest.mock import patch |
979 | import yaml |
980 | |
981 | +from jujupy.client import CommandTime |
982 | import utility |
983 | |
984 | |
985 | @@ -153,13 +154,15 @@ |
986 | |
987 | |
988 | @contextmanager |
989 | -def patch_juju_call(client, return_value=(0, None)): |
990 | +def patch_juju_call(client, return_value=0): |
991 | """Simple patch for client.juju call. |
992 | |
993 | :param return_value: A tuple to return representing the retvar and |
994 | CommandTime object |
995 | """ |
996 | - with patch.object(client, 'juju', return_value=return_value) as mock: |
997 | + with patch.object( |
998 | + client, 'juju', |
999 | + return_value=make_fake_juju_return(retvar=return_value)) as mock: |
1000 | yield mock |
1001 | |
1002 | |
1003 | @@ -168,7 +171,7 @@ |
1004 | """Check a mock's positional arguments. |
1005 | |
1006 | :param test_case: The test case currently being run. |
1007 | - :param mock_mothod: The mock object to be checked. |
1008 | + :param mock_method: The mock object to be checked. |
1009 | :param client: Ignored. |
1010 | :param expected_args: The expected positional arguments for the call. |
1011 | :param call_index: Index of the call to check, if None checks first call |
1012 | @@ -259,3 +262,9 @@ |
1013 | }, |
1014 | } |
1015 | } |
1016 | + |
1017 | + |
1018 | +def make_fake_juju_return( |
1019 | + retvar=0, cmd='mock_cmd', full_args=[], envvars=None, start=None): |
1020 | + """Shadow fake that defaults construction arguments.""" |
1021 | + return (retvar, CommandTime(cmd, full_args, envvars, start)) |
1022 | |
1023 | === modified file 'tests/test_assess_block.py' |
1024 | --- tests/test_assess_block.py 2017-01-20 20:49:41 +0000 |
1025 | +++ tests/test_assess_block.py 2017-03-23 04:50:58 +0000 |
1026 | @@ -18,6 +18,7 @@ |
1027 | ) |
1028 | from tests import ( |
1029 | parse_error, |
1030 | + patch_juju_call, |
1031 | FakeHomeTestCase, |
1032 | TestCase, |
1033 | ) |
1034 | @@ -149,7 +150,7 @@ |
1035 | autospec=True, side_effect=side_effects): |
1036 | with patch('assess_block.deploy_dummy_stack', autospec=True): |
1037 | with patch.object(client, 'remove_service') as mock_rs: |
1038 | - with patch.object(client, 'juju') as mock_juju: |
1039 | + with patch_juju_call(client) as mock_juju: |
1040 | with patch.object( |
1041 | client, 'wait_for_started') as mock_ws: |
1042 | assess_block(client, 'trusty') |
1043 | |
1044 | === modified file 'tests/test_assess_bootstrap.py' |
1045 | --- tests/test_assess_bootstrap.py 2017-03-01 19:02:24 +0000 |
1046 | +++ tests/test_assess_bootstrap.py 2017-03-23 04:50:58 +0000 |
1047 | @@ -29,6 +29,7 @@ |
1048 | from tests import ( |
1049 | FakeHomeTestCase, |
1050 | TestCase, |
1051 | + make_fake_juju_return, |
1052 | ) |
1053 | from utility import ( |
1054 | JujuAssertionError, |
1055 | @@ -361,7 +362,7 @@ |
1056 | args.temp_env_name = 'qux' |
1057 | with extended_bootstrap_cxt('2.0.0'): |
1058 | with patch('jujupy.ModelClient.juju', autospec=True, |
1059 | - side_effect=['', '']) as j_mock: |
1060 | + return_value=make_fake_juju_return()) as j_mock: |
1061 | with patch('assess_bootstrap.get_controller_hostname', |
1062 | return_value='test-host', autospec=True): |
1063 | bs_manager = BootstrapManager.from_args(args) |
1064 | |
1065 | === modified file 'tests/test_assess_user_grant_revoke.py' |
1066 | --- tests/test_assess_user_grant_revoke.py 2017-01-20 21:35:27 +0000 |
1067 | +++ tests/test_assess_user_grant_revoke.py 2017-03-23 04:50:58 +0000 |
1068 | @@ -27,6 +27,7 @@ |
1069 | from tests import ( |
1070 | parse_error, |
1071 | TestCase, |
1072 | + patch_juju_call, |
1073 | ) |
1074 | |
1075 | |
1076 | @@ -150,7 +151,7 @@ |
1077 | def test_assert_write_model(self): |
1078 | fake_client = fake_juju_client() |
1079 | with patch.object(fake_client, 'wait_for_started'): |
1080 | - with patch.object(fake_client, 'juju', return_value=True): |
1081 | + with patch_juju_call(fake_client): |
1082 | assert_write_model(fake_client, 'write', True) |
1083 | with self.assertRaises(JujuAssertionError): |
1084 | assert_write_model(fake_client, 'write', False) |
1085 | |
1086 | === modified file 'tests/test_deploy_stack.py' |
1087 | --- tests/test_deploy_stack.py 2017-03-10 00:50:40 +0000 |
1088 | +++ tests/test_deploy_stack.py 2017-03-23 04:50:58 +0000 |
1089 | @@ -82,6 +82,7 @@ |
1090 | assert_juju_call, |
1091 | FakeHomeTestCase, |
1092 | FakePopen, |
1093 | + make_fake_juju_return, |
1094 | observable_temp_file, |
1095 | temp_os_env, |
1096 | use_context, |
1097 | @@ -1757,7 +1758,7 @@ |
1098 | def do_check(*args, **kwargs): |
1099 | with client.check_timeouts(): |
1100 | with tear_down_client.check_timeouts(): |
1101 | - pass |
1102 | + return make_fake_juju_return() |
1103 | |
1104 | with patch.object(bs_manager.tear_down_client, 'juju', |
1105 | side_effect=do_check, autospec=True): |
1106 | @@ -1996,7 +1997,9 @@ |
1107 | bs_manager.has_controller = False |
1108 | with patch('deploy_stack.safe_print_status', |
1109 | autospec=True) as sp_mock: |
1110 | - with patch.object(client, 'juju', wrap=client.juju) as juju_mock: |
1111 | + with patch.object( |
1112 | + client, 'juju', wrap=client.juju, |
1113 | + return_value=make_fake_juju_return()) as juju_mock: |
1114 | with patch.object(client, 'get_juju_output', |
1115 | wraps=client.get_juju_output) as gjo_mock: |
1116 | with patch.object(bs_manager, '_should_dump', |
1117 | @@ -2085,7 +2088,9 @@ |
1118 | """Preform patches to focus on the call to bootstrap.""" |
1119 | with patch.object(bs_manager, 'dump_all_logs'): |
1120 | with patch.object(bs_manager, 'runtime_context'): |
1121 | - with patch.object(bs_manager.client, 'juju'): |
1122 | + with patch.object( |
1123 | + bs_manager.client, 'juju', |
1124 | + return_value=make_fake_juju_return()): |
1125 | with patch.object(bs_manager.client, 'bootstrap') as mock: |
1126 | yield mock |
1127 |
Thank you.