diff --git a/src/nethsec/mwan/__init__.py b/src/nethsec/mwan/__init__.py index b2c7f2f5..282bf3a3 100644 --- a/src/nethsec/mwan/__init__.py +++ b/src/nethsec/mwan/__init__.py @@ -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') diff --git a/tests/test_mwan.py b/tests/test_mwan.py index 4cd27b0e..d593c747 100644 --- a/tests/test_mwan.py +++ b/tests/test_mwan.py @@ -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() \ No newline at end of file