Skip to content
New issue

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

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

Already on GitHub? # to your account

[syseepromd] Support both new platform API and old platform plugins #36

Merged
merged 2 commits into from
Aug 6, 2019

Conversation

stephenxs
Copy link
Collaborator

Support new platform api with plugin mode compatible.
In this PR, new platform api is supported in following steps:

  1. initialization, load new-platform-api-based class eeprom or chassis for syseepromd and psud respectively, if failed then load old style plugin.
  2. for each api, call new platform api, old style plugin is called if the former raised a NotImplementError; other Exceptions raised will be passed to caller without handling.

now only two APIs are called in syseepromd, update_eeprom_db and read_eeprom.
it depends on the sonic-platform-common #48 add get_eeprom to Chassis for syseepromd to access

@jleveque jleveque changed the title [syseepromd] support new platform api with plugin mode compatible (syseepromd) [syseepromd] Support both new platform API and old platform plugins Jul 31, 2019
Copy link
Contributor

@jleveque jleveque left a comment

Choose a reason for hiding this comment

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

After thinking about this more, I think we can make this change even smaller. Because no matter which API gets loaded (the new API or the old plugin), the resulting object is handled the same way. Do you see any reason why we can't do the following:

  1. Remove eeprom_util, load_eeprom_util(), load_platform_api() and all _wrapper_*() functions completely.
  2. Replace lines 136-140 with something like the following:
        # First, try to load the new platform API
        try:
            import sonic_platform
            self.chassis = sonic_platform.platform.Platform().get_chassis()
            self.eeprom = self.chassis.get_eeprom()
        except Exception as e:
            logger.log_warning("Failed to load platform-specific eeprom from sonic_platform package due to {}".format(repr(e)))
        finally:
            # If we didn't successfully load the class from the sonic_platform package, try loading the old plugin
            if not self.eeprom:
                try:
                    self.eeprom = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
                except Exception as e:
                    logger.log_error("Failed to load platform-specific eeprom implementation: %s" % (str(e)), True)

        if not self.eeprom:
            sys.exit(ERR_EEPROMUTIL_LOAD)

Then all the functions can simply reference self.eeprom. Will this work or am I missing something?

@stephenxs
Copy link
Collaborator Author

stephenxs commented Aug 1, 2019 via email

@jleveque
Copy link
Contributor

jleveque commented Aug 1, 2019

The finally block is a bit of a messy approach, I agree. Instead, you should be able to simply check for None:

        # First, try to load the new platform API
        try:
            import sonic_platform
            self.chassis = sonic_platform.platform.Platform().get_chassis()
            self.eeprom = self.chassis.get_eeprom()
        except Exception as e:
            logger.log_warning("Failed to load platform-specific eeprom from sonic_platform package due to {}".format(repr(e)))

        # If we didn't successfully load the class from the sonic_platform package, try loading the old plugin
        if not self.eeprom:
            try:
                self.eeprom = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
            except Exception as e:
                logger.log_error("Failed to load platform-specific eeprom implementation: %s" % (str(e)), True)

        if not self.eeprom:
            sys.exit(ERR_EEPROMUTIL_LOAD)

Great to know psud should be able to use the same approach. I assumed xcvrd would require a different solution.

@stephenxs
Copy link
Collaborator Author

stephenxs commented Aug 1, 2019 via email

@jleveque
Copy link
Contributor

jleveque commented Aug 1, 2019

Understood. So do you want to make any changes to this PR after all?

@stephenxs
Copy link
Collaborator Author

The finally block is a bit of a messy approach, I agree. Instead, you should be able to simply check for None:

        # First, try to load the new platform API
        try:
            import sonic_platform
            self.chassis = sonic_platform.platform.Platform().get_chassis()
            self.eeprom = self.chassis.get_eeprom()
        except Exception as e:
            logger.log_warning("Failed to load platform-specific eeprom from sonic_platform package due to {}".format(repr(e)))

        # If we didn't successfully load the class from the sonic_platform package, try loading the old plugin
        if not self.eeprom:
            try:
                self.eeprom = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
            except Exception as e:
                logger.log_error("Failed to load platform-specific eeprom implementation: %s" % (str(e)), True)

        if not self.eeprom:
            sys.exit(ERR_EEPROMUTIL_LOAD)

