Merge lp:~milo/lava-tool/server-rpc-endpoint-fix into lp:~linaro-validation/lava-tool/trunk

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 191
Proposed branch: lp:~milo/lava-tool/server-rpc-endpoint-fix
Merge into: lp:~linaro-validation/lava-tool/trunk
Diff against target: 98 lines (+21/-24)
3 files modified
lava/helper/command.py (+2/-2)
lava_tool/tests/test_utils.py (+3/-3)
lava_tool/utils.py (+16/-19)
To merge this branch: bzr merge lp:~milo/lava-tool/server-rpc-endpoint-fix
Reviewer Review Type Date Requested Status
Antonio Terceiro Approve
Linaro Validation Team Pending
Review via email: mp+177658@code.launchpad.net

Description of the change

This merge proposal fixed the problem with how the server and rpc_endpoint parameters have been intended.
With these changes now "server" is just a name, and "rpc_endpoint" is the actual URL.

To post a comment you must log in.
Revision history for this message
Antonio Terceiro (terceiro) wrote :

> === modified file 'lava_tool/utils.py'
> --- lava_tool/utils.py 2013-07-26 14:12:33 +0000
> +++ lava_tool/utils.py 2013-07-30 17:42:26 +0000
> @@ -281,7 +281,7 @@
> editor))
>
>
> -def verify_and_create_url(server, endpoint=""):
> +def verify_and_create_url(endpoint):
> """Checks that the provided values make a correct URL.
>
> If the server address does not contain a scheme, by default it will use
> @@ -291,25 +291,22 @@
> :param server: A server URL to verify.
> :return A URL.
> """
> - scheme, netloc, path, params, query, fragment = \
> - urlparse.urlparse(server)
> - if not scheme:
> - scheme = "https"
> - if not netloc:
> - netloc, path = path, ""
> -
> - if not netloc[-1:] == "/":
> - netloc += "/"
> -
> + url = ""
> if endpoint:
> - if endpoint[0] == "/":
> - endpoint = endpoint[1:]
> - if not endpoint[-1:] == "/":
> - endpoint += "/"
> - netloc += endpoint
> -
> - return urlparse.urlunparse(
> - (scheme, netloc, path, params, query, fragment))
> + scheme, netloc, path, params, query, fragment = \
> + urlparse.urlparse(endpoint)
> + if not scheme:
> + scheme = "https"
> + if not netloc:
> + netloc, path = path, ""
> +
> + url = urlparse.urlunparse(
> + (scheme, netloc, path, params, query, fragment))
> +
> + if url[-1:] != "/":
> + url += "/"
> +
> + return url

I don't understand why you need to parse the url just to unparse it a
few lines below. This function seems rather pointless to me.

Revision history for this message
Milo Casagrande (milo) wrote :

On Thu, Aug 1, 2013 at 2:04 AM, Antonio Terceiro
<email address hidden> wrote:
>
> I don't understand why you need to parse the url just to unparse it a
> few lines below. This function seems rather pointless to me.

Because if somebody when prompted for the server URL enters just
"127.0.0.1/RPC2", withouth the scheme, we will get a rather unpleasant
"IOError: unsupported XML-RPC protocol" error.

So, I need to look into the given URL and make sure we have a scheme,
or default to HTTPS, and that the URL has a trailing slash (since
looks like lava-tool auth-add adds it by default when adding an auth
token). That's why I parse the URL first, check what's necessary, and
then unparse it to create back the full URL.

--
Milo Casagrande | Automation Engineer
Linaro.org <www.linaro.org> │ Open source software for ARM SoCs

Revision history for this message
Antonio Terceiro (terceiro) wrote :

On Tue, Aug 06, 2013 at 09:37:08AM -0000, Milo Casagrande wrote:
> On Thu, Aug 1, 2013 at 2:04 AM, Antonio Terceiro
> <email address hidden> wrote:
> >
> > I don't understand why you need to parse the url just to unparse it a
> > few lines below. This function seems rather pointless to me.
>
> Because if somebody when prompted for the server URL enters just
> "127.0.0.1/RPC2", withouth the scheme, we will get a rather unpleasant
> "IOError: unsupported XML-RPC protocol" error.
>
> So, I need to look into the given URL and make sure we have a scheme,
> or default to HTTPS, and that the URL has a trailing slash (since
> looks like lava-tool auth-add adds it by default when adding an auth
> token). That's why I parse the URL first, check what's necessary, and
> then unparse it to create back the full URL.

