diff --git a/go-server-server/go/models.go b/go-server-server/go/models.go index 2a9aca7..953daf6 100644 --- a/go-server-server/go/models.go +++ b/go-server-server/go/models.go @@ -233,13 +233,12 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) { } m.NextHop = *required.NextHop } - + nexthops := strings.Split(m.NextHop, ",") if required.NextHopMonitor != nil { if !strings.Contains(*required.NextHopMonitor, ",") && !IsValidIPBoth(*required.NextHopMonitor) { err = &InvalidFormatError{Field: "nexthop_monitor", Message: "Invalid IP address"} return } - nexthops := strings.Split(m.NextHop, ",") nexthop_mon := strings.Split(*required.NextHopMonitor, ",") if len(nexthops) != len(nexthop_mon) { err = &InvalidFormatError{Field: "nexthop_monitor", Message: "there must be equal number of nexthop(s) and nexthop_monitor(s)"} @@ -249,11 +248,19 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) { } if required.IfName == nil && required.MACAddress != nil { - _, err = net.ParseMAC(*required.MACAddress) + mac_addresses := strings.Split(*required.MACAddress, ",") + if len(nexthops) != len(mac_addresses) { + err = &InvalidFormatError{Field: "mac_address", Message: "there must be equal number of nexthop(s) and mac_address(es)"} + return + } - if err != nil { - err = &InvalidFormatError{Field: "mac_address", Message: "Invalid MAC address"} - return + for _, mac := range mac_addresses { + _, err = net.ParseMAC(mac) + + if err != nil { + err = &InvalidFormatError{Field: "mac_address", Message: "Invalid MAC address"} + return + } } m.MACAddress = *required.MACAddress } diff --git a/sonic_api.yaml b/sonic_api.yaml index b1e3fa2..9b435e0 100644 --- a/sonic_api.yaml +++ b/sonic_api.yaml @@ -195,7 +195,7 @@ paths: required: true schema: $ref: '#/definitions/ResetStatusEntry' - description: The value of configuration reset status. Only true or false accepted + description: The value of configuration reset status. Only "true" or "false" string values accepted responses: '200': description: OK @@ -2854,5 +2854,5 @@ definitions: - reset_status properties: reset_status: - type: boolean + type: string description: configuration reset status. \ No newline at end of file diff --git a/test/test_restapi.py b/test/test_restapi.py index cb557e7..0f861b7 100644 --- a/test/test_restapi.py +++ b/test/test_restapi.py @@ -778,7 +778,7 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client): # Mac address Optional arg del route['vnid'] - route['mac_address'] = '00:08:aa:bb:cd:ef' + route['mac_address'] = '00:08:aa:bb:cc:dd,00:08:aa:bb:cd:ef' route['cmd'] = 'add' r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) assert r.status_code == 204 @@ -794,6 +794,7 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client): assert r.status_code == 200 j = json.loads(r.text) assert sorted(j) == sorted(routes) + # Endpoint Monitor optional arg route['vnid'] = 5000 route['nexthop_monitor'] = '100.3.152.32,200.3.152.32' @@ -1623,12 +1624,21 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client): } route['vnid'] = 5000 route['nexthop_monitor'] = '700.3.152.327' - route['cmd'] = 'add' r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) assert r.status_code == 400 route['nexthop_monitor'] = '100.3.152.32,200.3.152.32' r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) assert r.status_code == 400 + del route['nexthop_monitor'] + route['mac_address'] = '00:08:xx:bb:cc:dd' + r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) + assert r.status_code == 400 + route['mac_address'] = '00:08:aa:bb:cc:dd,00:08:aa:bb:cd:ef' + r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) + assert r.status_code == 400 + route['mac_address'] = '0008aabbccdd' + r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) + assert r.status_code == 400 del route['nexthop'] r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route]) assert r.status_code == 400