[ARVADOS] updated: b3fd3679187be8e51d31cb6bf17613cc488cda4b
git at public.curoverse.com
git at public.curoverse.com
Mon Sep 29 16:08:03 EDT 2014
Summary of changes:
sdk/python/arvados/keep.py | 16 +++++++--------
sdk/python/tests/test_keep_client.py | 38 ++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 8 deletions(-)
via b3fd3679187be8e51d31cb6bf17613cc488cda4b (commit)
from f1c20b66097f1bb37c0ffc8808b4a5831e91f87b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit b3fd3679187be8e51d31cb6bf17613cc488cda4b
Author: Brett Smith <brett at curoverse.com>
Date: Mon Sep 29 16:07:55 2014 -0400
3866: PySDK KeepClient accommodates services with IPv6 addresses.
I thought there was going to be a nicer way to construct URLs than
this, but urllib.urlunparse is still expecting the host+port as a
single string, so this approach is easier. Closes #3866.
diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py
index 323251d..37b1c17 100644
--- a/sdk/python/arvados/keep.py
+++ b/sdk/python/arvados/keep.py
@@ -473,14 +473,14 @@ class KeepClient(object):
if not keep_services:
raise arvados.errors.NoKeepServersError()
- self.using_proxy = (keep_services[0].get('service_type') ==
- 'proxy')
-
- roots = (("http%s://%s:%d/" %
- ('s' if f['service_ssl_flag'] else '',
- f['service_host'],
- f['service_port']))
- for f in keep_services)
+ self.using_proxy = any(ks.get('service_type') == 'proxy'
+ for ks in keep_services)
+
+ roots = ("{}://[{}]:{:d}/".format(
+ 'https' if ks['service_ssl_flag'] else 'http',
+ ks['service_host'],
+ ks['service_port'])
+ for ks in keep_services)
self.service_roots = sorted(set(roots))
_logger.debug(str(self.service_roots))
diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py
index 8cc22a6..b12ae77 100644
--- a/sdk/python/tests/test_keep_client.py
+++ b/sdk/python/tests/test_keep_client.py
@@ -2,6 +2,7 @@ import mock
import os
import socket
import unittest
+import urlparse
import arvados
import arvados.retry
@@ -221,6 +222,43 @@ class KeepProxyTestCase(run_test_server.TestCaseWithServers):
self.assertTrue(keep_client.using_proxy)
+class KeepClientServiceTestCase(unittest.TestCase):
+ def mock_keep_services(self, *services):
+ api_client = mock.MagicMock(name='api_client')
+ api_client.keep_services().accessible().execute.return_value = {
+ 'items_available': len(services),
+ 'items': [{
+ 'uuid': 'zzzzz-bi6l4-mockservice{:04x}'.format(index),
+ 'owner_uuid': 'zzzzz-tpzed-mockownerabcdef',
+ 'service_host': host,
+ 'service_port': port,
+ 'service_ssl_flag': ssl,
+ 'service_type': servtype,
+ } for index, (host, port, ssl, servtype)
+ in enumerate(services)],
+ }
+ return api_client
+
+ def get_service_roots(self, *services):
+ api_client = self.mock_keep_services(*services)
+ keep_client = arvados.KeepClient(api_client=api_client)
+ services = keep_client.shuffled_service_roots('000000')
+ return [urlparse.urlparse(url) for url in sorted(services)]
+
+ def test_ssl_flag_respected_in_roots(self):
+ services = self.get_service_roots(('keep', 10, False, 'disk'),
+ ('keep', 20, True, 'disk'))
+ self.assertEqual(10, services[0].port)
+ self.assertEqual('http', services[0].scheme)
+ self.assertEqual(20, services[1].port)
+ self.assertEqual('https', services[1].scheme)
+
+ def test_correct_ports_with_ipv6_addresses(self):
+ service = self.get_service_roots(('100::1', 10, True, 'proxy'))[0]
+ self.assertEqual('100::1', service.hostname)
+ self.assertEqual(10, service.port)
+
+
class KeepClientRetryTestMixin(object):
# Testing with a local Keep store won't exercise the retry behavior.
# Instead, our strategy is:
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list