Merge lp:~frankban/juju-quickstart/minor-fixes-0 into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 51
Proposed branch: lp:~frankban/juju-quickstart/minor-fixes-0
Merge into: lp:juju-quickstart
Diff against target: 170 lines (+56/-48)
5 files modified
HACKING.rst (+8/-0)
quickstart/app.py (+22/-22)
quickstart/manage.py (+5/-5)
quickstart/tests/test_app.py (+20/-20)
quickstart/tests/test_manage.py (+1/-1)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/minor-fixes-0
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+203942@code.launchpad.net

Description of the change

Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

https://codereview.appspot.com/58680043/

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

Reviewers: mp+203942_code.launchpad.net,

Message:
Please take a look.

Description:
Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

https://code.launchpad.net/~frankban/juju-quickstart/minor-fixes-0/+merge/203942

(do not edit description out of merge proposal)

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

Affected files (+58, -48 lines):
   M HACKING.rst
   A [revision details]
   M quickstart/app.py
   M quickstart/manage.py
   M quickstart/tests/test_app.py
   M quickstart/tests/test_manage.py

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

*** Submitted:

Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

R=bac
CC=
https://codereview.appspot.com/58680043

https://codereview.appspot.com/58680043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'HACKING.rst'
--- HACKING.rst 2013-11-20 08:58:02 +0000
+++ HACKING.rst 2014-01-30 12:27:24 +0000
@@ -110,6 +110,14 @@
110available. They are available in saucy, and they are also stored in our PPA in110available. They are available in saucy, and they are also stored in our PPA in
111order to support previous Ubuntu releases.111order to support previous Ubuntu releases.
112112
113Creating PyPI releases
114~~~~~~~~~~~~~~~~~~~~~~
115
116Juju Quickstart is present on PyPI: see
117<https://pypi.python.org/pypi/juju-quickstart>.
118It is possible to register and upload a new release on PyPI by just running
119``make release`` and providing your PyPI credentials.
120
113Updating application and test dependencies121Updating application and test dependencies
114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~122~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115123
116124
=== modified file 'quickstart/app.py'
--- quickstart/app.py 2014-01-29 14:25:35 +0000
+++ quickstart/app.py 2014-01-30 12:27:24 +0000
@@ -288,6 +288,28 @@
288 raise ProgramExit('the state server is not ready:\n{}'.format(details))288 raise ProgramExit('the state server is not ready:\n{}'.format(details))
289289
290290
291def get_admin_secret(env_name, juju_home):
292 """Read the admin-secret from the generated environment file.
293
294 At bootstrap, juju (v1.16 and later) writes the admin-secret to a
295 generated file located in JUJU_HOME. Return the value.
296 Raise a ValueError if:
297 - the environment file is not found;
298 - the environment file contents are not parsable by YAML;
299 - the YAML contents are not properly structured;
300 - the admin-secret is not found.
301 """
302 filename = '{}.jenv'.format(env_name)
303 juju_env_file = os.path.expanduser(
304 os.path.join(juju_home, 'environments', filename))
305 jenv_db = envs.load_generated(juju_env_file)
306 try:
307 return jenv_db['admin-secret']
308 except KeyError:
309 msg = 'admin-secret not found in {}'.format(juju_env_file)
310 raise ValueError(msg.encode('utf-8'))
311
312
291def get_api_url(env_name):313def get_api_url(env_name):
292 """Return a Juju API URL for the given environment name.314 """Return a Juju API URL for the given environment name.
293315
@@ -497,25 +519,3 @@
497 env.deploy_bundle(bundle_yaml, name=bundle_name, bundle_id=bundle_id)519 env.deploy_bundle(bundle_yaml, name=bundle_name, bundle_id=bundle_id)
498 except jujuclient.EnvError as err:520 except jujuclient.EnvError as err:
499 raise ProgramExit('bad API server response: {}'.format(err.message))521 raise ProgramExit('bad API server response: {}'.format(err.message))
500
501
502def get_admin_secret(env_name, juju_home):
503 """Read the admin-secret from the generated environment file.
504
505 At bootstrap, juju (v1.16 and later) writes the admin-secret to a
506 generated file located in JUJU_HOME. Return the value.
507 Raise a ValueError if:
508 - the environment file is not found;
509 - the environment file contents are not parsable by YAML;
510 - the YAML contents are not properly structured;
511 - the admin-secret is not found.
512 """
513 filename = '{}.jenv'.format(env_name)
514 juju_env_file = os.path.expanduser(
515 os.path.join(juju_home, 'environments', filename))
516 jenv_db = envs.load_generated(juju_env_file)
517 try:
518 return jenv_db['admin-secret']
519 except KeyError:
520 msg = 'admin-secret not found in {}'.format(juju_env_file)
521 raise ValueError(msg.encode('utf-8'))
522522
=== modified file 'quickstart/manage.py'
--- quickstart/manage.py 2014-01-29 14:25:35 +0000
+++ quickstart/manage.py 2014-01-30 12:27:24 +0000
@@ -392,17 +392,17 @@
392 already_bootstrapped, bsn_series = app.bootstrap(392 already_bootstrapped, bsn_series = app.bootstrap(
393 options.env_name, is_local=is_local, debug=options.debug)393 options.env_name, is_local=is_local, debug=options.debug)
394394
395 # The admin secret was not in the environments file. Retrieve it from395 # Retrieve the admin-secret for the current environment.
396 # the Juju-generated file.
397 # Find the Juju-generated environment file.
398 try:396 try:
399 admin_secret = app.get_admin_secret(397 admin_secret = app.get_admin_secret(
400 options.env_name, settings.JUJU_HOME)398 options.env_name, settings.JUJU_HOME)
401 except ValueError as err:399 except ValueError as err:
402 admin_secret = options.admin_secret400 admin_secret = options.admin_secret
403 if admin_secret is None:401 if admin_secret is None:
404 msg = err.message + ' or {}.'.format(options.env_file)402 # The admin-secret cannot be found in the jenv file and is not
405 raise app.ProgramExit(msg.encode('utf-8'))403 # explicitly specified in the environments.yaml file.
404 msg = b'{} or {}'.format(err, options.env_file.encode('utf-8'))
405 raise app.ProgramExit(msg)
406406
407 print('retrieving the Juju API address')407 print('retrieving the Juju API address')
408 api_url = app.get_api_url(options.env_name)408 api_url = app.get_api_url(options.env_name)
409409
=== modified file 'quickstart/tests/test_app.py'
--- quickstart/tests/test_app.py 2014-01-29 14:25:35 +0000
+++ quickstart/tests/test_app.py 2014-01-30 12:27:24 +0000
@@ -569,6 +569,26 @@
569 ] + self.make_status_calls(2))569 ] + self.make_status_calls(2))
570570
571571
572class TestGetAdminSecret(unittest.TestCase):
573
574 def test_no_admin_secret(self):
575 with mock.patch('quickstart.manage.envs.load_generated',
576 lambda x: {}):
577 with self.assertRaises(ValueError) as exc:
578 app.get_admin_secret('local', '/home/bac/.juju')
579 expected = (
580 u'admin-secret not found in '
581 '/home/bac/.juju/environments/local.jenv')
582 self.assertIn(expected, bytes(exc.exception))
583
584 def test_success(self):
585 expected = 'superchunk'
586 with mock.patch('quickstart.manage.envs.load_generated',
587 lambda x: {'admin-secret': expected}):
588 secret = app.get_admin_secret('local', '~bac/.juju')
589 self.assertEqual(expected, secret)
590
591
572class TestGetApiUrl(592class TestGetApiUrl(
573 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):593 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):
574594
@@ -1311,23 +1331,3 @@
1311 with self.assertRaises(ValueError) as context_manager:1331 with self.assertRaises(ValueError) as context_manager:
1312 app.deploy_bundle(env, self.yaml, self.name, None)1332 app.deploy_bundle(env, self.yaml, self.name, None)
1313 self.assertIs(error, context_manager.exception)1333 self.assertIs(error, context_manager.exception)
1314
1315
1316class TestGetAdminSecret(unittest.TestCase):
1317
1318 def test_no_admin_secret(self):
1319 with mock.patch('quickstart.manage.envs.load_generated',
1320 lambda x: {}):
1321 with self.assertRaises(ValueError) as exc:
1322 app.get_admin_secret('local', '/home/bac/.juju')
1323 expected = (
1324 u'admin-secret not found in '
1325 '/home/bac/.juju/environments/local.jenv')
1326 self.assertIn(expected, bytes(exc.exception))
1327
1328 def test_success(self):
1329 expected = 'superchunk'
1330 with mock.patch('quickstart.manage.envs.load_generated',
1331 lambda x: {'admin-secret': expected}):
1332 secret = app.get_admin_secret('local', '~bac/.juju')
1333 self.assertEqual(expected, secret)
13341334
=== modified file 'quickstart/tests/test_manage.py'
--- quickstart/tests/test_manage.py 2014-01-29 14:26:43 +0000
+++ quickstart/tests/test_manage.py 2014-01-30 12:27:24 +0000
@@ -770,5 +770,5 @@
770 manage.run(options)770 manage.run(options)
771 expected = (771 expected = (
772 u'admin-secret not found in ~/.juju/environments/local.jenv '772 u'admin-secret not found in ~/.juju/environments/local.jenv '
773 'or environments.yaml.')773 'or environments.yaml')
774 self.assertEqual(expected, context.exception.message)774 self.assertEqual(expected, context.exception.message)

Subscribers

People subscribed via source and target branches