Merge lp:~hazmat/pyjuju/deploy-invalid-conf into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Approved by: Jim Baker
Approved revision: 448
Merged at revision: 455
Proposed branch: lp:~hazmat/pyjuju/deploy-invalid-conf
Merge into: lp:pyjuju
Diff against target: 82 lines (+28/-8)
2 files modified
juju/control/deploy.py (+9/-7)
juju/control/tests/test_deploy.py (+19/-1)
To merge this branch: bzr merge lp:~hazmat/pyjuju/deploy-invalid-conf
Reviewer Review Type Date Requested Status
Jim Baker (community) Approve
Review via email: mp+90321@code.launchpad.net

Description of the change

Validate config options before deploying.

It was previously possible to deploy a service with an invalid config, which
would result in a service with no units active in the environment. With the
change on invalid config with deploy, no service will be created in the
environment.

https://codereview.appspot.com/5572068/

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

Reviewers: mp+90321_code.launchpad.net,

Message:
Please take a look.

Description:
It was previously possible to deploy a service with an invalid config,
which
would result in a service with no units active in the environment. With
the
change on invalid config with deploy, no service will be created in the
environment.

https://code.launchpad.net/~hazmat/juju/deploy-invalid-conf/+merge/90321

(do not edit description out of merge proposal)

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

Affected files:
   M juju/control/deploy.py
   M juju/control/tests/test_deploy.py

Index: juju/control/deploy.py
=== <email address hidden> >
<email address hidden>
=== modified file 'juju/control/deploy.py'
--- juju/control/deploy.py 2011-12-07 02:26:56 +0000
+++ juju/control/deploy.py 2012-01-26 19:39:06 +0000
@@ -65,7 +65,7 @@
          num_units=options.num_units)

-def parse_config_options(config_file, service_name):
+def parse_config_options(config_file, service_name, charm):
      if not os.path.exists(config_file) or \
              not os.access(config_file, os.R_OK):
          raise ServiceConfigValueError(
@@ -77,8 +77,9 @@
          raise ServiceConfigValueError(
              "Invalid options file passed to --config.\n"
              "Expected a YAML dict with service name (%r)." % service_name)
- # remove the service name prefix for application to state
- return options[service_name]
+
+ # Validate and type service options and return
+ return charm.config.validate(options[service_name])

  @inlineCallbacks
@@ -93,14 +94,15 @@
      repo, charm_url = resolve(
          charm_name, repository_path, environment.default_series)

+ charm = yield repo.find(charm_url)
+ charm_id = str(charm_url.with_revision(charm.get_revision()))
+
      # Validate config options prior to deployment attempt
      service_options = {}
      service_name = service_name or charm_url.name
      if config_file:
- service_options = parse_config_options(config_file, service_name)
-
- charm = yield repo.find(charm_url)
- charm_id = str(charm_url.with_revision(charm.get_revision()))
+ service_options = parse_config_options(
+ config_file, service_name, charm)

      provider = environment.get_machine_provider()
      placement_policy = provider.get_placement_policy()

Index: juju/control/tests/test_deploy.py
=== <email address hidden> >
<email address hidden>
=== modified file 'juju/control/tests/test_deploy.py'
--- juju/control/tests/test_deploy.py 2011-11-29 20:49:04 +0000
+++ juju/control/tests/test_deploy.py 2012-01-26 19:39:06 +0000
@@ -8,7 +8,7 @@
  from juju.environment.config import EnvironmentsConfig
  from juju.charm.errors import ServiceConfigValueError
  from juju.state.environment import EnvironmentStateManager
-from juju.state.errors import ServiceStateNameInUse
+from juju.state.errors import ServiceStateNameInUse, ServiceStateNotFound
  from juju.state.service import ServiceStateManager
  from juju.state.relation import RelationSta...

Read more...

Revision history for this message
Benjamin Saller (bcsaller) wrote :
Download full text (4.6 KiB)

LGTM +1

On Thu, Jan 26, 2012 at 11:50 AM, Kapil Thangavelu
<email address hidden> wrote:
> Reviewers: mp+90321_code.launchpad.net,
>
> Message:
> Please take a look.
>
> Description:
> It was previously possible to deploy a service with an invalid config,
> which
> would result in a service with no units active in the environment. With
> the
> change on invalid config with deploy, no service will be created in the
> environment.
>
> https://code.launchpad.net/~hazmat/juju/deploy-invalid-conf/+merge/90321
>
> (do not edit description out of merge proposal)
>
>
> Please review this at https://codereview.appspot.com/5572068/
>
> Affected files:
>   M juju/control/deploy.py
>   M juju/control/tests/test_deploy.py
>
>
> Index: juju/control/deploy.py
> === <email address hidden> >
> <email address hidden>
> === modified file 'juju/control/deploy.py'
> --- juju/control/deploy.py      2011-12-07 02:26:56 +0000
> +++ juju/control/deploy.py      2012-01-26 19:39:06 +0000
> @@ -65,7 +65,7 @@
>          num_units=options.num_units)
>
>
> -def parse_config_options(config_file, service_name):
> +def parse_config_options(config_file, service_name, charm):
>      if not os.path.exists(config_file) or \
>              not os.access(config_file, os.R_OK):
>          raise ServiceConfigValueError(
> @@ -77,8 +77,9 @@
>          raise ServiceConfigValueError(
>              "Invalid options file passed to --config.\n"
>              "Expected a YAML dict with service name (%r)." % service_name)
> -    # remove the service name prefix for application to state
> -    return options[service_name]
> +
> +    # Validate and type service options and return
> +    return charm.config.validate(options[service_name])
>
>
>  @inlineCallbacks
> @@ -93,14 +94,15 @@
>      repo, charm_url = resolve(
>          charm_name, repository_path, environment.default_series)
>
> +    charm = yield repo.find(charm_url)
> +    charm_id = str(charm_url.with_revision(charm.get_revision()))
> +
>      # Validate config options prior to deployment attempt
>      service_options = {}
>      service_name = service_name or charm_url.name
>      if config_file:
> -        service_options = parse_config_options(config_file, service_name)
> -
> -    charm = yield repo.find(charm_url)
> -    charm_id = str(charm_url.with_revision(charm.get_revision()))
> +        service_options = parse_config_options(
> +            config_file, service_name, charm)
>
>      provider = environment.get_machine_provider()
>      placement_policy = provider.get_placement_policy()
>
>
> Index: juju/control/tests/test_deploy.py
> === <email address hidden> >
> <email address hidden>
> === modified file 'juju/control/tests/test_deploy.py'
> --- juju/control/tests/test_deploy.py   2011-11-29 20:49:04 +0000
> +++ juju/control/tests/test_deploy.py   2012-01-26 19:39:06 +0000
> @@ -8,7 +8,7 @@
>  from juju.environment.config import EnvironmentsConfig
>  from juju.charm.errors import ServiceConfigValueError
>  from juju.state.environment import Environmen...

Read more...

Revision history for this message
Jim Baker (jimbaker) wrote :

+1, looks good to me. Nearly a trivial.

Looks like Ben should have marked his comment approved too, so I'll will approve the branch too.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'juju/control/deploy.py'
--- juju/control/deploy.py 2011-12-07 02:26:56 +0000
+++ juju/control/deploy.py 2012-01-26 19:46:25 +0000
@@ -65,7 +65,7 @@
65 num_units=options.num_units)65 num_units=options.num_units)
6666
6767
68def parse_config_options(config_file, service_name):68def parse_config_options(config_file, service_name, charm):
69 if not os.path.exists(config_file) or \69 if not os.path.exists(config_file) or \
70 not os.access(config_file, os.R_OK):70 not os.access(config_file, os.R_OK):
71 raise ServiceConfigValueError(71 raise ServiceConfigValueError(
@@ -77,8 +77,9 @@
77 raise ServiceConfigValueError(77 raise ServiceConfigValueError(
78 "Invalid options file passed to --config.\n"78 "Invalid options file passed to --config.\n"
79 "Expected a YAML dict with service name (%r)." % service_name)79 "Expected a YAML dict with service name (%r)." % service_name)
80 # remove the service name prefix for application to state80
81 return options[service_name]81 # Validate and type service options and return
82 return charm.config.validate(options[service_name])
8283
8384
84@inlineCallbacks85@inlineCallbacks
@@ -93,14 +94,15 @@
93 repo, charm_url = resolve(94 repo, charm_url = resolve(
94 charm_name, repository_path, environment.default_series)95 charm_name, repository_path, environment.default_series)
9596
97 charm = yield repo.find(charm_url)
98 charm_id = str(charm_url.with_revision(charm.get_revision()))
99
96 # Validate config options prior to deployment attempt100 # Validate config options prior to deployment attempt
97 service_options = {}101 service_options = {}
98 service_name = service_name or charm_url.name102 service_name = service_name or charm_url.name
99 if config_file:103 if config_file:
100 service_options = parse_config_options(config_file, service_name)104 service_options = parse_config_options(
101105 config_file, service_name, charm)
102 charm = yield repo.find(charm_url)
103 charm_id = str(charm_url.with_revision(charm.get_revision()))
104106
105 provider = environment.get_machine_provider()107 provider = environment.get_machine_provider()
106 placement_policy = provider.get_placement_policy()108 placement_policy = provider.get_placement_policy()
107109
=== modified file 'juju/control/tests/test_deploy.py'
--- juju/control/tests/test_deploy.py 2011-11-29 20:49:04 +0000
+++ juju/control/tests/test_deploy.py 2012-01-26 19:46:25 +0000
@@ -8,7 +8,7 @@
8from juju.environment.config import EnvironmentsConfig8from juju.environment.config import EnvironmentsConfig
9from juju.charm.errors import ServiceConfigValueError9from juju.charm.errors import ServiceConfigValueError
10from juju.state.environment import EnvironmentStateManager10from juju.state.environment import EnvironmentStateManager
11from juju.state.errors import ServiceStateNameInUse11from juju.state.errors import ServiceStateNameInUse, ServiceStateNotFound
12from juju.state.service import ServiceStateManager12from juju.state.service import ServiceStateManager
13from juju.state.relation import RelationStateManager13from juju.state.relation import RelationStateManager
1414
@@ -290,6 +290,24 @@
290 "Expected a YAML dict with service name ('myblog').", str(error))290 "Expected a YAML dict with service name ('myblog').", str(error))
291291
292 @inlineCallbacks292 @inlineCallbacks
293 def test_deploy_with_invalid_config(self):
294 """Can't deploy with config that doesn't pass charm validation."""
295 config_file = self.makeFile(
296 yaml.dump(dict(myblog=dict(application_file="foo"))))
297 environment = self.config.get("firstenv")
298
299 failure = deploy.deploy(
300 self.config, environment, self.unbundled_repo_path, "local:sample",
301 "myblog", logging.getLogger("deploy"), config_file)
302 error = yield self.assertFailure(failure, ServiceConfigValueError)
303 self.assertIn(
304 "application_file is not a valid configuration option",
305 str(error))
306 yield self.assertFailure(
307 ServiceStateManager(self.client).get_service_state("myblog"),
308 ServiceStateNotFound)
309
310 @inlineCallbacks
293 def test_deploy_with_config(self):311 def test_deploy_with_config(self):
294 """Valid config options should be available to the deployed312 """Valid config options should be available to the deployed
295 service."""313 service."""

Subscribers

People subscribed via source and target branches

to status/vote changes: