Skip to content

Commit

Permalink
sonic-yang-models: Update test cases in preparation for libyang3
Browse files Browse the repository at this point in the history
This mostly simplifies the existing test cases and standardizes
behavior where they may be incompatible with libyang3.  The main goal
is to have this in place before the migration to libyang3 to make it
easier to evaluate the actual code review for porting aspects for libyang3.

Convert some yang model test cases that use `eStr` for failure matching
to use `eStrKey` instead to standardize expected failure matching so
when messsages change they can be updated in one place instead of all
over.

Also, split out some new `eStrKey` values that are needed for libyang3
due to different messages, and document the libyang3 values needed once
upgraded but keep libyang1 values for now.

Finally, some tests were using both `eStr` and `eStrKey` and the `eStr`
portion is not needed to perform a meaningful validation, plus the
`eStr` in these cases are not valid for libyang3.
  • Loading branch information
bradh352 committed Feb 10, 2025
1 parent b424856 commit 852d821
Show file tree
Hide file tree
Showing 43 changed files with 143 additions and 152 deletions.
22 changes: 16 additions & 6 deletions src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,27 @@ class Test_yang_models:
def initTest(self):
self.defaultYANGFailure = {
'Must': ['Must condition', 'not satisfied'],
'InvalidValue': ['Invalid value'],
'LeafRef': ['Leafref', 'non-existing'],
'InvalidValue': ['Invalid value'], # libyang3: ['Invalid', 'value', 'Data path']
'LeafRef': ['Leafref', 'non-existing'], #libyang3: ['Invalid leafref', 'no target instance']
'When': ['When condition', 'not satisfied'],
'Pattern': ['pattern', 'does not satisfy'],
'Mandatory': ['required element', 'Missing'],
'Pattern': ['pattern', 'does not satisfy'], #libyang3: ['pattern', 'Unsatisfied pattern']
'Mandatory': ['required element', 'Missing'], #libyang3: ['Mandatory node', 'does not exist']
'Verify': ['verified'],
'Range': ['does not satisfy', 'range'],
'Range': ['does not satisfy', 'range'], #libyang3: ['Unsatisfied range']
'MinElements': ['Too few'],
'MaxElements': ['Too many'],
'UnknownElement': ['Unknown element'],
'None': []
'None': [],
# New keys are needed for libyang3's messages which are different. Go
# ahead and add them now with the libyang1 values (which are duplicates
# of the above). This will make migrating to libyang3 easier with less
# code review.
'Length': ['does not satisfy', 'range'], # libyang3: ['Unsatisfied length']
'DecimalFractionExceed': ['Invalid value'], # libyang3: ['Value', 'exceeds defined number', 'fraction digits']
'Bounds': ['Invalid value'], #libyang3 ['Value', 'out of type', 'min/max bounds'],
'ListKey': ['Missing required element'], #libyang3 ['List instance is missing its key']
'DateTime': ['pattern', 'does not satisfy'], #libyang3: ['Invalid date-and-time']
'IPv4': ['pattern', 'does not satisfy'], #libyang3 ['Failed to convert IPv4 address'],
}