Great to know psud should be able to use the same approach. I assumed xcvrd would require a different solution.

    # First, try to load the new platform API
    try:
        import sonic_platform
        self.chassis = sonic_platform.platform.Platform().get_chassis()
        self.eeprom = self.chassis.get_eeprom()
    except Exception as e:
        logger.log_warning("Failed to load platform-specific eeprom from sonic_platform package due to {}".format(repr(e)))

    # If we didn't successfully load the class from the sonic_platform package, try loading the old plugin
    if not self.eeprom:
        try:
            self.eeprom = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
        except Exception as e:
            logger.log_error("Failed to load platform-specific eeprom implementation: %s" % (str(e)), True)

    if not self.eeprom:
        sys.exit(ERR_EEPROMUTIL_LOAD)

Understood. So do you want to make any changes to this PR after all?

Sure. I'm testing the syseepromd.

@stephenxs
Copy link
Collaborator Author

Understood. So do you want to make any changes to this PR after all?

Hi Joe, syseepromd has been updated. Please review. Thank you.

@jleveque jleveque merged commit 04efe39 into sonic-net:master Aug 6, 2019
jleveque pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Aug 14, 2019
[sonic-platform-common]

[sonic_sfp] Interpret sff 'int' element =0 as valid value (sonic-net/sonic-platform-common#51)
add more error code to get_transceiver_change_event ((sonic-net/sonic-platform-common#50)
[sonic_platform_base] support new-platform-api-based daemons ((sonic-net/sonic-platform-common#48)
sync change to sonic_platform_base/sonic_sfp and create symbol link ((sonic-net/sonic-platform-common#49)
Add parser support for Tx_RxLos,TxFault, PowerControl, ResetStatus in sff8436.py ((sonic-net/sonic-platform-common#45)
readd type_abbrv_name in sonic_sfp/sff8436.py ((sonic-net/sonic-platform-common#44)
[psu_base] get_status_led() returns current state of the status LED ((sonic-net/sonic-platform-common#39)
Fix abbrv name for OSFP ((sonic-net/sonic-platform-common#36)
[sff8436] support "Control Bytes" and "Options" ((sonic-net/sonic-platform-common#38)
sonic_sfp: avoid possible key error in get_physical_to_logical() ((sonic-net/sonic-platform-common#37)

[sonic-platform-daemons]

[xcvrd] Enhance xcvrd to handle new system level event/error (sonic-net/sonic-platform-daemons#39)
[xcvrd] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#38)
[psud] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#37)
[syseepromd] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#36)
Add missing import statemet (sonic-net/sonic-platform-daemons#32)
sonic_xcvrd: Support for DOM Threshold values for EEPROM dump (sonic-net/sonic-platform-daemons#29)
wangshengjun pushed a commit to wangshengjun/sonic-buildimage that referenced this pull request Nov 16, 2020
…ic-net#3333)

[sonic-platform-common]

[sonic_sfp] Interpret sff 'int' element =0 as valid value (sonic-net/sonic-platform-common#51)
add more error code to get_transceiver_change_event ((sonic-net/sonic-platform-common#50)
[sonic_platform_base] support new-platform-api-based daemons ((sonic-net/sonic-platform-common#48)
sync change to sonic_platform_base/sonic_sfp and create symbol link ((sonic-net/sonic-platform-common#49)
Add parser support for Tx_RxLos,TxFault, PowerControl, ResetStatus in sff8436.py ((sonic-net/sonic-platform-common#45)
readd type_abbrv_name in sonic_sfp/sff8436.py ((sonic-net/sonic-platform-common#44)
[psu_base] get_status_led() returns current state of the status LED ((sonic-net/sonic-platform-common#39)
Fix abbrv name for OSFP ((sonic-net/sonic-platform-common#36)
[sff8436] support "Control Bytes" and "Options" ((sonic-net/sonic-platform-common#38)
sonic_sfp: avoid possible key error in get_physical_to_logical() ((sonic-net/sonic-platform-common#37)

[sonic-platform-daemons]

[xcvrd] Enhance xcvrd to handle new system level event/error (sonic-net/sonic-platform-daemons#39)
[xcvrd] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#38)
[psud] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#37)
[syseepromd] Support both new platform API and old platform plugins (sonic-net/sonic-platform-daemons#36)
Add missing import statemet (sonic-net/sonic-platform-daemons#32)
sonic_xcvrd: Support for DOM Threshold values for EEPROM dump (sonic-net/sonic-platform-daemons#29)
vdahiya12 pushed a commit to vdahiya12/sonic-platform-daemons that referenced this pull request Apr 4, 2022
There was a problem with the abbreviated type name fetching if the xcvr
was OSFP. This commit fixes the issue.
@stephenxs stephenxs deleted the npapi-based-daemon-eeprom branch April 12, 2022 01:59
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants