From 5878e220cf1ea3dc9222af4c0fc6859a274e49b2 Mon Sep 17 00:00:00 2001 From: Stephen Bourke Date: Tue, 29 Aug 2023 09:17:40 +0100 Subject: [PATCH] Comply with pre-commit and lint --- salt/modules/ipset.py | 24 +++++++++---------- .../pytests/functional/modules/test_ipset.py | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/salt/modules/ipset.py b/salt/modules/ipset.py index e47880d1b6e7..c250d90e0d8c 100644 --- a/salt/modules/ipset.py +++ b/salt/modules/ipset.py @@ -315,7 +315,7 @@ def new_set(name=None, set_type=None, family="ipv4", comment=False, **kwargs): # Check for required arguments for item in _CREATE_OPTIONS_REQUIRED[set_type]: if item not in kwargs: - return "Error: {} is a required argument".format(item) + return f"Error: {item} is a required argument" cmd = [_ipset_cmd(), "create", name, set_type] @@ -478,7 +478,7 @@ def add(name=None, entry=None, family="ipv4", **kwargs): setinfo = _find_set_info(name) if not setinfo: - return "Error: Set {} does not exist".format(name) + return f"Error: Set {name} does not exist" settype = setinfo["Type"] @@ -486,21 +486,21 @@ def add(name=None, entry=None, family="ipv4", **kwargs): if "timeout" in kwargs: if "timeout" not in setinfo["Header"]: - return "Error: Set {} not created with timeout support".format(name) + return f"Error: Set {name} not created with timeout support" if "packets" in kwargs or "bytes" in kwargs: if "counters" not in setinfo["Header"]: - return "Error: Set {} not created with counters support".format(name) + return f"Error: Set {name} not created with counters support" if "comment" in kwargs: if "comment" not in setinfo["Header"]: - return "Error: Set {} not created with comment support".format(name) + return f"Error: Set {name} not created with comment support" if "comment" not in entry: cmd = cmd + ["comment", f"{kwargs['comment']}"] if {"skbmark", "skbprio", "skbqueue"} & set(kwargs.keys()): if "skbinfo" not in setinfo["Header"]: - return "Error: Set {} not created with skbinfo support".format(name) + return f"Error: Set {name} not created with skbinfo support" for item in _ADD_OPTIONS[settype]: if item in kwargs: @@ -508,14 +508,14 @@ def add(name=None, entry=None, family="ipv4", **kwargs): current_members = _find_set_members(name) if entry in current_members: - return "Warn: Entry {} already exists in set {}".format(entry, name) + return f"Warn: Entry {entry} already exists in set {name}" # Using -exist to ensure entries are updated if the comment changes out = __salt__["cmd.run"](cmd, python_shell=False) if not out: return "Success" - return "Error: {}".format(out) + return f"Error: {out}" def delete(name=None, entry=None, family="ipv4", **kwargs): @@ -537,14 +537,14 @@ def delete(name=None, entry=None, family="ipv4", **kwargs): settype = _find_set_type(name) if not settype: - return "Error: Set {} does not exist".format(name) + return f"Error: Set {name} does not exist" cmd = [_ipset_cmd(), "del", name, entry] out = __salt__["cmd.run"](cmd, python_shell=False) if not out: return "Success" - return "Error: {}".format(out) + return f"Error: {out}" def check(name=None, entry=None, family="ipv4"): @@ -581,7 +581,7 @@ def check(name=None, entry=None, family="ipv4"): settype = _find_set_type(name) if not settype: - return "Error: Set {} does not exist".format(name) + return f"Error: Set {name} does not exist" current_members = _parse_members(settype, _find_set_members(name)) @@ -621,7 +621,7 @@ def test(name=None, entry=None, family="ipv4", **kwargs): settype = _find_set_type(name) if not settype: - return "Error: Set {} does not exist".format(name) + return f"Error: Set {name} does not exist" cmd = [_ipset_cmd(), "test", name, entry] out = __salt__["cmd.run_all"](cmd, python_shell=False) diff --git a/tests/pytests/functional/modules/test_ipset.py b/tests/pytests/functional/modules/test_ipset.py index 16fc12eac8bb..98af02c599f6 100644 --- a/tests/pytests/functional/modules/test_ipset.py +++ b/tests/pytests/functional/modules/test_ipset.py @@ -55,7 +55,7 @@ def test_ipset_new_set_with_family(ipset): """ set_name = "test_name_haship" ret = ipset.new_set(name=set_name, set_type="hash:ip") - assert ret == True + assert ret is True check_set = ipset.list_sets() try: assert any([x for x in check_set if x["Name"] == set_name])