Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFPS: fix to fetch right value from sfp_list to compare in test_sfps test in 'platform_tests/api/test_chassis.py' #3985

Merged
merged 2 commits into from
Aug 26, 2021

Conversation

mannytaheri
Copy link
Contributor

@mannytaheri mannytaheri commented Aug 6, 2021

Description of PR

Fixed the issue: - 'get_all_sfps' returns list which should be traversed from 0 index irrespective of sfp index

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911

Approach

What is the motivation for this PR?

How did you do it?

How did you verify/test it?

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@lguohan
Copy link
Contributor

lguohan commented Aug 13, 2021

look at the history. it was change to sfp_index explicitly, I am not sure if this pr is correct or not.

@sujinmkang , have you confirmed?

d642d05

@rawal01 , can you check?

@rawal01
Copy link
Contributor

rawal01 commented Aug 13, 2021

@lguohan
this is correct as in case of platforms not starting from 0, you will get list of indexes 1...x say,
list_sfps = [1, 2 , ..]
when do chassis.get_all_sfps it returns a list of sfps from DUT for e.g. [sfp1, sfp2 , ...]
current code was doing :

for i in list_sfps:
            sfp = chassis.get_sfp(platform_api_conn, i)
            self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

so sfp for index 1 will get sfp1 the first sfp in DUT by chassis.get_sfp(platform_api_conn, i)
but sfp_list[1] will get second item in list sfp2 instead of sfp1 , as lists are 0 index based (python list), so to correct this we introduced change to fix that.

for i in range(num_sfps):
        index = list_sfps[i]
        sfp = chassis.get_sfp(platform_api_conn, index)
        self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

it will always compare value returned by first index from list of indexes and first item in list from get_all_sfps

After this change it would work for both 0 based and 1 based or even if it is non continuous indexes.
Hope this makes it more clear.

@sujinmkang sujinmkang requested review from stephenxs and a team August 16, 2021 03:45
Copy link
Contributor

@prgeor prgeor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lguohan
this is correct as in case of platforms not starting from 0, you will get list of indexes 1...x say,
list_sfps = [1, 2 , ..]
when do chassis.get_all_sfps it returns a list of sfps from DUT for e.g. [sfp1, sfp2 , ...]
current code was doing :

for i in list_sfps:
            sfp = chassis.get_sfp(platform_api_conn, i)
            self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

so sfp for index 1 will get sfp1 the first sfp in DUT by chassis.get_sfp(platform_api_conn, i)
but sfp_list[1] will get second item in list sfp2 instead of sfp1 , as lists are 0 index based (python list), so to correct this we introduced change to fix that.

for i in range(num_sfps):
        index = list_sfps[i]
        sfp = chassis.get_sfp(platform_api_conn, index)
        self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

it will always compare value returned by first index from list of indexes and first item in list from get_all_sfps

After this change it would work for both 0 based and 1 based or even if it is non continuous indexes.
Hope this makes it more clear.

@lguohan
this is correct as in case of platforms not starting from 0, you will get list of indexes 1...x say,
list_sfps = [1, 2 , ..]
when do chassis.get_all_sfps it returns a list of sfps from DUT for e.g. [sfp1, sfp2 , ...]
current code was doing :

for i in list_sfps:
            sfp = chassis.get_sfp(platform_api_conn, i)
            self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

so sfp for index 1 will get sfp1 the first sfp in DUT by chassis.get_sfp(platform_api_conn, i)
but sfp_list[1] will get second item in list sfp2 instead of sfp1 , as lists are 0 index based (python list), so to correct this we introduced change to fix that.

for i in range(num_sfps):
        index = list_sfps[i]
        sfp = chassis.get_sfp(platform_api_conn, index)
        self.expect(sfp and sfp == sfp_list[i], "SFP {} is incorrect".format(i))

it will always compare value returned by first index from list of indexes and first item in list from get_all_sfps

After this change it would work for both 0 based and 1 based or even if it is non continuous indexes.
Hope this makes it more clear.

The SFP list will always start from index "0". See Ref:- https://github.com/Azure/sonic-platform-common/blob/master/sonic_platform_base/chassis_base.py#L473

chassis.get_sfp(0) should return SFP object corresponding to FIRST physical port, chassis.get_sfp(1) should return the SECOND physical port and so on. The abstract class doesn't talk about any mapping because the chassis object corresponding to a platform should take care of the internal mapping between SFP index and the physical port numbering. The common test relies upon the abstract class definition described and agreed upon by all platforms.

tests/platform_tests/api/test_chassis.py Show resolved Hide resolved
@lguohan
Copy link
Contributor

lguohan commented Aug 17, 2021

i am confused now, are we approving this pr or not? sounds like @prgeor does not agree with the change. @rawal01, can you check the url listed by prince?

@yxieca
Copy link
Collaborator

yxieca commented Aug 18, 2021

I believe @rawal01's quoting is correct. We do want to have index match the front panel numbering, therefore index can start from either 0 or 1.

@prgeor
Copy link
Contributor

prgeor commented Aug 21, 2021

The test_sfps() test case in test_chassis.py is going through a list of SFP objects but in reality, chassis.get_all_sfps() and chassis.get_sfp() is actually not returning objects (see the test logs below)

05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[0]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[1]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[2]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[3]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[4]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[5]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"
05:49:35 test_chassis.test_sfps L0136 INFO | name=
05:49:35 chassis.chassis_api L0016 INFO | Executing chassis API: "get_sfp", arguments: "[6]", result: "{u'module': u'arista.utils.sonic_platform.sfp', u'class': u'Sfp'}"

All the results are same dictionary so there is no point in going through each index. Object serialization is failing here:- https://github.com/Azure/sonic-mgmt/blob/master/tests/common/helpers/platform_api/scripts/platform_api_server.py#L96

Aug 21 05:49:35.557043 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.566908 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: message repeated 33 times: [ Unserializable object: arista.utils.sonic_platform.sfp.Sfp]
Aug 21 05:49:35.566908 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34f485860>
Aug 21 05:49:35.566908 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.570202 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34e7b32b0>
Aug 21 05:49:35.570202 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.573256 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34e7b3320>
Aug 21 05:49:35.573256 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.576528 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34e7b3390>
Aug 21 05:49:35.576528 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.579876 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34e7b3400>
Aug 21 05:49:35.579876 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.583332 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7fe34e7b3470>
Aug 21 05:49:35.583332 str2-7050cx3-acs-09 WARNING pmon#platform_api_server.py: Unserializable object: arista.utils.sonic_platform.sfp.Sfp
Aug 21 05:49:35.586493 str2-7050cx3-acs-09 ERR pmon#platform_api_server.py: $$$ result = <arista.utils.sonic_platform.sfp.Sfp object at 0x7

@prgeor
Copy link
Contributor

prgeor commented Aug 25, 2021

@rawal01 This PR assumes that the ChassisBase._sfp_list[] has all valid SFPs but this assumption doesn't go well with get_sfp() where index starts from '1'. I have fixed this here sonic-net/sonic-platform-common#214. Can you review?

@prgeor prgeor merged commit 1afd2ba into sonic-net:master Aug 26, 2021
vmittal-msft pushed a commit to vmittal-msft/sonic-mgmt that referenced this pull request Sep 28, 2021
…test in 'platform_tests/api/test_chassis.py' (sonic-net#3985)

* get_all_sfps returns list which should be traversed from 0 index irrespective of sfp index

* Update test_chassis.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants