Skip to content

Commit

Permalink
Comply with pre-commit and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourkeostk authored and Megan Wilhite committed Sep 5, 2023
1 parent 89bdd91 commit 5878e22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions salt/modules/ipset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -478,44 +478,44 @@ 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"]

cmd = [_ipset_cmd(), "add", "-exist", name] + entry.split()

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:
cmd.extend([item, kwargs[item]])

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):
Expand All @@ -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"):
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/pytests/functional/modules/test_ipset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 5878e22

Please sign in to comment.