Merge lp:~daker/pyjuju/small-fix into lp:pyjuju

Proposed by Adnane Belmadiaf
Status: Work in progress
Proposed branch: lp:~daker/pyjuju/small-fix
Merge into: lp:pyjuju
Diff against target: 78 lines (+45/-9)
2 files modified
ensemble/control/shutdown.py (+13/-9)
ensemble/tests/test_shutdown.py (+32/-0)
To merge this branch: bzr merge lp:~daker/pyjuju/small-fix
Reviewer Review Type Date Requested Status
Kapil Thangavelu (community) Approve
William Reade (community) Approve
Review via email: mp+68038@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ahmed Kamal (kim0) wrote :

I would actually love it if shutdown took a -y argument as well

lp:~daker/pyjuju/small-fix updated
277. By Adnane Belmadiaf

Added -y argument to shutdown command.

Revision history for this message
William Reade (fwereade) wrote :

Line 13 goes well over 80 characters, please break it.

Also: can I suggest that you use a name other than "choice" for the dest and variable names? I think something like "confirmed" would be a bit clearer (which environment you're using is also a choice, and so will be any other options we add in the future).

Otherwise, it works perfectly :).

review: Needs Resubmitting
lp:~daker/pyjuju/small-fix updated
278. By Adnane Belmadiaf

* Added --yes argument to shutdown command
* Changed dest variable name
* Other fixes

Revision history for this message
William Reade (fwereade) wrote :

Sorry, I think I was unclear before: I meant that the source line should be broken, not that the help text itself needed a line break.

I also just noticed that you've put spaces before colons, which isn't necessary. Please remove those, but otherwise I'm happy; +1.

review: Approve
lp:~daker/pyjuju/small-fix updated
279. By Adnane Belmadiaf

* Small fix

280. By Adnane Belmadiaf

* Remove spaces

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

There aren't any tests here. There should be a default=False for the param, especially given the is False condition afaics.

review: Needs Fixing
lp:~daker/pyjuju/small-fix updated
281. By Adnane Belmadiaf

* Added a default value

282. By Adnane Belmadiaf

* Added test case, props hazmat

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

Looks good +1

review: Approve
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

one additional question.. have you signed the contributor agreement per?
http://www.canonical.com/contributors

else it looks good to get merged.

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

marking work in progress while waiting on contrib agreement.

Revision history for this message
Adnane Belmadiaf (daker) wrote :

Ok, sorry for the late reply, i signed the agreement.

Unmerged revisions

282. By Adnane Belmadiaf

* Added test case, props hazmat

281. By Adnane Belmadiaf

* Added a default value

280. By Adnane Belmadiaf

* Remove spaces

279. By Adnane Belmadiaf

* Small fix

278. By Adnane Belmadiaf

* Added --yes argument to shutdown command
* Changed dest variable name
* Other fixes

277. By Adnane Belmadiaf

Added -y argument to shutdown command.

276. By Adnane Belmadiaf

Small fix.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ensemble/control/shutdown.py'
2--- ensemble/control/shutdown.py 2011-06-09 15:13:03 +0000
3+++ ensemble/control/shutdown.py 2011-07-21 17:57:49 +0000
4@@ -9,9 +9,12 @@
5 sub_parser.add_argument(
6 "--environment", "-e",
7 help="Ensemble environment to operate in.")
8+ sub_parser.add_argument(
9+ "--yes", "-y", dest='confirmed', action='store_true', default=False,
10+ help="Destroy all machines and services in the environment "
11+ "automatically.")
12 return sub_parser
13
14-
15 @inlineCallbacks
16 def command(options):
17 """
18@@ -19,14 +22,15 @@
19 """
20 environment = get_environment(options)
21 provider = environment.get_machine_provider()
22-
23- value = raw_input(
24- "Warning, this will destroy all machines and services in the\n"
25- "environment. Continue [y/N]")
26-
27- if value.strip().lower() not in ("y", "yes"):
28- options.log.info("Shutdown aborted")
29- returnValue(None)
30+ confirmed = options.confirmed
31+ if confirmed is False:
32+ value = raw_input(
33+ "Warning, this will destroy all machines and services in the\n"
34+ "environment. Continue [y/N]: ")
35+
36+ if value.strip().lower() not in ("y", "ye", "yes"):
37+ options.log.info("Shutdown aborted")
38+ returnValue(None)
39 options.log.info("Shutting down environment %r (type: %s)..." % (
40 environment.name, environment.type))
41 yield provider.shutdown()
42
43=== added file 'ensemble/tests/test_shutdown.py'
44--- ensemble/tests/test_shutdown.py 1970-01-01 00:00:00 +0000
45+++ ensemble/tests/test_shutdown.py 2011-07-21 17:57:49 +0000
46@@ -0,0 +1,32 @@
47+@inlineCallbacks
48+def test_shutdown_with_cli_confirm(self):
49+ """
50+ 'ensemble-control shutdown' will shutdown all configured instances
51+ in the specified environment. The confirmation prompt can be bypassed
52+ via a cli option.
53+ """
54+ config = {
55+ "ensemble": "environments",
56+ "environments": {"firstenv": {"type": "dummy"},
57+ "secondenv": {"type": "dummy"}}}
58+ self.write_config(dump(config))
59+ finished = self.setup_cli_reactor()
60+
61+ envs = set(("firstenv", "secondenv"))
62+
63+ def track_shutdown_call(self):
64+ envs.remove(self.environment_name)
65+ return succeed(True)
66+
67+ provider = self.mocker.patch(MachineProvider)
68+ provider.shutdown()
69+ self.mocker.call(track_shutdown_call, with_object=True)
70+
71+ self.setup_exit(0)
72+ self.mocker.replay()
73+
74+ main(["shutdown", "-y", "-e", "firstenv"])
75+ yield finished
76+ msg = "Shutting down environment 'firstenv' (type: dummy)..."
77+ self.assertIn(msg, self.log.getvalue())
78+ self.assertEqual(envs, set(["secondenv"]))

Subscribers

People subscribed via source and target branches

to status/vote changes: