Merge lp:~pguimaraes/python-jujuclient/python-jujuclient into lp:python-jujuclient

Proposed by Pedro Guimarães
Status: Needs review
Proposed branch: lp:~pguimaraes/python-jujuclient/python-jujuclient
Merge into: lp:python-jujuclient
Diff against target: 93 lines (+40/-11)
3 files modified
jujuclient/juju2/connector.py (+18/-9)
test-requirements.txt (+0/-1)
tox.ini (+22/-1)
To merge this branch: bzr merge lp:~pguimaraes/python-jujuclient/python-jujuclient
Reviewer Review Type Date Requested Status
Ryan Beisner (community) Needs Information
David Ames (community) Needs Fixing
juju-deployers Pending
Review via email: mp+352408@code.launchpad.net

Description of the change

Juju version 2.5 returns controllers' UUIDs as 'controller-uuid' key
instead of 'uuid'. Set same value for both keys on controller dict if
Juju's minor version is equal or greater than 2.5; this allows
to integrate with newer Jujuversion while keeping backward compatibility.

To post a comment you must log in.
101. By Pedro Guimarães

Correcting get_juju_minor_version() to also work with format:
<MAJOR VERSION>.<MINOR VERSION>.<RELEASES>-<SYSTEM INFO>
of juju --version

Revision history for this message
Ryan Beisner (1chb1n) wrote :

rbeisner@rby:~/bzr/python-jujuclient$ flake8 jujuclient/
jujuclient/utils.py:9:1: E302 expected 2 blank lines, found 1
jujuclient/utils.py:16:1: E302 expected 2 blank lines, found 1
jujuclient/utils.py:23:1: E302 expected 2 blank lines, found 1
jujuclient/juju2/connector.py:1:1: E902 IndentationError: unindent does not match any outer indentation level
jujuclient/juju2/connector.py:43:1: E305 expected 2 blank lines after class or function definition, found 0
jujuclient/juju2/connector.py:44:8: E999 IndentationError: unexpected indent
jujuclient/juju2/connector.py:44:9: E113 unexpected indentation

review: Needs Fixing
102. By Pedro Guimarães

Juju version 2.5 returns controllers' UUIDs as 'controller-uuid' flags
instead of 'uuid'. Set same value for both keys on controller dict to
allow it to work with newer version while keeping older format as well.

Revised test-related files. Added py36 testing scenario.

Revision history for this message
David Ames (thedac) wrote :

Please have the except catch a KeyError and we can do away with the changes to utils.py

review: Needs Fixing
103. By Pedro Guimarães

Clean-up of unused methods on jujuclient/utils.py
Update to get KeyError exception on juju2/connector.py

Revision history for this message
Ryan Beisner (1chb1n) wrote :

https://bugs.launchpad.net/juju/+bug/1786061

The root cause of this bug was a backward-incompatible change in juju core master (2.5). That change has been reverted and this issue should no longer exist at the current jujuclient release.

Please confirm and report back on that juju bug.

Thank you.

review: Needs Information

Unmerged revisions

103. By Pedro Guimarães

Clean-up of unused methods on jujuclient/utils.py
Update to get KeyError exception on juju2/connector.py

102. By Pedro Guimarães

Juju version 2.5 returns controllers' UUIDs as 'controller-uuid' flags
instead of 'uuid'. Set same value for both keys on controller dict to
allow it to work with newer version while keeping older format as well.

Revised test-related files. Added py36 testing scenario.

101. By Pedro Guimarães

Correcting get_juju_minor_version() to also work with format:
<MAJOR VERSION>.<MINOR VERSION>.<RELEASES>-<SYSTEM INFO>
of juju --version

100. By Pedro Guimarães

Added Juju minor version retrieval on utils.py
If minor version is equal or greater than 2.5, then controller['uuid']
equals controller['controller-uuid'] on connector.py

99. By Pedro Guimarães

Juju version 2.5 returns controllers' UUIDs as 'controller-uuid' flags
instead of 'uuid'. Set same value for both keys on controller dict to
allow it to work with newer version while keeping older format as well.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujuclient/juju2/connector.py'
2--- jujuclient/juju2/connector.py 2016-12-08 17:28:26 +0000
3+++ jujuclient/juju2/connector.py 2018-08-10 11:55:45 +0000
4@@ -40,7 +40,6 @@
5 controller_name, remainder = env_name.split(':')
6 else:
7 raise Exception('Invalid environment name: %s', env_name)
8-
9 if '/' in remainder:
10 owner, model_name = remainder.split('/')
11 else:
12@@ -62,14 +61,24 @@
13 model = self.get_model(controller_name, model_name, owner)
14 account = self.get_account(jhome, controller_name)
15
16- return jhome, {
17- 'user': account['user'],
18- 'password': account.get('password', ''),
19- 'environ-uuid': model['model-uuid'],
20- 'server-uuid': controller['uuid'],
21- 'state-servers': controller['api-endpoints'],
22- 'ca-cert': controller['ca-cert'],
23- }
24+ # On juju 2.5, uuid value migrated to controller-uuid
25+ # therefore, accessing controller[uuid] will raises exception
26+ # This check makes sure it will work for both Juju <2.5 and
27+ # versions >=2.5
28+ try:
29+ controller['uuid'] = controller['controller-uuid']
30+ except KeyError:
31+ # ignore case where controller-uuid does not exist
32+ pass
33+ finally:
34+ return jhome, {
35+ 'user': account['user'],
36+ 'password': account.get('password', ''),
37+ 'environ-uuid': model['model-uuid'],
38+ 'server-uuid': controller['uuid'],
39+ 'state-servers': controller['api-endpoints'],
40+ 'ca-cert': controller['ca-cert'],
41+ }
42
43 def get_controller(self, controller_name):
44 """Return info for the specified or current controller.
45
46=== modified file 'test-requirements.txt'
47--- test-requirements.txt 2015-07-09 20:08:51 +0000
48+++ test-requirements.txt 2018-08-10 11:55:45 +0000
49@@ -2,4 +2,3 @@
50 pytest
51 flake8
52 pytest-cov
53-pytest-capturelog
54
55=== modified file 'tox.ini'
56--- tox.ini 2016-03-23 03:02:53 +0000
57+++ tox.ini 2018-08-10 11:55:45 +0000
58@@ -1,6 +1,6 @@
59 [tox]
60 minversion = 1.8
61-envlist = py27,py34,pep8
62+envlist = py27,py34,py36,pep8
63
64 [testenv]
65 usedevelop=True
66@@ -12,6 +12,27 @@
67 commands=
68 py.test -v {posargs}
69
70+[testenv:py27]
71+basepython = python2.7
72+deps = -r{toxinidir}/test-requirements.txt
73+setenv =
74+ JUJU_TEST_ENV = {env:JUJU_TEST_ENV:"test"}
75+ JUJU_DATA = {homedir}/.local/share/juju
76+ HOME = {env:HOME}
77+commands=
78+ py.test -v {posargs}
79+
80+
81+[testenv:py36]
82+basepython = python3.6
83+deps = -r{toxinidir}/test-requirements.txt
84+setenv =
85+ JUJU_TEST_ENV = {env:JUJU_TEST_ENV:"test"}
86+ JUJU_DATA = {homedir}/.local/share/juju
87+ HOME = {env:HOME}
88+commands=
89+ py.test -v {posargs}
90+
91 [testenv:docs]
92 basepython=python
93 changedir=docs/source

Subscribers

People subscribed via source and target branches