Commit 22ccebd6 authored by Kirill Smelkov's avatar Kirill Smelkov

client: Don't allow master_nodes and name to be present in options

Because list of masters and cluster name must be already present in
netloc and path. Previously e.g.

	neo://db@α,β,γ?master_nodes=a,b,c"

would mean to use master nodes {a,b,c} not {α,β,γ}. Now it is treated as
invalid URI to remove ambiguity. Same for cluster name.

/cc @levin.zimmermann
/reviewed-by @jm
/reviewed-on nexedi/neoppod!21
parent 9a3898e4
...@@ -66,6 +66,10 @@ def _resolve_uri(uri): ...@@ -66,6 +66,10 @@ def _resolve_uri(uri):
neokw = OrderedDict() neokw = OrderedDict()
neokw['master_nodes'] = ' '.join(master_list) neokw['master_nodes'] = ' '.join(master_list)
neokw['name'] = name neokw['name'] = name
def setopt(k, v):
if k in ('master_nodes', 'name'):
raise ValueError("invalid uri: %s : invalid option %s" % (uri, k))
neokw[k] = v
# get options from query: only those that are defined by NEO schema go to # get options from query: only those that are defined by NEO schema go to
# storage - rest are returned as database options # storage - rest are returned as database options
...@@ -73,14 +77,14 @@ def _resolve_uri(uri): ...@@ -73,14 +77,14 @@ def _resolve_uri(uri):
neo_options = neo_zconf_options() neo_options = neo_zconf_options()
for k, v in OrderedDict(parse_qsl(query)).items(): for k, v in OrderedDict(parse_qsl(query)).items():
if k in neo_options: if k in neo_options:
neokw[k] = v setopt(k, v)
else: else:
# it might be option for storage, but not in canonical form e.g. # it might be option for storage, but not in canonical form e.g.
# read_only -> read-only (zodburi world settled on using "_" and # read_only -> read-only (zodburi world settled on using "_" and
# ZConfig world on "-" as separators) # ZConfig world on "-" as separators)
k2 = canonical_opt_name(k) k2 = canonical_opt_name(k)
if k2 in neo_options: if k2 in neo_options:
neokw[k2] = v setopt(k2, v)
# else keep this kv as db option # else keep this kv as db option
else: else:
......
...@@ -72,6 +72,10 @@ class ZODBURITests(unittest.TestCase): ...@@ -72,6 +72,10 @@ class ZODBURITests(unittest.TestCase):
# db @ master not fully specified # db @ master not fully specified
self.assertRaises(ValueError, _resolve_uri, "neo://master") self.assertRaises(ValueError, _resolve_uri, "neo://master")
# master_nodes and name provided in options (they come in netloc)
self.assertRaises(ValueError, _resolve_uri, "neo://db@master?master_nodes=a,b,c")
self.assertRaises(ValueError, _resolve_uri, "neo://db@master?name=zzz")
# verify zodburi resolver produces expected zconfig # verify zodburi resolver produces expected zconfig
for uri, zconf_ok, dbkw_ok in testv: for uri, zconf_ok, dbkw_ok in testv:
zconf_ok = "%import neo.client\n<NEOStorage>\n" + zconf_ok + \ zconf_ok = "%import neo.client\n<NEOStorage>\n" + zconf_ok + \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment