From 7d55d269c0b41e717192ed1e0a596525d8e63f5d Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Mon, 25 Jul 2022 21:51:21 +0000 Subject: [PATCH 1/3] Mac Address changes --- go-server-server/go/models.go | 19 +++++++++++++------ sonic_api.yaml | 4 ++-- test/test_restapi.py | 13 +++++++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/go-server-server/go/models.go b/go-server-server/go/models.go index 2a9aca7..6b9d321 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_address { + _, 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 7f38783..9fb7649 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' @@ -1609,12 +1610,20 @@ 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 + route['mac_address'] = '00:08:aa: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:xx:bb:cc:dd,00:08:yy: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,0008aabbcdef' + 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 From 461e6c6fb17eb4f42bcaddb4e088c5e02f9fb20b Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Mon, 25 Jul 2022 22:47:16 +0000 Subject: [PATCH 2/3] fix typo --- go-server-server/go/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-server-server/go/models.go b/go-server-server/go/models.go index 6b9d321..953daf6 100644 --- a/go-server-server/go/models.go +++ b/go-server-server/go/models.go @@ -254,7 +254,7 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) { return } - for _, mac := range mac_address { + for _, mac := range mac_addresses { _, err = net.ParseMAC(mac) if err != nil { From 1e71cf1b3ca2c5ba4e9796a8f8f821da717ffdfa Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Tue, 26 Jul 2022 18:17:36 +0000 Subject: [PATCH 3/3] fix tests --- test/test_restapi.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_restapi.py b/test/test_restapi.py index 9fb7649..8170260 100644 --- a/test/test_restapi.py +++ b/test/test_restapi.py @@ -1615,13 +1615,14 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client): 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 - route['mac_address'] = '00:08:aa:bb:cc:dd' + 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:xx:bb:cc:dd,00:08:yy:bb:cd:ef' + 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,0008aabbcdef' + 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']