summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-02-22 05:10:55 +0000
committerGerrit Code Review <review@openstack.org>2018-02-22 05:10:55 +0000
commit0d555bf85a6254a244a72a1b523653715c9cf4a6 (patch)
tree2f9e51cab502e6eb41120bcc5a97432ed45de05c
parent739600802e337494c4c0fe5a1705531975a9694c (diff)
parent1667ad5e80be7d0bf3ac8e02410a18ce3a0ea4cd (diff)
Merge "Allow host URL for versions to be configurable"HEADmaster
-rw-r--r--trove/common/cfg.py10
-rw-r--r--trove/tests/unittests/api/test_versions.py39
-rw-r--r--trove/versions.py5
3 files changed, 52 insertions, 2 deletions
diff --git a/trove/common/cfg.py b/trove/common/cfg.py
index abfa043..81d6528 100644
--- a/trove/common/cfg.py
+++ b/trove/common/cfg.py
@@ -44,6 +44,15 @@ path_opts = [
44 help='Directory where the Trove python module is installed.'), 44 help='Directory where the Trove python module is installed.'),
45] 45]
46 46
47versions_opts = [
48 cfg.StrOpt('public_endpoint', default=None,
49 help='Public URL to use for versions endpoint. The default '
50 'is None, which will use the request\'s host_url '
51 'attribute to populate the URL base. If Trove is '
52 'operating behind a proxy, you will want to change '
53 'this to represent the proxy\'s URL.')
54]
55
47common_opts = [ 56common_opts = [
48 cfg.IPOpt('bind_host', default='0.0.0.0', 57 cfg.IPOpt('bind_host', default='0.0.0.0',
49 help='IP address the API server will listen on.'), 58 help='IP address the API server will listen on.'),
@@ -1523,6 +1532,7 @@ rpcapi_cap_opts = [
1523CONF = cfg.CONF 1532CONF = cfg.CONF
1524 1533
1525CONF.register_opts(path_opts) 1534CONF.register_opts(path_opts)
1535CONF.register_opts(versions_opts)
1526CONF.register_opts(common_opts) 1536CONF.register_opts(common_opts)
1527 1537
1528CONF.register_opts(database_opts, 'database') 1538CONF.register_opts(database_opts, 'database')
diff --git a/trove/tests/unittests/api/test_versions.py b/trove/tests/unittests/api/test_versions.py
index b4b1860..ca44f79 100644
--- a/trove/tests/unittests/api/test_versions.py
+++ b/trove/tests/unittests/api/test_versions.py
@@ -14,7 +14,9 @@
14# under the License. 14# under the License.
15 15
16from mock import Mock 16from mock import Mock
17import webob
17 18
19from trove.common import cfg
18from trove.tests.unittests import trove_testtools 20from trove.tests.unittests import trove_testtools
19from trove.versions import BaseVersion 21from trove.versions import BaseVersion
20from trove.versions import Version 22from trove.versions import Version
@@ -41,6 +43,10 @@ class VersionsControllerTest(trove_testtools.TestCase):
41 self.assertIsNotNone(self.controller, 43 self.assertIsNotNone(self.controller,
42 "VersionsController instance was None") 44 "VersionsController instance was None")
43 45
46 def tearDown(self):
47 super(VersionsControllerTest, self).tearDown()
48 cfg.CONF.clear_override('public_endpoint')
49
44 def test_index_json(self): 50 def test_index_json(self):
45 request = Mock() 51 request = Mock()
46 result = self.controller.index(request) 52 result = self.controller.index(request)
@@ -66,6 +72,23 @@ class VersionsControllerTest(trove_testtools.TestCase):
66 self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'], 72 self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
67 'Version updated value is incorrect') 73 'Version updated value is incorrect')
68 74
75 def test_index_json_with_public_endpoint(self):
76 cfg.CONF.set_override('public_endpoint', "https://example.com:8779")
77 req = webob.Request.blank('/')
78 resp = self.controller.index(req)
79 result = resp.data('application/json')['versions']
80 expected = [
81 {
82 'status': 'CURRENT',
83 'updated': '2012-08-01T00:00:00Z',
84 'id': 'v1.0',
85 'links': [{
86 'href': 'https://example.com:8779/v1.0/',
87 'rel': 'self'}]
88 }
89 ]
90 self.assertEqual(expected, result)
91
69 def test_show_json(self): 92 def test_show_json(self):
70 request = Mock() 93 request = Mock()
71 request.url_version = '1.0' 94 request.url_version = '1.0'
@@ -84,6 +107,22 @@ class VersionsControllerTest(trove_testtools.TestCase):
84 "Version updated was not '2012-08-01T00:00:00Z'") 107 "Version updated was not '2012-08-01T00:00:00Z'")
85 self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'") 108 self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")
86 109
110 def test_show_json_with_public_endpoint(self):
111 cfg.CONF.set_override('public_endpoint', "https://example.com:8779")
112 req = webob.Request.blank('/')
113 req.url_version = '1.0'
114 resp = self.controller.show(req)
115 result = resp.data('application/json')['version']
116 expected = {
117 'status': 'CURRENT',
118 'updated': '2012-08-01T00:00:00Z',
119 'id': 'v1.0',
120 'links': [{
121 'href': 'https://example.com:8779/',
122 'rel': 'self'}]
123 }
124 self.assertEqual(expected, result)
125
87 126
88class BaseVersionTestCase(trove_testtools.TestCase): 127class BaseVersionTestCase(trove_testtools.TestCase):
89 128
diff --git a/trove/versions.py b/trove/versions.py
index 7b2a81d..48ed94d 100644
--- a/trove/versions.py
+++ b/trove/versions.py
@@ -16,9 +16,10 @@
16import os 16import os
17import routes 17import routes
18 18
19from trove.common import cfg
19from trove.common import wsgi 20from trove.common import wsgi
20 21
21 22CONF = cfg.CONF
22VERSIONS = { 23VERSIONS = {
23 "1.0": { 24 "1.0": {
24 "id": "v1.0", 25 "id": "v1.0",
@@ -56,7 +57,7 @@ class BaseVersion(object):
56 def __init__(self, id, status, base_url, updated): 57 def __init__(self, id, status, base_url, updated):
57 self.id = id 58 self.id = id
58 self.status = status 59 self.status = status
59 self.base_url = base_url 60 self.base_url = CONF.public_endpoint or base_url
60 self.updated = updated 61 self.updated = updated
61 62
62 def data(self): 63 def data(self):