Merge lp:~frankban/juju-deployer/guiserver-auth into lp:juju-deployer

Proposed by Francesco Banconi on 2014-12-17
Status: Merged
Merged at revision: 134
Proposed branch: lp:~frankban/juju-deployer/guiserver-auth
Merge into: lp:juju-deployer
Diff against target: 164 lines (+25/-24)
4 files modified
deployer/env/gui.py (+4/-11)
deployer/guiserver.py (+4/-4)
deployer/tests/test_guienv.py (+4/-2)
deployer/tests/test_guiserver.py (+13/-7)
To merge this branch: bzr merge lp:~frankban/juju-deployer/guiserver-auth
Reviewer Review Type Date Requested Status
Tim Van Steenburgh 2014-12-17 Needs Fixing on 2015-02-06
Brad Crittenden (community) code Approve on 2014-12-17
j.c.sackett (community) code Approve on 2014-12-17
Review via email: mp+244984@code.launchpad.net

Commit Message

GUI environment: use both username and password.

Description of the Change

Use both credentials to authenticate to the Juju environment: do not assume the user name to always be user-admin.

To post a comment you must log in.
j.c.sackett (jcsackett) wrote :

LGTM, Francesco. Thanks!

review: Approve (code)
Brad Crittenden (bac) wrote :

LGTM

review: Approve (code)
Tim Van Steenburgh (tvansteenburgh) wrote :

