diff --git a/vmware_nsxlib/tests/unit/v3/test_security.py b/vmware_nsxlib/tests/unit/v3/test_security.py index c7705e76..b0b3641c 100644 --- a/vmware_nsxlib/tests/unit/v3/test_security.py +++ b/vmware_nsxlib/tests/unit/v3/test_security.py @@ -62,6 +62,26 @@ class TestNsxLibFirewallSection(nsxlib_testcase.NsxLibTestCase): } self.assertEqual(expected, result) + def test_get_rule_dict(self): + result = self.nsxlib.firewall_section.get_rule_dict( + 'display_name', sources='sources', destinations='destinations', + direction=const.IN_OUT, ip_protocol=const.IPV4_IPV6, + services='services', action=const.FW_ACTION_ALLOW, + logged=True, disabled=True, applied_tos='applied_tos', + rule_tag='rule_tag') + expected = {'display_name': 'display_name', + 'sources': 'sources', + 'destinations': 'destinations', + 'direction': const.IN_OUT, + 'ip_protocol': const.IPV4_IPV6, + 'services': 'services', + 'action': const.FW_ACTION_ALLOW, + 'logged': True, + 'disabled': True, + 'applied_tos': 'applied_tos', + 'rule_tag': 'rule_tag'} + self.assertEqual(expected, result) + def test_create_rules_with_protocol(self): with mock.patch("vmware_nsxlib.v3.security.NsxLibFirewallSection" ".add_rules") as add_rules: diff --git a/vmware_nsxlib/v3/security.py b/vmware_nsxlib/v3/security.py index 47bb3b14..bbfeb02c 100644 --- a/vmware_nsxlib/v3/security.py +++ b/vmware_nsxlib/v3/security.py @@ -407,7 +407,8 @@ class NsxLibFirewallSection(utils.NsxLibApiBase): def get_rule_dict(self, display_name, sources=None, destinations=None, direction=consts.IN_OUT, ip_protocol=consts.IPV4_IPV6, services=None, action=consts.FW_ACTION_ALLOW, - logged=False, disabled=False, applied_tos=None): + logged=False, disabled=False, applied_tos=None, + rule_tag=None): rule_dict = {'display_name': display_name, 'direction': direction, 'ip_protocol': ip_protocol, @@ -419,6 +420,8 @@ class NsxLibFirewallSection(utils.NsxLibApiBase): 'services': services or []} if applied_tos is not None: rule_dict['applied_tos'] = applied_tos + if rule_tag is not None: + rule_dict['rule_tag'] = rule_tag return rule_dict def add_rule(self, rule, section_id, operation=consts.FW_INSERT_BOTTOM):