Code review comment for lp:~frankban/juju-quickstart/fix-num-units

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

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
+++ quickstart/tests/models/test_bundles.py 2015-05-13 08:26:57 +0000
@@ -121,6 +121,18 @@
              [('mysql', 0), ('wordpress', 1)])
          self.assertEqual(expected_services, self.bundle.services())

+ def test_services_subordinate_units(self):
+ # The number of units for a subordinate service is zero.
+ bundle = bundles.Bundle({
+ 'services': {
+ 'logger': {'charm': 'cs:trusty/logger-42'},
+ 'django': {'charm': 'django', 'num_units': 2},
+ },
+ })
+ expected_services = collections.OrderedDict(
+ [('django', 2), ('logger', 0)])
+ self.assertEqual(expected_services, bundle.services())
+

  class TestFromSource(
          helpers.BundleFileTestsMixin, helpers.UrlReadTestsMixin,

« Back to merge proposal