OK - bring it in then

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lava/helper/command.py'
--- lava/helper/command.py 2013-07-29 10:09:09 +0000
+++ lava/helper/command.py 2013-07-30 17:42:26 +0000
@@ -89,10 +89,10 @@
89 rpc_endpoint_parameter = Parameter("rpc_endpoint",89 rpc_endpoint_parameter = Parameter("rpc_endpoint",
90 depends=server_name_parameter)90 depends=server_name_parameter)
9191
92 server_url = self.config.get(server_name_parameter)92 self.config.get(server_name_parameter)
93 endpoint = self.config.get(rpc_endpoint_parameter)93 endpoint = self.config.get(rpc_endpoint_parameter)
9494
95 rpc_url = verify_and_create_url(server_url, endpoint)95 rpc_url = verify_and_create_url(endpoint)
96 server = AuthenticatingServerProxy(rpc_url,96 server = AuthenticatingServerProxy(rpc_url,
97 auth_backend=KeyringAuthBackend())97 auth_backend=KeyringAuthBackend())
98 return server98 return server
9999
=== modified file 'lava_tool/tests/test_utils.py'
--- lava_tool/tests/test_utils.py 2013-07-26 09:30:11 +0000
+++ lava_tool/tests/test_utils.py 2013-07-30 17:42:26 +0000
@@ -243,7 +243,7 @@
243243
244 def test_verify_and_create_url_0(self):244 def test_verify_and_create_url_0(self):
245 expected = "https://www.example.org/"245 expected = "https://www.example.org/"
246 obtained = verify_and_create_url("www.example.org", "")246 obtained = verify_and_create_url("www.example.org")
247 self.assertEquals(expected, obtained)247 self.assertEquals(expected, obtained)
248248
249 def test_verify_and_create_url_1(self):249 def test_verify_and_create_url_1(self):
@@ -253,12 +253,12 @@
253253
254 def test_verify_and_create_url_2(self):254 def test_verify_and_create_url_2(self):
255 expected = "http://www.example.org/RPC/"255 expected = "http://www.example.org/RPC/"
256 obtained = verify_and_create_url("http://www.example.org", "RPC")256 obtained = verify_and_create_url("http://www.example.org/RPC")
257 self.assertEquals(expected, obtained)257 self.assertEquals(expected, obtained)
258258
259 def test_verify_and_create_url_3(self):259 def test_verify_and_create_url_3(self):
260 expected = "https://www.example.org/RPC/"260 expected = "https://www.example.org/RPC/"
261 obtained = verify_and_create_url("www.example.org/", "/RPC/")261 obtained = verify_and_create_url("www.example.org/RPC")
262 self.assertEquals(expected, obtained)262 self.assertEquals(expected, obtained)
263263
264 def test_create_dir_0(self):264 def test_create_dir_0(self):
265265
=== modified file 'lava_tool/utils.py'
--- lava_tool/utils.py 2013-07-26 14:12:33 +0000
+++ lava_tool/utils.py 2013-07-30 17:42:26 +0000
@@ -281,7 +281,7 @@
281 editor))281 editor))
282282
283283
284def verify_and_create_url(server, endpoint=""):284def verify_and_create_url(endpoint):
285 """Checks that the provided values make a correct URL.285 """Checks that the provided values make a correct URL.
286286
287 If the server address does not contain a scheme, by default it will use287 If the server address does not contain a scheme, by default it will use
@@ -291,25 +291,22 @@
291 :param server: A server URL to verify.291 :param server: A server URL to verify.
292 :return A URL.292 :return A URL.
293 """293 """
294 scheme, netloc, path, params, query, fragment = \294 url = ""
295 urlparse.urlparse(server)
296 if not scheme:
297 scheme = "https"
298 if not netloc:
299 netloc, path = path, ""
300
301 if not netloc[-1:] == "/":
302 netloc += "/"
303
304 if endpoint:295 if endpoint:
305 if endpoint[0] == "/":296 scheme, netloc, path, params, query, fragment = \
306 endpoint = endpoint[1:]297 urlparse.urlparse(endpoint)
307 if not endpoint[-1:] == "/":298 if not scheme:
308 endpoint += "/"299 scheme = "https"
309 netloc += endpoint300 if not netloc:
310301 netloc, path = path, ""
311 return urlparse.urlunparse(302
312 (scheme, netloc, path, params, query, fragment))303 url = urlparse.urlunparse(
304 (scheme, netloc, path, params, query, fragment))
305
306 if url[-1:] != "/":
307 url += "/"
308
309 return url
313310
314311
315def create_dir(path, dir_name=None):312def create_dir(path, dir_name=None):

Subscribers

People subscribed via source and target branches