Merge lp:~hazmat/pyjuju/env-safety-belt into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Approved by: Clint Byrum
Approved revision: 580
Merged at revision: 624
Proposed branch: lp:~hazmat/pyjuju/env-safety-belt
Merge into: lp:pyjuju
Diff against target: 59 lines (+30/-0)
3 files modified
juju/control/destroy_environment.py (+6/-0)
juju/control/tests/test_destroy_environment.py (+20/-0)
juju/environment/environment.py (+4/-0)
To merge this branch: bzr merge lp:~hazmat/pyjuju/env-safety-belt
Reviewer Review Type Date Requested Status
Clint Byrum (community) Approve
Review via email: mp+126819@code.launchpad.net

Description of the change

configuration safety belt for environments.

Per request, an environment with a client side config value of prevent-destroy:
true will not allow itself to be destroyed via juju destroy-environment, and
appropriate message to that effect will instead result on an attempt.

https://codereview.appspot.com/6574059/

To post a comment you must log in.
Revision history for this message
Kapil Thangavelu (hazmat) wrote :
Download full text (3.4 KiB)

Reviewers: mp+126819_code.launchpad.net,

Message:
Please take a look.

Description:
configuration safety belt for environments.

Per request, an environment with a client side config value of
prevent-destroy:
true will not allow itself to be destroyed via juju destroy-environment,
and
appropriate message to that effect will instead result on an attempt.

https://code.launchpad.net/~hazmat/juju/env-safety-belt/+merge/126819

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6574059/

Affected files:
   A [revision details]
   M juju/control/destroy_environment.py
   M juju/control/tests/test_destroy_environment.py
   M juju/environment/environment.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: juju/control/destroy_environment.py
=== modified file 'juju/control/destroy_environment.py'
--- juju/control/destroy_environment.py 2012-07-13 15:12:02 +0000
+++ juju/control/destroy_environment.py 2012-09-27 21:53:57 +0000
@@ -21,6 +21,12 @@
      environment = get_environment(options)
      provider = environment.get_machine_provider()

+ if environment.prevent_destroy:
+ options.log.warning(
+ "Environment %r configuration prevents destruction" % (
+ environment.name))
+ return
+
      value = raw_input(
          "WARNING: this command will destroy the %r environment
(type: %s).\n"
          "This includes all machines, services, data, and other resources. "

Index: juju/environment/environment.py
=== modified file 'juju/environment/environment.py'
--- juju/environment/environment.py 2012-04-06 18:53:52 +0000
+++ juju/environment/environment.py 2012-09-27 21:53:57 +0000
@@ -56,3 +56,7 @@
      def origin(self):
          """Returns the origin of the code."""
          return self._environment_config.get("juju-origin", "distro")
+
+ @property
+ def prevent_destroy(self):
+ return self._environment_config.get("prevent-destroy", False)

Index: juju/control/tests/test_destroy_environment.py
=== modified file 'juju/control/tests/test_destroy_environment.py'
--- juju/control/tests/test_destroy_environment.py 2012-09-10 03:20:20 +0000
+++ juju/control/tests/test_destroy_environment.py 2012-09-27 21:53:57 +0000
@@ -11,6 +11,26 @@
  class ControlDestroyEnvironmentTest(ControlToolTest):

      @inlineCallbacks
+ def test_prevent_destroy_setting(self):
+ """Environment config can explicitly prevent destruction.
+ """
+ config = {
+ 'environments': {'firstenv': {
+ 'type': 'dummy', 'prevent-destroy': True}}
+ }
+ self.write_config(dump(config))
+ finished = self.setup_cli_reactor()
+ self.setup_exit(0)
+ self.mocker.replay()
+
+ stderr = self.capture_logging()
+ main(['destroy-environment'])
+ yield finished
+ self.assertIn(
+ "Environment 'firstenv' co...

Read more...

Revision history for this message
Clint Byrum (clint-fewbar) wrote :

LGTM, and a nice idea, though it exposes a hole in SCHEMA that we can't specify global options like this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/control/destroy_environment.py'
2--- juju/control/destroy_environment.py 2012-07-13 15:12:02 +0000
3+++ juju/control/destroy_environment.py 2012-09-27 22:25:22 +0000
4@@ -21,6 +21,12 @@
5 environment = get_environment(options)
6 provider = environment.get_machine_provider()
7
8+ if environment.prevent_destroy:
9+ options.log.warning(
10+ "Environment %r configuration prevents destruction" % (
11+ environment.name))
12+ return
13+
14 value = raw_input(
15 "WARNING: this command will destroy the %r environment (type: %s).\n"
16 "This includes all machines, services, data, and other resources. "
17
18=== modified file 'juju/control/tests/test_destroy_environment.py'
19--- juju/control/tests/test_destroy_environment.py 2012-09-10 03:20:20 +0000
20+++ juju/control/tests/test_destroy_environment.py 2012-09-27 22:25:22 +0000
21@@ -11,6 +11,26 @@
22 class ControlDestroyEnvironmentTest(ControlToolTest):
23
24 @inlineCallbacks
25+ def test_prevent_destroy_setting(self):
26+ """Environment config can explicitly prevent destruction.
27+ """
28+ config = {
29+ 'environments': {'firstenv': {
30+ 'type': 'dummy', 'prevent-destroy': True}}
31+ }
32+ self.write_config(dump(config))
33+ finished = self.setup_cli_reactor()
34+ self.setup_exit(0)
35+ self.mocker.replay()
36+
37+ stderr = self.capture_logging()
38+ main(['destroy-environment'])
39+ yield finished
40+ self.assertIn(
41+ "Environment 'firstenv' configuration prevents destruction",
42+ stderr.getvalue())
43+
44+ @inlineCallbacks
45 def test_destroy_multiple_environments_no_default(self):
46 """With multiple environments a default needs to be set or passed.
47 """
48
49=== modified file 'juju/environment/environment.py'
50--- juju/environment/environment.py 2012-04-06 18:53:52 +0000
51+++ juju/environment/environment.py 2012-09-27 22:25:22 +0000
52@@ -56,3 +56,7 @@
53 def origin(self):
54 """Returns the origin of the code."""
55 return self._environment_config.get("juju-origin", "distro")
56+
57+ @property
58+ def prevent_destroy(self):
59+ return self._environment_config.get("prevent-destroy", False)

Subscribers

People subscribed via source and target branches

to status/vote changes: