Skip to content

platform API led related test should check the return value of set_status_led #2525

@Junchao-Mellanox

Description

@Junchao-Mellanox

Description

In current platform API test, it usually set led to different color and use get_status_led to verify that whether the operation is success. Here is an example in test_psu.py:

    def test_led(self, duthost, localhost, platform_api_conn):
        ''' PSU status led test '''
        LED_COLOR_LIST = [
            STATUS_LED_COLOR_GREEN,
            STATUS_LED_COLOR_AMBER,
            STATUS_LED_COLOR_RED,
            STATUS_LED_COLOR_OFF
        ]

        for psu_id in range(self.num_psus):
            for color in LED_COLOR_LIST:
                result = psu.set_status_led(platform_api_conn, psu_id, color)
                if self.expect(result is not None, "Failed to perform set_status_led of PSU {}".format(psu_id)):
                    self.expect(result is True, "Failed to set status_led of PSU {} to {}".format(psu_id, color))

                color_actual = psu.get_status_led(platform_api_conn, psu_id)
                if self.expect(color_actual is not None, "Failed to retrieve status_led of PSU {}".format(psu_id)):
                    if self.expect(isinstance(color_actual, STRING_TYPE), "PSU {} status LED color appears incorrect".format(psu_id)):
                        self.expect(color == color_actual, "Status LED color incorrect (expected: {}, actual: {}) from PSU {}".format(color, color_actual, psu_id))
        self.assert_expectations()

However, in sonic_platform_common, the API set_status_led is designed to allow a boolean return value:

    def set_status_led(self, color):
        """
        Sets the state of the PSU status LED

        Args:
            color: A string representing the color with which to set the
                   PSU status LED

        Returns:
            bool: True if status LED state is set successfully, False if not
        """
        raise NotImplementedError

And once the color is not supported, this API can return False. So I suppose we should allow the API return False in the test case in case the color is not supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions