Skip to content

Commit

Permalink
feat: added rule deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Sep 28, 2023
1 parent 618b0e3 commit 2f78cdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/nethsec/mwan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,11 @@ def order_rules(e_uci: EUci, rules: list[str]) -> list[str]:

e_uci.save('mwan3')
return order


def delete_rule(e_uci: EUci, name: str):
if name not in utils.get_all_by_type(e_uci, 'mwan3', 'rule').keys():
raise ValidationError('name', 'invalid', name)

e_uci.delete('mwan3', name)
e_uci.save('mwan3')
19 changes: 19 additions & 0 deletions tests/test_mwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,22 @@ def test_index_rules(e_uci, mocker):
'label': 'default',
}
}


def test_delete_rule(e_uci, mocker):
mocker.patch('subprocess.run')
mwan.store_policy(e_uci, 'default', [
{
'name': 'RED_1',
'metric': '10',
'weight': '100',
},
{
'name': 'RED_2',
'metric': '10',
'weight': '100',
}
])
mwan.store_rule(e_uci, 'additional rule', 'ns_default')
mwan.delete_rule(e_uci, 'ns_additional_r')
assert 'ns_additional_r' not in e_uci.get_all('mwan3').keys()

0 comments on commit 2f78cdc

Please sign in to comment.