self.ExceptionTests = { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"ASIC_SENSORS_INVALID_POLLER_INTERVAL": {
"desc": "Configure an invalid ASIC Sensors polling interval",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"ASIC_SENSORS_INVALID_POLLER_ADMIN_STATUS": {
"desc": "Configure an invalid ASIC Sensors polling admin status",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
},
"AUTO_TECHSUPPORT_OUT_OF_RANGE_DECIMAL": {
"desc" : "Configure a value for core-uage outside the range [0, 100)",
"eStr": "Value \"100.00\" does not satisfy the constraint \"0..99.99\" (range, length, or pattern)."
"eStrKey": "Range"
},
"AUTO_TECHSUPPORT_VALID_DECIMAL_VALUE": {
"desc" : "Configure a value for max_techsupport_size inside the range [0, 100)"
},
"AUTO_TECHSUPPORT_INVALID_FRACTION_DIGITS": {
"desc" : "Configure a value for max_techsupport_size inside the range [0, 100) but with 3 fractional digits",
"eStrKey": "InvalidValue"
"eStrKey": "DecimalFractionExceed"
},
"AUTO_TECHSUPPORT_RATE_LIMIT_INTERVAL_TEST": {
"desc" : "Configure and test the valid configuration"
Expand All @@ -29,13 +29,13 @@
},
"AUTO_TECHSUPPORT_INVALID_AVAILABLE_MEM_THRESHOLD": {
"desc" : "Configure a value for available_mem_threshold inside the range [0, 100) but with 3 fractional digits",
"eStrKey": "InvalidValue"
"eStrKey": "DecimalFractionExceed"
},
"AUTO_TECHSUPPORT_GLOBAL_MEM_THRESHOLD_VALID": {
"desc" : "Configure and test the valid configuration"
},
"AUTO_TECHSUPPORT_GLOBAL_MEM_THRESHOLD_INVALID_THRESHOLD": {
"desc" : "Configure a value for available_mem_threshold inside the range [0, 100) but with 3 fractional digits",
"eStrKey": "InvalidValue"
"eStrKey": "DecimalFractionExceed"
}
}
11 changes: 5 additions & 6 deletions src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
},
"BGP_NEIGHBOR_NEG_INVALID_NAME": {
"desc": "Incorrect neighbor name.",
"eStrKey": "InvalidValue",
"eStr": ["neighbor"]
"eStrKey": "InvalidValue"
},
"BGP_NEIGHBOR_NEG_INVALID_ASN": {
"desc": "Invalid local AS number.",
Expand All @@ -78,7 +77,7 @@
},
"BGP_NEIGHBOR_AF_NEG_INVALID_MAXTHRESHOLD": {
"desc": "Invalid maximum prefix warning threshold in neighbor AF.",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"BGP_NEIGHBOR_AF_NEG_INVALID_SOFT_RECFG_IN": {
"desc": "Invalid boolean value for soft reconfiguration-in in neighbor AF.",
Expand Down Expand Up @@ -118,11 +117,11 @@
},
"BGP_PEERGROUP_INVALID_HOPS": {
"desc": "Invalid TTL hops for peergroup.",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"BGP_PEERGROUP_AF_INVALID_MAXTHRESHOLD": {
"desc": "Invalid maximum prefix warning threshold in peergroup AF.",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"BGP_PEERGROUP_AF_INVALID_SOFT_RECFG_IN": {
"desc": "Invalid boolean value for soft reconfiguration-in in peergroup AF.",
Expand Down Expand Up @@ -157,7 +156,7 @@
},
"BGP_NEIGHBOR_NEG_INVALID_HOPS": {
"desc": "Invalid TTL hops for unnumbered interface neigbhor.",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"BGP_MONITORS_ALL_VALID": {
"desc": "Configure BGP monitor table."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"BUFFER_POOL_WRONG_PERCENTAGE_NEGATIVE_VALUE": {
"desc": "BUFFER_POOL_WRONG_PERCENTAGE_NEGATIVE_VALUE pattern failure.",
"eStr": "Invalid value"
"eStrKey": "Bounds"
},
"BUFFER_POOL_WRONG_PERCENTAGE_NOT_A_NUMBER_VALUE": {
"desc": "BUFFER_POOL_WRONG_PERCENTAGE_NOT_A_NUMBER_VALUE pattern failure.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"DEVICE_METADATA_INCORRECT_BUFFER_MODEL_PATTERN": {
"desc": "DEVICE_METADATA wrong value for BUFFER_MODEL field.",
"eStr": ["pattern", "does not satisfy"]
"eStrKey": "Pattern"
},
"DEVICE_METADATA_FRR_MGMT_FWK_CONFIG": {
"desc": "Verifying FRR MGMT framework configuration."
Expand Down Expand Up @@ -118,7 +118,7 @@
},
"DEVICE_METADATA_INVALID_PEER_SWITCH": {
"desc": "Verifying test fails with hostname that is too long",
"eStrKey": "Range"
"eStrKey": "Length"
},
"DEVICE_METADATA_VALID_STORAGE_DEVICE": {
"desc": "Verifying valid storage device value"
Expand Down Expand Up @@ -169,7 +169,7 @@
},
"DEVICE_METADATA_INVALID_TIMEZONE": {
"desc": "Verifying invalid timezone value",
"eStrKey": "Range"
"eStrKey": "Length"
},
"DEVICE_METADATA_VALID_CREATE_ONLY_CONFIG_DB_BUFFERS": {
"desc": "Verifying the create_only_config_db_buffers value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"DHCP_SERVER_IPV4_INCORRECT_NETMASK": {
"desc": "Add netmask which is not in correct ip-prefix format.",
"eStrKey": "Pattern"
"eStrKey": "IPv4"
},
"DHCP_SERVER_IPV4_STATE_WRONG_VALUE": {
"desc": "Configure wrong value for state.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
},
"FG_NHG_MEMBER_TEST_MISSING_FG_NHG_REF": {
"desc": "Fine-grained ECMP next-hop member configuration with missing FG_NHG reference in FG_NHG_MEMBER_LIST table.",
"eStr": "Missing required element \"FG_NHG\" in \"FG_NHG_MEMBER_LIST\". "
"eStrKey": "Mandatory"
},
"FG_NHG_PREFIX_TEST_MISSING_FG_NHG_REF": {
"desc": "Fine-grained ECMP prefix configuration with missing FG_NHG reference in FG_NHG_PREFIX_LIST table.",
"eStr": "Missing required element \"FG_NHG\" in \"FG_NHG_PREFIX_LIST\". "
"eStrKey": "Mandatory"
},
"FG_NHG_MEMBER_TEST_MISSING_BANK": {
"desc": "Fine-grained ECMP next-hop member configuration with missing bank in FG_NHG_MEMBER_LIST table.",
"eStr": "Missing required element \"bank\""
"eStrKey": "Mandatory"
},
"FG_NHG_PREFIX_TEST_DUPLICATE_ENTRY": {
"desc": "Fine-grained ECMP prefix configuration with duplicate entry in FG_NHG_PREFIX_LIST table.",
Expand All @@ -56,4 +56,4 @@
"desc": "Fine-grained ECMP next-hop member configuration with duplicate member in FG_NHG_MEMBER_LIST table.",
"eStr": "Duplicated instance of \"FG_NHG_MEMBER_LIST\" list."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
},
"FLEX_COUNTER_TABLE_WITH_INVALID_POLL_INTERVAL": {
"desc": "Out of range poll interval.",
"eStrKey": "Range",
"eStr": "100..4294967295"
"eStrKey": "Range"
},
"FLEX_COUNTER_TABLE_WITH_VALID_BULK_CHUNK_SIZE": {
"desc": "FLEX_COUNTER_TABLE_WITH_VALID_BULK_CHUNK_SIZE no failure."
},
"FLEX_COUNTER_TABLE_WITH_INVALID_BULK_CHUNK_SIZE": {
"desc": "Out of range bulk chunk size.",
"eStrKey": "Range",
"eStr": "1..4294967295"
"eStrKey": "Range"
},
"FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_VRF": {
"desc": "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_VRF no failure."
Expand All @@ -23,7 +21,6 @@
},
"FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_INVALID_MAX_MATCH_COUNT": {
"desc": "Out of range max_match_count.",
"eStrKey": "Range",
"eStr": "1..50"
"eStrKey": "Range"
}
}
4 changes: 2 additions & 2 deletions src/sonic-yang-models/tests/yang_model_tests/tests/kdump.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"KDUMP_WITH_INVALID_NUM_DUMPS": {
"desc": "Configuring kdump config with a invalid number of allowed kdumps.",
"eStr": ["pattern", "does not satisfy"]
"eStrKey": "Range"
},
"KDUMP_WITH_INVALID_MEMORY": {
"desc": "Configuring kdump config with invalid memory config.",
"eStr": ["pattern", "does not satisfy"]
"eStrKey": "Pattern"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"KUBERNETES_MASTER_INVALID_PORT": {
"desc": "Configure invalid PORT in kubernetes_master.",
"eStrKey": "InvalidValue"
"eStrKey": "Bounds"
},
"KUBERNETES_MASTER_INVALID_IP" : {
"desc": "Configure invalid IP in kubernetes_master.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
},
"MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": {
"desc": "Configuring memory statistics with an invalid sampling_interval ( out of acceptable range).",
"eStrKey": "Range",
"eStr": "3..15"
"eStrKey": "Range"
},
"MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": {
"desc": "Configuring memory statistics with an invalid retention_period (out of acceptable range).",
"eStrKey": "Range",
"eStr": "1..30"
"eStrKey": "Range"
},
"MEMORY_STATISTICS_WITH_ENABLE_FEATURE": {
"desc": "Enabling memory statistics feature with valid values."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
},
"MGMT_PORT_INVALID_SPEED": {
"desc": "INVALID SPEED",
"eStrKey": "Range",
"eStr": ["10|100|1000"]
"eStrKey": "Range"
},
"MGMT_PORT_INVALID_MTU": {
"desc": "INVALID MTU",
"eStrKey": "Range",
"eStr": "1500..9216"
"eStrKey": "Range"
},
"MGMT_PORT_DEFAULT_MTU": {
"desc": "VALIDATE DEFAULT MTU",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL": {
"desc": "Configuring ERSPAN entry with invalid ttl",
"eStr": "Invalid ttl value"
"eStrKey": "Bounds"
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL_TYPE": {
"desc": "Configuring ERSPAN entry with invalid ttl",
Expand Down
9 changes: 4 additions & 5 deletions src/sonic-yang-models/tests/yang_model_tests/tests/nat.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
},
"STATIC_NAPT_ENTRY_WRONG_GLOBAL_L4_PORT": {
"desc": "Configuring a wrong global l4 port in Static NAPT table.",
"eStrKey": "InvalidValue",
"eStr": ["global_l4_port"]
"eStrKey": "Bounds"
},
"STATIC_NAPT_ENTRY_WITHOUT_LOCAL_IP": {
"desc": "Configuring a Static NAPT table without local ip.",
Expand All @@ -26,7 +25,7 @@
},
"STATIC_NAPT_ENTRY_INVALID_TWICE_NAT_ID": {
"desc": "Configuring a invalid twice nat id in Static NAPT table.",
"eStrKey": "InvalidValue"
"eStrKey": "Bounds"
},
"STATIC_NAT_ENTRY_WITH_VALID_VALUES": {
"desc": "Configuring the Static NAT table with valid values."
Expand All @@ -41,7 +40,7 @@
},
"STATIC_NAT_ENTRY_INVALID_TWICE_NAT_ID": {
"desc": "Configuring a invalid twice nat id in Static NAT table.",
"eStrKey": "InvalidValue"
"eStrKey": "Bounds"
},
"NAT_GLOBAL_WITH_VALID_VALUES": {
"desc": "Configuring a NAT Global table with valid values."
Expand Down Expand Up @@ -92,7 +91,7 @@
},
"NAT_BINDING_WITH_INVALID_TWICE_NAT_ID": {
"desc": "Configuring a invalid twice nat id in NAT Binding table.",
"eStrKey": "InvalidValue"
"eStrKey": "Bounds"
},
"NAT_BINDING_WITHOUT_ACL_TABLE": {
"desc": "Configuring a NAT Binding table without acl."
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-yang-models/tests/yang_model_tests/tests/neigh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

"NEIGH_MISSING_IP": {
"desc": "Load NEIGH missing IP address",
"eStr": ["Invalid JSON data"]
"eStrKey": "ListKey"
},

"NEIGH_INVALID_VLAN": {
"desc": "Load NEIGH missing VLAN",
"eStr": ["does not satisfy the constraint"]
"eStrKey": "Pattern"
}
}
4 changes: 2 additions & 2 deletions src/sonic-yang-models/tests/yang_model_tests/tests/ntp.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
},
"NTP_KEY_ID_INVALID": {
"desc": "NTP authentication keys invalid key id",
"eStrKey": "InvalidValue"
"eStrKey": "Bounds"
},
"NTP_KEY_TRUSTED_INVALID": {
"desc": "NTP authentication keys invalid trustiness",
Expand All @@ -134,6 +134,6 @@
},
"NTP_KEY_VALUE_INVALID": {
"desc": "NTP authentication keys bad key value",
"eStrKey": "Range"
"eStrKey": "Length"
}
}
6 changes: 3 additions & 3 deletions src/sonic-yang-models/tests/yang_model_tests/tests/nvgre.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

"NVGRE_TUNNEL_MAP_INVALID_VLAN_ID": {
"desc": "Invalid VLAN ID",
"eStrKey": "Pattern"
"eStrKey": "Range"
},

"NVGRE_TUNNEL_MAP_INVALID_VSID": {
"desc": "INVALID VSID value for NVGRE_TUNNEL_MAP",
"eStrKey": "Pattern"
"eStrKey": "Range"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
},
"PASSWORD_BAD_HISTORY_CNT": {
"desc": "Configure password history_cnt with out of range value",
"eStrKey" : "InvalidValue"
"eStrKey" : "Bounds"
},
"PASSWORD_BAD_LEN_MIN": {
"desc": "Configure password len-min with out of range value",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"PASSWORD_BAD_EXPIRATION": {
"desc": "Configure password expiration with out of range value",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
},
"PASSWORD_BAD_EXPIRATION_WARN": {
"desc": "Configure password expiration-warning with out of range value",
"eStrKey" : "Pattern"
"eStrKey" : "Range"
}
}
}
Loading

0 comments on commit 852d821

Please sign in to comment.