|
14 | 14 |
|
15 | 15 | class TestValidateFieldOperation(unittest.TestCase):
|
16 | 16 |
|
| 17 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="")) |
| 18 | + def test_port_config_update_validator_valid_speed_no_state_db(self): |
| 19 | + patch_element = {"path": "/PORT/Ethernet3", "op": "add", "value": {"speed": "234"}} |
| 20 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 21 | + |
| 22 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="40000,30000")) |
| 23 | + def test_port_config_update_validator_invalid_speed_existing_state_db(self): |
| 24 | + patch_element = {"path": "/PORT/Ethernet3", "op": "add", "value": {"speed": "xyz"}} |
| 25 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 26 | + |
| 27 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 28 | + def test_port_config_update_validator_valid_speed_existing_state_db(self): |
| 29 | + patch_element = {"path": "/PORT/Ethernet3", "op": "add", "value": {"speed": "234"}} |
| 30 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 31 | + |
| 32 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 33 | + def test_port_config_update_validator_valid_speed_existing_state_db(self): |
| 34 | + patch_element = {"path": "/PORT/Ethernet3/speed", "op": "add", "value": "234"} |
| 35 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 36 | + |
| 37 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 38 | + def test_port_config_update_validator_invalid_speed_existing_state_db(self): |
| 39 | + patch_element = {"path": "/PORT/Ethernet3/speed", "op": "add", "value": "235"} |
| 40 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 41 | + |
| 42 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 43 | + def test_port_config_update_validator_invalid_speed_existing_state_db_nested(self): |
| 44 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "speed": "235"}}} |
| 45 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 46 | + |
| 47 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 48 | + def test_port_config_update_validator_valid_speed_existing_state_db_nested(self): |
| 49 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "speed": "234"}, "Ethernet4": {"alias": "Eth4", "speed": "234"}}} |
| 50 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 51 | + |
| 52 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="123,234")) |
| 53 | + def test_port_config_update_validator_invalid_speed_existing_state_db_nested_2(self): |
| 54 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "speed": "234"}, "Ethernet4": {"alias": "Eth4", "speed": "236"}}} |
| 55 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 56 | + |
| 57 | + def test_port_config_update_validator_remove(self): |
| 58 | + patch_element = {"path": "/PORT/Ethernet3", "op": "remove"} |
| 59 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 60 | + |
| 61 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="rs, fc")) |
| 62 | + def test_port_config_update_validator_invalid_fec_existing_state_db(self): |
| 63 | + patch_element = {"path": "/PORT/Ethernet3/fec", "op": "add", "value": "asf"} |
| 64 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 65 | + |
| 66 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="rs, fc")) |
| 67 | + def test_port_config_update_validator_invalid_fec_existing_state_db_nested(self): |
| 68 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "fec": "none"}, "Ethernet4": {"alias": "Eth4", "fec": "fs"}}} |
| 69 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 70 | + |
| 71 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="rs, fc")) |
| 72 | + def test_port_config_update_validator_valid_fec_existing_state_db_nested(self): |
| 73 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "fec": "fc"}}} |
| 74 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 75 | + |
| 76 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="rs, fc")) |
| 77 | + def test_port_config_update_validator_valid_fec_existing_state_db_nested_2(self): |
| 78 | + patch_element = {"path": "/PORT", "op": "add", "value": {"Ethernet3": {"alias": "Eth0", "fec": "rs"}, "Ethernet4": {"alias": "Eth4", "fec": "fc"}}} |
| 79 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 80 | + |
| 81 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="rs, fc")) |
| 82 | + def test_port_config_update_validator_valid_fec_existing_state_db(self): |
| 83 | + patch_element = {"path": "/PORT/Ethernet3/fec", "op": "add", "value": "rs"} |
| 84 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 85 | + |
| 86 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="")) |
| 87 | + def test_port_config_update_validator_valid_fec_no_state_db(self): |
| 88 | + patch_element = {"path": "/PORT/Ethernet3", "op": "add", "value": {"fec": "rs"}} |
| 89 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == True |
| 90 | + |
| 91 | + @patch("generic_config_updater.field_operation_validators.read_statedb_entry", mock.Mock(return_value="")) |
| 92 | + def test_port_config_update_validator_invalid_fec_no_state_db(self): |
| 93 | + patch_element = {"path": "/PORT/Ethernet3/fec", "op": "add", "value": "rsf"} |
| 94 | + assert generic_config_updater.field_operation_validators.port_config_update_validator(patch_element) == False |
| 95 | + |
17 | 96 | @patch("generic_config_updater.field_operation_validators.get_asic_name", mock.Mock(return_value="unknown"))
|
18 | 97 | def test_rdma_config_update_validator_unknown_asic(self):
|
19 | 98 | patch_element = {"path": "/PFC_WD/Ethernet4/restoration_time", "op": "replace", "value": "234234"}
|
|
0 commit comments