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

Fix SAI adapter exception due to POE PSE attribute conflicting with variables in sai_adapter.py. #2011

Merged
merged 3 commits into from
May 10, 2024

Conversation

r12f
Copy link
Contributor

@r12f r12f commented May 10, 2024

Problem

After the recent POE PSE API update, the SAI adapter python script will fail on launch with the exception below:

byte-compiling /dash/dash-pipeline/SAI/saithrift/../rpc/usr/local/lib/python3.10/site-packages/sai_thrift/sai_adapter.py to sai_adapter.cpython-310.pyc
  File "/dash/dash-pipeline/SAI/saithrift/../rpc/usr/local/lib/python3.10/site-packages/sai_thrift/sai_adapter.py", line 37000
    global status
    ^^^^^^^^^^^^^
SyntaxError: name 'status' is parameter and global

The reason is because the POE PSE API has a attribute with name STATUS:

/**
 * @brief POE PSE attributes
 */
typedef enum _sai_poe_pse_attr_t
{
    ...

    /**
     * @brief Status of the PSE
     *
     * @type sai_poe_pse_status_t
     * @flags READ_ONLY
     */
    SAI_POE_PSE_ATTR_STATUS,

    ...
} sai_poe_pse_attr_t;

This causes the status parameter being generated in the SAI thrift adapter, and conflicting with the variable global status:

image

image

Fix

Since it is not ideal to change the API name, as it might break any code rely on it. This commit updates the template for generating the adapter code with 2 changes:

  1. Rename the status global variable into sai_status.
  2. Add a fallback __getattr__ function (called after no attribute is found), which ensures any existing code that gets the status variable will not break, such as adapter.status.

@lguohan lguohan merged commit c93e463 into opencomputeproject:master May 10, 2024
3 checks passed
@r12f r12f deleted the user/r12f/fix-thrift branch May 10, 2024 20:53
erohsik pushed a commit to erohsik/SAI that referenced this pull request Sep 17, 2024
…ariables in sai_adapter.py. (opencomputeproject#2011)

After the recent POE PSE API update, the SAI adapter python script will fail on launch with the exception below:

byte-compiling /dash/dash-pipeline/SAI/saithrift/../rpc/usr/local/lib/python3.10/site-packages/sai_thrift/sai_adapter.py to sai_adapter.cpython-310.pyc
  File "/dash/dash-pipeline/SAI/saithrift/../rpc/usr/local/lib/python3.10/site-packages/sai_thrift/sai_adapter.py", line 37000
    global status
    ^^^^^^^^^^^^^
SyntaxError: name 'status' is parameter and global
The reason is because the POE PSE API has a attribute with name STATUS:

/**
 * @brief POE PSE attributes
 */
typedef enum _sai_poe_pse_attr_t
{
    ...

    /**
     * @brief Status of the PSE
     *
     * @type sai_poe_pse_status_t
     * @flags READ_ONLY
     */
    SAI_POE_PSE_ATTR_STATUS,

    ...
} sai_poe_pse_attr_t;
This causes the status parameter being generated in the SAI thrift adapter, and conflicting with the variable global status:

Fix

Since it is not ideal to change the API name, as it might break any code rely on it. This commit updates the template for generating the adapter code with 2 changes:

Rename the status global variable into sai_status.
Add a fallback __getattr__ function (called after no attribute is found), which ensures any existing code that gets the status variable will not break, such as adapter.status.


Signed-off-by: r12f <[email protected]>
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.

3 participants