Skip to content

Commit

Permalink
[SAI-PTF]Add platform helper for saiswitch test and refactor saiswitch (
Browse files Browse the repository at this point in the history
#1445)

* [SAI-PTF]Add platform helper for saiswitch test and refactor saiswitch

Make the sai test on different platforms can use their own helpers for
making some platform related settings.

- Register the helper in the common_sai_helper
- Override the helper in the platfrom helper as needed
- Use the method from the helper for platform related settings
- Platform choice the helper and its helper method from the
corresponding platform
- refactor the test from method to class

Signed-off-by: richardyu-ms <[email protected]>

* run switch tests and enable it in warmboot

Signed-off-by: richardyu-ms <[email protected]>

* remove duplicated cases

Signed-off-by: richardyu-ms <[email protected]>

* compatiable with v1, gSwichId and switch_id share the addredd

Signed-off-by: richardyu-ms <[email protected]>
  • Loading branch information
richardyu-ms authored May 6, 2022
1 parent c460675 commit 356e705
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 87 deletions.
28 changes: 28 additions & 0 deletions ptf/platform_helper/brcm_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2022 Microsoft Open Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
# Microsoft would like to thank the following companies for their review and
# assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
# Dell Products, L.P., Facebook, Inc., Marvell International Ltd.
#
# @file __init__.py
#
# @brief init
#

"""
Init the platform helper module.
platform_helper module contains classes to distiguish the different behivor on different platforms.
"""
40 changes: 40 additions & 0 deletions ptf/platform_helper/brcm_helper/brcm_saiswitch_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2022 Microsoft Open Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
# Microsoft would like to thank the following companies for their review and
# assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
# Dell Products, L.P., Facebook, Inc., Marvell International Ltd.


from platform_helper.common_helper.saiswitch_helper import *
from sai_base_test import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

"""
Brcm sai switch helper for sai switch tests.
"""

class BrcmSaiSwitchHelper(SaiSwitchHelper):

def create_route_entry_from_default_vrf(self, client):
print("BrcmSaiSwitchHelper::create_route_entry_from_default_vrf.")
route_entry = sai_thrift_route_entry_t(
switch_id=client.switch_id,
vr_id = client.default_vrf,
destination=sai_ipprefix('0.0.0.0/0'))
status = sai_thrift_create_route_entry(
client.client, route_entry, next_hop_id=client.nhop)
client.assertEqual(status, SAI_STATUS_SUCCESS)
# Cause we add a route here, we need to increase the route_number
if hasattr(client, 'route_number'):
client.route_number += 1
6 changes: 6 additions & 0 deletions ptf/platform_helper/brcm_sai_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
"""

from platform_helper.common_sai_helper import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
from platform_helper.brcm_helper.brcm_saiswitch_helper import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

class BrcmSaiHelper(CommonSaiHelper):
def __init__(self):
super().__init__()
self.switch_helper = BrcmSaiSwitchHelper()


"""
This class contains broadcom(brcm) specified functions for the platform setup and test context configuration.
"""
Expand Down
28 changes: 28 additions & 0 deletions ptf/platform_helper/common_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2022 Microsoft Open Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
# Microsoft would like to thank the following companies for their review and
# assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
# Dell Products, L.P., Facebook, Inc., Marvell International Ltd.
#
# @file __init__.py
#
# @brief init
#

"""
Init the platform helper module.
platform_helper module contains classes to distiguish the different behivor on different platforms.
"""
29 changes: 29 additions & 0 deletions ptf/platform_helper/common_helper/saiswitch_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2022 Microsoft Open Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
# Microsoft would like to thank the following companies for their review and
# assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
# Dell Products, L.P., Facebook, Inc., Marvell International Ltd.

"""
Common sai switch helper for sai switch tests.
"""

class SaiSwitchHelper:
"""
Common sai switch helper for sai switch tests.
"""

def create_route_entry_from_default_vrf(self, client, nhop):
print("SaiSwitchHelper::create_route_entry_from_default_vrf.")
10 changes: 9 additions & 1 deletion ptf/platform_helper/common_sai_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
This file contains base class for other platform classes.
"""
from sai_base_test import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
from platform_helper.common_helper.saiswitch_helper import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

from sai_base_test import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]


class CommonSaiHelper(SaiHelper):
def __init__(self):
super().__init__()
self.switch_helper = SaiSwitchHelper()


"""
This class contains the common functions for the platform setup and test context configuration.
"""
Expand Down
2 changes: 1 addition & 1 deletion ptf/sai_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from sai_thrift import sai_rpc

from sai_utils import *
from sai_utils import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
import sai_thrift.sai_adapter as adapter

ROUTER_MAC = '00:77:66:55:44:00'
Expand Down
6 changes: 3 additions & 3 deletions ptf/sai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

from functools import wraps

from ptf.packet import *
from ptf.testutils import *
from ptf.packet import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
from ptf.testutils import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

from sai_thrift.sai_adapter import *
from sai_thrift.sai_adapter import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]


def sai_thrift_query_attribute_enum_values_capability(client,
Expand Down
4 changes: 2 additions & 2 deletions ptf/saisanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
This file contains some Test classes which are used to the basic functionality of the switch.
"""

from sai_thrift.sai_headers import *
from sai_base_test import *
from sai_thrift.sai_headers import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
from sai_base_test import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]

mac1 = '00:11:11:11:11:11'
mac2 = '00:22:22:22:22:22'
Expand Down
Loading

0 comments on commit 356e705

Please sign in to comment.