I'm +1 on this idea but have a suggestion for the implementation. The proposed solution unnecessarily breaks backward compatibility by changing the order of args, and by making username a required arg. This could be avoided by maintaining the existing order of args, and adding username as a kwarg with default value 'user-admin'.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/env/gui.py'
2--- deployer/env/gui.py 2014-09-03 17:21:51 +0000
3+++ deployer/env/gui.py 2014-12-17 14:20:19 +0000
4@@ -12,21 +12,14 @@
5 """A Juju environment for the juju-deployer.
6
7 Add support for deployments via the Juju API and for authenticating with
8- the provided password.
9+ the provided credentials.
10 """
11
12- def __init__(self, endpoint, password):
13+ def __init__(self, endpoint, username, password):
14 super(GUIEnvironment, self).__init__('gui', endpoint=endpoint)
15+ self._username = username
16 self._password = password
17
18- def _get_token(self):
19- """Return the stored password.
20-
21- This method is overridden so that the juju-deployer does not try to
22- parse the environments.yaml file in order to retrieve the admin-secret.
23- """
24- return self._password
25-
26 def connect(self):
27 """Connect the API client to the Juju backend.
28
29@@ -35,7 +28,7 @@
30 """
31 if self.client is None:
32 self.client = EnvironmentClient(self.api_endpoint)
33- self.client.login(self._password)
34+ self.client.login(self._password, user=self._username)
35
36 def close(self):
37 """Close the API connection.
38
39=== modified file 'deployer/guiserver.py'
40--- deployer/guiserver.py 2014-02-20 18:13:57 +0000
41+++ deployer/guiserver.py 2014-12-17 14:20:19 +0000
42@@ -72,9 +72,9 @@
43 raise ValueError(error)
44
45
46-def validate(apiurl, password, bundle):
47+def validate(apiurl, username, password, bundle):
48 """Validate a bundle."""
49- env = GUIEnvironment(apiurl, password)
50+ env = GUIEnvironment(apiurl, username, password)
51 env.connect()
52 try:
53 _validate(env, bundle)
54@@ -82,9 +82,9 @@
55 env.close()
56
57
58-def import_bundle(apiurl, password, name, bundle, options):
59+def import_bundle(apiurl, username, password, name, bundle, options):
60 """Import a bundle."""
61- env = GUIEnvironment(apiurl, password)
62+ env = GUIEnvironment(apiurl, username, password)
63 deployment = GUIDeployment(name, bundle)
64 importer = Importer(env, deployment, options)
65 env.connect()
66
67=== modified file 'deployer/tests/test_guienv.py'
68--- deployer/tests/test_guienv.py 2014-09-03 17:21:51 +0000
69+++ deployer/tests/test_guienv.py 2014-12-17 14:20:19 +0000
70@@ -12,17 +12,19 @@
71 class TestGUIEnvironment(unittest.TestCase):
72
73 endpoint = 'wss://api.example.com:17070'
74+ username = 'who'
75 password = 'Secret!'
76
77 def setUp(self):
78- self.env = GUIEnvironment(self.endpoint, self.password)
79+ self.env = GUIEnvironment(self.endpoint, self.username, self.password)
80
81 def test_connect(self, mock_client):
82 # The environment uses the provided endpoint and password to connect
83 # to the Juju API server.
84 self.env.connect()
85 mock_client.assert_called_once_with(self.endpoint)
86- mock_client().login.assert_called_once_with(self.password)
87+ mock_client().login.assert_called_once_with(
88+ self.password, user=self.username)
89
90 def test_multiple_connections(self, mock_client):
91 # The environment does not attempt a second connection if it is already
92
93=== modified file 'deployer/tests/test_guiserver.py'
94--- deployer/tests/test_guiserver.py 2014-09-29 12:14:05 +0000
95+++ deployer/tests/test_guiserver.py 2014-12-17 14:20:19 +0000
96@@ -107,6 +107,7 @@
97 """Base set up for the functions that make use of the juju-deployer."""
98
99 apiurl = 'wss://api.example.com:17070'
100+ username = 'who'
101 password = 'Secret!'
102 name = 'mybundle'
103 bundle = yaml.safe_load("""
104@@ -144,7 +145,8 @@
105 services, the environment is instantiated, connected, env.status is
106 called and then the connection is closed.
107 """
108- mock_environment.assert_called_once_with(self.apiurl, self.password)
109+ mock_environment.assert_called_once_with(
110+ self.apiurl, self.username, self.password)
111 mock_env_instance = mock_environment()
112 mock_env_instance.connect.assert_called_once_with()
113 mock_env_instance.status.assert_called_once_with()
114@@ -177,7 +179,8 @@
115
116 def test_validation(self, mock_environment):
117 # The validation is correctly run.
118- guiserver.validate(self.apiurl, self.password, self.bundle)
119+ guiserver.validate(
120+ self.apiurl, self.username, self.password, self.bundle)
121 # The environment is correctly instantiated and used.
122 self.check_environment_life(mock_environment)
123
124@@ -185,7 +188,8 @@
125 # The validation fails if the bundle includes a service name already
126 # present in the Juju environment.
127 with self.assert_overlapping_services(mock_environment):
128- guiserver.validate(self.apiurl, self.password, self.bundle)
129+ guiserver.validate(
130+ self.apiurl, self.username, self.password, self.bundle)
131
132
133 @unittest.skipIf(TEST_OFFLINE,
134@@ -211,7 +215,8 @@
135 def import_bundle(self):
136 """Call the import_bundle function."""
137 guiserver.import_bundle(
138- self.apiurl, self.password, self.name, self.bundle, self.options)
139+ self.apiurl, self.username, self.password, self.name, self.bundle,
140+ self.options)
141
142 def cleanup_series_path(self):
143 """Remove the series path created by the Deployment object."""
144@@ -270,7 +275,8 @@
145 mock_sleep.assert_has_calls([mock.call(5.1), mock.call(60)])
146 # If any of the calls below fails, then we have to change the
147 # signatures of deployer.guiserver.GUIEnvironment methods.
148- mock_environment.assert_called_once_with(self.apiurl, self.password)
149+ mock_environment.assert_called_once_with(
150+ self.apiurl, self.username, self.password)
151 mock_environment().assert_has_calls([
152 mock.call.connect(),
153 mock.call.status(),
154@@ -309,8 +315,8 @@
155 with self.patch_juju_home():
156 with self.assertRaises(guiserver.DeploymentError) as cm:
157 guiserver.import_bundle(
158- self.apiurl, self.password, self.name, bundle,
159- self.options)
160+ self.apiurl, self.username, self.password, self.name,
161+ bundle, self.options)
162 expected_errors = set([
163 'Invalid config charm cs:precise/wordpress-20 no-such-option=42',
164 'Invalid config charm cs:precise/mysql-28 bad=wolf',

Subscribers

People subscribed via source and target branches