Fix ipset new_set bug

This commit is contained in:
Stephen Bourke 2023-08-24 13:53:04 +01:00 committed by Megan Wilhite
parent 8f9405cf8e
commit f1a35823f7
3 changed files with 18 additions and 1 deletions

1
changelog/61620.fixed.md Normal file
View file

@ -0,0 +1 @@
`ipset.new_set` no longer fails when creating a set type that uses the `family` create option

View file

@ -328,7 +328,7 @@ def new_set(name=None, set_type=None, family="ipv4", comment=False, **kwargs):
# Family only valid for certain set types
if "family" in _CREATE_OPTIONS[set_type]:
cmd.extend(["family", cmd, ipset_family])
cmd.extend(["family", ipset_family])
if comment:
cmd.append("comment")

View file

@ -47,3 +47,19 @@ def test_ipset_add_comment_kwarg(ipset, setup_set):
assert ret == "Success"
check_set = ipset.list_sets()
assert any([x for x in check_set if x["Name"] == setup_set])
def test_ipset_new_set_with_family(ipset):
"""
test ipset.new_set with set_type that uses family (eg. hash:ip)
"""
set_name = "test_name_haship"
ret = ipset.new_set(name=set_name, set_type="hash:ip")
assert ret == True
check_set = ipset.list_sets()
try:
assert any([x for x in check_set if x["Name"] == set_name])
except Exception as e:
raise e
finally:
ipset.delete_set(set_name)