From ac6d69eb5091ec7f3c2768a7e68c66de98406805 Mon Sep 17 00:00:00 2001 From: MoBoo Date: Thu, 7 Jul 2022 11:09:45 +0200 Subject: [PATCH 1/2] Update opts.py to allow for 'None' timeout-value in client_options parameter. Added to_none() to opts.py and updated kv_to_map() function. --- esrally/utils/opts.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/esrally/utils/opts.py b/esrally/utils/opts.py index 663481924..624c444e2 100644 --- a/esrally/utils/opts.py +++ b/esrally/utils/opts.py @@ -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) @@ -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 @@ -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) From 75ec472def7a922310cd3dd58b0e554649ef1e94 Mon Sep 17 00:00:00 2001 From: stmamasu Date: Fri, 8 Jul 2022 10:49:06 +0200 Subject: [PATCH 2/2] Add test; update docs/command_line_reference.rst --- docs/command_line_reference.rst | 3 ++- tests/utils/opts_test.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/command_line_reference.rst b/docs/command_line_reference.rst index 5b46207d3..0d17f1f28 100644 --- a/docs/command_line_reference.rst +++ b/docs/command_line_reference.rst @@ -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: diff --git a/tests/utils/opts_test.py b/tests/utils/opts_test.py index 3c70e01d6..0b7cdc0a3 100644 --- a/tests/utils/opts_test.py +++ b/tests/utils/opts_test.py @@ -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"]}