diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index d2cab6ad..ab23c78a 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -941,6 +941,14 @@ class TestPolicyIcmpService(NsxPolicyLibTestCase): self.assert_called_with_defs( update_call, [service_def, entry_def]) + def test_icmp_type_and_code_in_obj_dict(self): + icmp_type, icmp_code = 0, 0 + entry_def = core_defs.IcmpServiceEntryDef( + icmp_type=icmp_type, icmp_code=icmp_code) + body = entry_def.get_obj_dict() + self.assertEqual(icmp_type, body["icmp_type"]) + self.assertEqual(icmp_code, body["icmp_code"]) + class TestPolicyIPProtocolService(NsxPolicyLibTestCase): @@ -1062,6 +1070,13 @@ class TestPolicyIPProtocolService(NsxPolicyLibTestCase): self.assert_called_with_defs(service_update_call, [service_def, entry_def]) + def test_protocol_number_in_obj_dict(self): + protocol_number = 0 + entry_def = core_defs.IPProtocolServiceEntryDef( + protocol_number=protocol_number) + body = entry_def.get_obj_dict() + self.assertEqual(protocol_number, body["protocol_number"]) + class TestPolicyMixedService(NsxPolicyLibTestCase): diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 5d72b098..51d5f86c 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1167,7 +1167,8 @@ class IcmpServiceEntryDef(ServiceEntryDef): body['protocol'] = 'ICMPv' + str(self.get_attr('version')) for attr in ('icmp_type', 'icmp_code'): - if self.get_attr(attr): + # Note that icmp_type and icmp_code could be 0. + if self.get_attr(attr) is not None: body[attr] = self.get_attr(attr) return body @@ -1180,7 +1181,8 @@ class IPProtocolServiceEntryDef(ServiceEntryDef): def get_obj_dict(self): body = super(IPProtocolServiceEntryDef, self).get_obj_dict() - if self.get_attr('protocol_number'): + if self.get_attr('protocol_number') is not None: + # Note that protocol_number could be 0. body['protocol_number'] = self.get_attr('protocol_number') return body