Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update opts.py to allow for 'None' timeout-value in client_options #1541

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/command_line_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,9 @@ We support the following data types:
* Strings: Have to be enclosed in single quotes. Example: ``ca_certs:'/path/to/CA_certs'``
* Numbers: There is nothing special about numbers. Example: ``sniffer_timeout:60``
* Booleans: Specify either ``true`` or ``false``. Example: ``use_ssl:true``
* None: Specify ``None`` without quotes.``'None'`` will be treated as string. Example: ``timeout:None``

Default value: ``timeout:60`` (applies any time ``timeout`` is not specified)
Default value: ``timeout:60`` (applies any time ``timeout`` is not specified. Set ``timeout:None`` to omit any timeouts)

Rally recognizes the following client options in addition:

Expand Down
18 changes: 17 additions & 1 deletion esrally/utils/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def to_bool(v):
raise ValueError("Could not convert value '%s'" % v)


def to_none(v):
if v is None:
return None
elif v.lower() == "none":
return None
else:
raise ValueError("Could not convert value '%s'" % v)


def kv_to_map(kvs):
def convert(v):
# string (specified explicitly)
Expand All @@ -76,6 +85,12 @@ def convert(v):
return to_bool(v)
except ValueError:
pass

try:
return to_none(v)
except ValueError:
pass

# treat it as string by default
return v

Expand Down Expand Up @@ -197,7 +212,8 @@ def parse_options(self):
default_client_map = kv_to_map([ClientOptions.DEFAULT_CLIENT_OPTIONS])
if self.argvalue == ClientOptions.DEFAULT_CLIENT_OPTIONS and self.target_hosts is not None:
# --client-options unset but multi-clusters used in --target-hosts? apply options defaults for all cluster names.
self.parsed_options = {cluster_name: default_client_map for cluster_name in self.target_hosts.all_hosts.keys()}
self.parsed_options = {cluster_name: default_client_map for cluster_name in
self.target_hosts.all_hosts.keys()}
else:
self.parsed_options = to_dict(self.argvalue, default_parser=ClientOptions.normalize_to_dict)

Expand Down
10 changes: 9 additions & 1 deletion tests/utils/opts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ def test_kv_to_map(self):
assert opts.kv_to_map(["k:3"]) == {"k": 3}
# implicit treatment as string
assert opts.kv_to_map(["k:v"]) == {"k": "v"}
assert opts.kv_to_map(["k:'v'", "size:4", "empty:false", "temperature:0.5"]) == {
assert opts.kv_to_map(["k:'v'", "size:4", "empty:false", "temperature:0.5", "timeout:None"]) == {
"k": "v",
"size": 4,
"empty": False,
"temperature": 0.5,
"timeout": None,
}
# When passing 'None' with quotes, treat it as string
assert opts.kv_to_map(["k:'None'"]) == {"k": "None"}
# When passing None without quotes, treat it as pythonic None
assert opts.kv_to_map(["k:None"]) == {"k": None}
assert opts.kv_to_map(["k:none"]) == {"k": None}
assert opts.kv_to_map(["k:NONE"]) == {"k": None}


def test_to_dict_with_inline_json(self):
assert opts.to_dict('{"default": ["127.0.0.1:9200","10.17.0.5:19200"]}') == {"default": ["127.0.0.1:9200", "10.17.0.5:19200"]}
Expand Down