Merge lp:~frankban/juju-quickstart/fix-num-units into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 133
Proposed branch: lp:~frankban/juju-quickstart/fix-num-units
Merge into: lp:juju-quickstart
Diff against target: 72 lines (+25/-4)
4 files modified
quickstart/__init__.py (+1/-1)
quickstart/models/bundles.py (+1/-1)
quickstart/tests/functional/test_functional.py (+11/-2)
quickstart/tests/models/test_bundles.py (+12/-0)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/fix-num-units
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+258972@code.launchpad.net

Description of the change

Fix key error: num_units not defined in services.

https://codereview.appspot.com/235490043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (3.9 KiB)

Reviewers: mp+258972_code.launchpad.net,

Message:
Please take a look.

Description:
Fix key error: num_units not defined in services.

https://code.launchpad.net/~frankban/juju-quickstart/fix-num-units/+merge/258972

(do not edit description out of merge proposal)

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

Affected files (+27, -4 lines):
   A [revision details]
   M quickstart/__init__.py
   M quickstart/models/bundles.py
   M quickstart/tests/functional/test_functional.py
   M quickstart/tests/models/test_bundles.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: quickstart/__init__.py
=== modified file 'quickstart/__init__.py'
--- quickstart/__init__.py 2015-05-11 10:55:51 +0000
+++ quickstart/__init__.py 2015-05-13 08:27:30 +0000
@@ -45,7 +45,7 @@
  Once Juju has been installed, the command can also be run as a juju plugin,
  without the hyphen ("juju quickstart").
  """
-VERSION = (2, 1, 0)
+VERSION = (2, 1, 1)

  def get_version():

Index: quickstart/models/bundles.py
=== modified file 'quickstart/models/bundles.py'
--- quickstart/models/bundles.py 2015-04-24 13:31:28 +0000
+++ quickstart/models/bundles.py 2015-05-13 08:31:51 +0000
@@ -113,7 +113,7 @@
          services = self.data['services']
          result = collections.OrderedDict()
          for service_name in sorted(services.keys()):
- result[service_name] = services[service_name]['num_units']
+ result[service_name] = services[service_name].get('num_units',
0)
          return result

Index: quickstart/tests/functional/test_functional.py
=== modified file 'quickstart/tests/functional/test_functional.py'
--- quickstart/tests/functional/test_functional.py 2015-02-26 19:12:17 +0000
+++ quickstart/tests/functional/test_functional.py 2015-05-13 08:31:51 +0000
@@ -166,8 +166,17 @@

      def test_bundle_deployment(self):
          # The application can be used to deploy bundles.
- retcode, output, error = run_quickstart(
- self.env_name, 'mediawiki-single')
+ self._check_bundle('mediawiki-single/7')
+
+ def test_user_owned_bundle_deployment(self):
+ # The application can be used to deploy user owned bundles.
+ # The kubernetes bundle also includes subordinate services not
+ # including the "num_units" field.
+ self._check_bundle('u/kubernetes/kubernetes-cluster/3')
+
+ def _check_bundle(self, bundle_name):
+ """Ensure the given bundle name can be properly deployed."""
+ retcode, output, error = run_quickstart(self.env_name, bundle_name)
          self.assertEqual(0, retcode)
          self.assertIn('bundle deployment request accepted', output)
          self.assertEqual('', error)

Index: quickstart/tests/models/test_bundles.py
=== modified file 'quickstart/tests/models/test_bundles.py'
--- quickstart/tests/models/test_bundles.py 2015-04-28 15:25:14 +0000
+++ quic...

Read more...

Revision history for this message
Martin Hilton (martin-hilton) wrote :

LGTM, but make sure that the default 0 is correct for all cases.

https://codereview.appspot.com/235490043/diff/1/quickstart/models/bundles.py
File quickstart/models/bundles.py (left):

https://codereview.appspot.com/235490043/diff/1/quickstart/models/bundles.py#oldcode116
quickstart/models/bundles.py:116: result[service_name] =
services[service_name]['num_units']
Is 0 always a good default? I thought for subordinates it should be 0
but for normal charms it should be 1.

https://codereview.appspot.com/235490043/

136. By Francesco Banconi

None units

Revision history for this message
Francesco Banconi (frankban) wrote :
Revision history for this message
Uros Jovanovic (uros-jovanovic) wrote :

On 2015/05/13 08:49:04, frankban wrote:
> Please take a look.

LGTM now.

https://codereview.appspot.com/235490043/

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Fix key error: num_units not defined in services.

R=martin.hilton, uros.jovanovic1
CC=
https://codereview.appspot.com/235490043

https://codereview.appspot.com/235490043/

Revision history for this message
Francesco Banconi (frankban) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quickstart/__init__.py'
2--- quickstart/__init__.py 2015-05-11 10:55:51 +0000
3+++ quickstart/__init__.py 2015-05-13 08:46:43 +0000
4@@ -45,7 +45,7 @@
5 Once Juju has been installed, the command can also be run as a juju plugin,
6 without the hyphen ("juju quickstart").
7 """
8-VERSION = (2, 1, 0)
9+VERSION = (2, 1, 1)
10
11
12 def get_version():
13
14=== modified file 'quickstart/models/bundles.py'
15--- quickstart/models/bundles.py 2015-04-24 13:31:28 +0000
16+++ quickstart/models/bundles.py 2015-05-13 08:46:43 +0000
17@@ -113,7 +113,7 @@
18 services = self.data['services']
19 result = collections.OrderedDict()
20 for service_name in sorted(services.keys()):
21- result[service_name] = services[service_name]['num_units']
22+ result[service_name] = services[service_name].get('num_units')
23 return result
24
25
26
27=== modified file 'quickstart/tests/functional/test_functional.py'
28--- quickstart/tests/functional/test_functional.py 2015-02-26 19:12:17 +0000
29+++ quickstart/tests/functional/test_functional.py 2015-05-13 08:46:43 +0000
30@@ -166,8 +166,17 @@
31
32 def test_bundle_deployment(self):
33 # The application can be used to deploy bundles.
34- retcode, output, error = run_quickstart(
35- self.env_name, 'mediawiki-single')
36+ self._check_bundle('mediawiki-single/7')
37+
38+ def test_user_owned_bundle_deployment(self):
39+ # The application can be used to deploy user owned bundles.
40+ # The kubernetes bundle also includes subordinate services not
41+ # including the "num_units" field.
42+ self._check_bundle('u/kubernetes/kubernetes-cluster/3')
43+
44+ def _check_bundle(self, bundle_name):
45+ """Ensure the given bundle name can be properly deployed."""
46+ retcode, output, error = run_quickstart(self.env_name, bundle_name)
47 self.assertEqual(0, retcode)
48 self.assertIn('bundle deployment request accepted', output)
49 self.assertEqual('', error)
50
51=== modified file 'quickstart/tests/models/test_bundles.py'
52--- quickstart/tests/models/test_bundles.py 2015-04-28 15:25:14 +0000
53+++ quickstart/tests/models/test_bundles.py 2015-05-13 08:46:43 +0000
54@@ -121,6 +121,18 @@
55 [('mysql', 0), ('wordpress', 1)])
56 self.assertEqual(expected_services, self.bundle.services())
57
58+ def test_services_subordinate_units(self):
59+ # The number of units, if not defined, is None.
60+ bundle = bundles.Bundle({
61+ 'services': {
62+ 'logger': {'charm': 'cs:trusty/logger-42'},
63+ 'django': {'charm': 'django', 'num_units': 2},
64+ },
65+ })
66+ expected_services = collections.OrderedDict(
67+ [('django', 2), ('logger', None)])
68+ self.assertEqual(expected_services, bundle.services())
69+
70
71 class TestFromSource(
72 helpers.BundleFileTestsMixin, helpers.UrlReadTestsMixin,

Subscribers

People subscribed via source and target branches