Beispiel #1
0
    def test_fans(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
                  platform_api_conn):
        ''' PSU fan test '''
        for psu_id in range(self.num_psus):
            try:
                num_fans = int(psu.get_num_fans(platform_api_conn, psu_id))
            except:
                pytest.fail("num_fans is not an integer!")

            fan_list = psu.get_all_fans(platform_api_conn, psu_id)
            if self.expect(fan_list is not None,
                           "Failed to retrieve fans of PSU {}".format(psu_id)):
                self.expect(
                    isinstance(fan_list, list) and len(fan_list) == num_fans,
                    "Fans of PSU {} appear to be incorrect".format(psu_id))

            for i in range(num_fans):
                fan = psu.get_fan(platform_api_conn, psu_id, i)
                if self.expect(
                        fan is not None,
                        "Failed to retrieve fan {} of PSU {}".format(
                            i, psu_id)):
                    self.expect(
                        fan and fan == fan_list[i],
                        "Fan {} of PSU {} is incorrect".format(i, psu_id))
        self.assert_expectations()
Beispiel #2
0
    def test_get_speed(self, duthosts, enum_rand_one_per_hwsku_hostname,
                       localhost, platform_api_conn):
        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                # Ensure the fan speed is sane
                speed_controllable = self.get_fan_facts(
                    duthost, j, i, True, "speed", "controllable")
                if not speed_controllable:
                    logger.info(
                        "test_get_speed: Skipping PSU {} fan {} (speed not controllable)"
                        .format(j, i))
                    continue
                speed = psu_fan.get_speed(platform_api_conn, j, i)
                if self.expect(
                        speed is not None,
                        "Unable to retrieve psu {} fan {} speed".format(j, i)):
                    if self.expect(
                            isinstance(speed, int),
                            "psu {} fan {} speed appears incorrect".format(
                                j, i)):
                        self.expect(
                            speed > 0 and speed <= 100,
                            "psu {} fan {} speed {} reading is not within range"
                            .format(j, i, speed))

        self.assert_expectations()
Beispiel #3
0
    def test_get_fans_speed_tolerance(self, duthosts,
                                      enum_rand_one_per_hwsku_hostname,
                                      localhost, platform_api_conn):
        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                speed_controllable = self.get_fan_facts(
                    duthost, j, i, True, "speed", "controllable")
                if not speed_controllable:
                    logger.info(
                        "test_get_fans_speed_tolerance: Skipping PSU {} fan {} (speed not controllable)"
                        .format(j, i))
                    continue
                speed_tolerance = psu_fan.get_speed_tolerance(
                    platform_api_conn, j, i)
                if self.expect(
                        speed_tolerance is not None,
                        "Unable to retrieve psu {} fan {} speed tolerance".
                        format(j, i)):
                    if self.expect(
                            isinstance(speed_tolerance, int),
                            "psu {} fan {} speed tolerance appears incorrect".
                            format(j, i)):
                        self.expect(
                            speed_tolerance > 0 and speed_tolerance <= 100,
                            "psu {} fan {} speed tolerance {} reading does not make sense"
                            .format(j, i, speed_tolerance))

        self.assert_expectations()
    def test_get_fans_target_speed(self, duthosts,
                                   enum_rand_one_per_hwsku_hostname, localhost,
                                   platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):

                speed_target_val = 25
                speed_set = psu_fan.set_speed(platform_api_conn, j, i,
                                              speed_target_val)
                target_speed = psu_fan.get_target_speed(
                    platform_api_conn, j, i)
                if self.expect(
                        target_speed is not None,
                        "Unable to retrieve psu {} fan {} target speed".format(
                            j, i)):
                    if self.expect(
                            isinstance(target_speed, int),
                            "psu {} fan {} target speed appears incorrect".
                            format(j, i)):
                        self.expect(
                            target_speed == speed_target_val,
                            "psu {} fan {} target speed setting is not correct, speed_target_val {} target_speed = {}"
                            .format(j, i, speed_target_val, target_speed))

        self.assert_expectations()
Beispiel #5
0
    def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname,
                          localhost, platform_api_conn):
        LED_COLOR_LIST = [
            "off",
            "red",
            "amber",
            "green",
        ]
        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        psus_skipped = 0

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)
            fans_skipped = 0

            for i in range(num_fans):
                led_controllable = self.get_fan_facts(duthost, j, i, True,
                                                      "status_led",
                                                      "controllable")
                if not led_controllable:
                    logger.info(
                        "test_set_fans_led: Skipping PSU {} fan {} (LED not controllable)"
                        .format(j, i))
                    fans_skipped += 1
                    continue

                LED_COLOR_LIST = self.get_fan_facts(duthost, j, i,
                                                    LED_COLOR_LIST,
                                                    "status_led", "colors")
                for color in LED_COLOR_LIST:

                    result = psu_fan.set_status_led(platform_api_conn, j, i,
                                                    color)
                    if self.expect(result is not None,
                                   "Failed to perform set_status_led"):
                        self.expect(
                            result is True,
                            "Failed to set status_led for psu {} fan {} to {}".
                            format(j, i, color))

                    color_actual = psu_fan.get_status_led(
                        platform_api_conn, j, i)

                    if self.expect(color_actual is not None,
                                   "Failed to retrieve status_led"):
                        if self.expect(isinstance(color_actual, STRING_TYPE),
                                       "Status LED color appears incorrect"):
                            self.expect(
                                color == color_actual,
                                "Status LED color incorrect (expected: {}, actual: {} for fan {})"
                                .format(color, color_actual, i))

            if num_fans != 0 and fans_skipped == num_fans:
                psus_skipped += 1

        if psus_skipped == self.num_psus:
            pytest.skip("skipped as all PSU fans' LED is not controllable")

        self.assert_expectations()
Beispiel #6
0
    def test_get_fans_target_speed(self, duthosts,
                                   enum_rand_one_per_hwsku_hostname, localhost,
                                   platform_api_conn):

        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        psus_skipped = 0

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)
            fans_skipped = 0

            for i in range(num_fans):
                speed_target_val = 25
                speed_controllable = self.get_fan_facts(
                    duthost, j, i, True, "speed", "controllable")
                if not speed_controllable:
                    logger.info(
                        "test_get_fans_target_speed: Skipping PSU {} fan {} (speed not controllable)"
                        .format(j, i))
                    fans_skipped += 1
                    continue

                speed_minimum = self.get_fan_facts(duthost, j, i, 25, "speed",
                                                   "minimum")
                speed_maximum = self.get_fan_facts(duthost, j, i, 100, "speed",
                                                   "maximum")
                if speed_minimum > speed_target_val or speed_maximum < speed_target_val:
                    speed_target_val = random.randint(speed_minimum,
                                                      speed_maximum)

                speed_set = psu_fan.set_speed(platform_api_conn, j, i,
                                              speed_target_val)
                target_speed = psu_fan.get_target_speed(
                    platform_api_conn, j, i)
                if self.expect(
                        target_speed is not None,
                        "Unable to retrieve psu {} fan {} target speed".format(
                            j, i)):
                    if self.expect(
                            isinstance(target_speed, int),
                            "psu {} fan {} target speed appears incorrect".
                            format(j, i)):
                        self.expect(
                            target_speed == speed_target_val,
                            "psu {} fan {} target speed setting is not correct, speed_target_val {} target_speed = {}"
                            .format(j, i, speed_target_val, target_speed))

            if num_fans != 0 and fans_skipped == num_fans:
                psus_skipped += 1

        if psus_skipped == self.num_psus:
            pytest.skip("skipped as all PSU fans' speed is not controllable")

        self.assert_expectations()
Beispiel #7
0
    def test_set_fans_speed(self, duthosts, enum_rand_one_per_hwsku_hostname,
                            localhost, platform_api_conn):

        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        psus_skipped = 0

        for j in range(self.num_psus):
            target_speed = random.randint(1, 100)
            num_fans = psu.get_num_fans(platform_api_conn, j)
            fans_skipped = 0

            for i in range(num_fans):
                speed_controllable = self.get_fan_facts(
                    duthost, j, i, True, "speed", "controllable")
                if not speed_controllable:
                    logger.info(
                        "test_set_fans_speed: Skipping PSU {} fan {} (speed not controllable)"
                        .format(j, i))
                    fans_skipped += 1
                    continue

                speed_minimum = self.get_fan_facts(duthost, j, i, 1, "speed",
                                                   "minimum")
                speed_maximum = self.get_fan_facts(duthost, j, i, 100, "speed",
                                                   "maximum")
                if speed_minimum > target_speed or speed_maximum < target_speed:
                    target_speed = random.randint(speed_minimum, speed_maximum)

                speed = psu_fan.get_speed(platform_api_conn, j, i)
                speed_tol = psu_fan.get_speed_tolerance(
                    platform_api_conn, j, i)

                speed_set = psu_fan.set_speed(platform_api_conn, j, i,
                                              target_speed)
                time.sleep(5)

                act_speed = psu_fan.get_speed(platform_api_conn, j, i)
                self.expect(
                    abs(act_speed - target_speed) <= speed_tol,
                    "psu {} fan {} speed change from {} to {} is not within tolerance, actual speed {}"
                    .format(j, i, speed, target_speed, act_speed))

            if num_fans != 0 and fans_skipped == num_fans:
                psus_skipped += 1

        if psus_skipped == self.num_psus:
            pytest.skip("skipped as all PSU fans' speed is not controllable")

        self.assert_expectations()
Beispiel #8
0
 def test_get_position_in_parent(self, platform_api_conn):
     for j in range(self.num_psus):
         num_fans = psu.get_num_fans(platform_api_conn, j)
         for i in range(num_fans):
             position = psu_fan.get_position_in_parent(
                 platform_api_conn, j, i)
             if self.expect(
                     position is not None,
                     "Failed to perform get_position_in_parent for PSU {} fan {}"
                     .format(j, i)):
                 self.expect(
                     isinstance(position, int),
                     "Position value must be an integer value for PSU {} fan {}"
                     .format(j, i))
     self.assert_expectations()
Beispiel #9
0
    def test_is_replaceable(self, platform_api_conn):
        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)
            for i in range(num_fans):
                replaceable = psu_fan.is_replaceable(platform_api_conn, j, i)
                if self.expect(
                        replaceable is not None,
                        "Failed to perform is_replaceable for PSU {} fan {}".
                        format(j, i)):
                    self.expect(
                        isinstance(replaceable, bool),
                        "Replaceable value must be a bool value for PSU {} fan {}"
                        .format(j, i))

        self.assert_expectations()
Beispiel #10
0
    def test_get_name(self, duthosts, enum_rand_one_per_hwsku_hostname,
                      localhost, platform_api_conn):
        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                name = psu_fan.get_name(platform_api_conn, j, i)

                if self.expect(
                        name is not None,
                        "Unable to retrieve psu {} fan {} name".format(j, i)):
                    self.expect(
                        isinstance(name, STRING_TYPE),
                        "psu {} fan {} name appears incorrect".format(j, i))
                    self.expect(
                        duthost._facts.get("platform") is not None,
                        "Unable to retrieve platform name")
                    #
                    # Check whether platform.json file exists for this specific platform. If yes compare names.
                    # If not, skip comparison.
                    #
                    platform_file_path = os.path.join(
                        "/usr/share/sonic/device",
                        duthost._facts.get("platform"), "platform.json")
                    platform_file_check = {}
                    try:
                        #
                        # Check if the JSON file exists in the specific path. Return 0 if it DOES exist.
                        # The command function throws exception if rc is non-zero, so handle it.
                        #
                        platform_file_check = duthost.command(
                            "[ -f {} ]".format(platform_file_path))
                    except:
                        # The JSON file does not exist, so set rc to 1.
                        platform_file_check['rc'] = 1
                    if platform_file_check.get('rc') == 0:
                        logging.info(
                            "{} has a platform.json file. Running comparison with platform facts."
                            .format(duthost._facts.get("platform")))
                        self.compare_value_with_platform_facts(
                            duthost, 'name', name, j, i)
                    else:
                        logging.info(
                            "{} does not have a platform.json file. Skipping comparison with platform facts."
                            .format(duthost._facts.get("platform")))

        self.assert_expectations()
    def test_get_model(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                model = psu_fan.get_model(platform_api_conn, j, i)

                if self.expect(
                        model is not None,
                        "Unable to retrieve psu {} fan {} model".format(j, i)):
                    self.expect(
                        isinstance(model, STRING_TYPE),
                        "psu {} fan {} model appears incorrect".format(j, i))

        self.assert_expectations()
    def test_get_status(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                status = psu_fan.get_status(platform_api_conn, j, i)

                if self.expect(
                        status is not None,
                        "Unable to retrieve psu {} fan {} status".format(j,
                                                                         i)):
                    self.expect(
                        isinstance(status, bool),
                        "psu {} fan {} status appears incorrect".format(j, i))

        self.assert_expectations()
Beispiel #13
0
    def test_get_name(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                name = psu_fan.get_name(platform_api_conn, j, i)

                if self.expect(
                        name is not None,
                        "Unable to retrieve psu {} fan {} name".format(j, i)):
                    self.expect(
                        isinstance(name, STRING_TYPE),
                        "psu {} fan {} name appears incorrect".format(j, i))
                    self.compare_value_with_platform_facts('name', name, j, i)

        self.assert_expectations()
Beispiel #14
0
    def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname,
                        localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                serial = psu_fan.get_serial(platform_api_conn, j, i)

                if self.expect(
                        serial is not None,
                        "Unable to retrieve psu {} fan {} serial number".
                        format(j, i)):
                    self.expect(
                        isinstance(serial, STRING_TYPE),
                        "psu {} fan {}serial number appears incorrect".format(
                            j, i))

        self.assert_expectations()
    def test_get_speed(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                # Ensure the fan speed is sane
                speed = psu_fan.get_speed(platform_api_conn, j, i)
                if self.expect(
                        speed is not None,
                        "Unable to retrieve psu {} fan {} speed".format(j, i)):
                    if self.expect(
                            isinstance(speed, int),
                            "psu {} fan {} speed appears incorrect".format(
                                j, i)):
                        self.expect(
                            speed > 0 and speed <= 100,
                            "psu {} fan {} speed {} reading is not within range"
                            .format(j, i, speed))

        self.assert_expectations()
    def test_get_presence(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                name = psu_fan.get_name(platform_api_conn, j, i)

                presence = psu_fan.get_presence(platform_api_conn, j, i)

                if self.expect(
                        presence is not None,
                        "Unable to retrieve psu {} fan {} presence".format(
                            j, i)):
                    if self.expect(
                            isinstance(presence, bool),
                            "psu {} fan {} presence appears incorrect".format(
                                j, i)):
                        self.expect(presence is True,
                                    "Fan {} is not present".format(j, i))

        self.assert_expectations()
    def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname,
                          localhost, platform_api_conn):
        LED_COLOR_LIST = [
            "off",
            "red",
            "amber",
            "green",
        ]

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):

                for color in LED_COLOR_LIST:

                    result = psu_fan.set_status_led(platform_api_conn, j, i,
                                                    color)
                    if self.expect(result is not None,
                                   "Failed to perform set_status_led"):
                        self.expect(
                            result is True,
                            "Failed to set status_led for psu {} fan {} to {}".
                            format(j, i, color))

                    color_actual = psu_fan.get_status_led(
                        platform_api_conn, j, i)

                    if self.expect(color_actual is not None,
                                   "Failed to retrieve status_led"):
                        if self.expect(isinstance(color_actual, STRING_TYPE),
                                       "Status LED color appears incorrect"):
                            self.expect(
                                color == color_actual,
                                "Status LED color incorrect (expected: {}, actual: {} for fan {})"
                                .format(color, color_actual, i))

        self.assert_expectations()
    def test_get_direction(self, duthost, localhost, platform_api_conn):
        # Ensure the fan speed is sane
        FAN_DIRECTION_LIST = [
            "intake",
            "exhaust",
            "N/A",
        ]

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                direction = psu_fan.get_direction(platform_api_conn, j, i)
                if self.expect(
                        direction is not None,
                        "Unable to retrieve psu {} fan {} direction".format(
                            j, i)):
                    self.expect(
                        direction in FAN_DIRECTION_LIST,
                        "psu {} fan {} direction is not one of predefined directions"
                        .format(j, i))

        self.assert_expectations()
    def test_set_fans_speed(self, duthost, localhost, platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            target_speed = random.randint(1, 100)

            for i in range(num_fans):
                speed = psu_fan.get_speed(platform_api_conn, j, i)
                speed_tol = psu_fan.get_speed_tolerance(
                    platform_api_conn, j, i)

                speed_set = psu_fan.set_speed(platform_api_conn, j, i,
                                              target_speed)
                time.sleep(5)

                act_speed = psu_fan.get_speed(platform_api_conn, j, i)
                self.expect(
                    abs(act_speed - target_speed) <= speed_tol,
                    "psu {} fan {} speed change from {} to {} is not within tolerance, actual speed {}"
                    .format(j, i, speed, target_speed, act_speed))

        self.assert_expectations()
    def test_get_fans_speed_tolerance(self, duthost, localhost,
                                      platform_api_conn):

        for j in range(self.num_psus):
            num_fans = psu.get_num_fans(platform_api_conn, j)

            for i in range(num_fans):
                speed_tolerance = psu_fan.get_speed_tolerance(
                    platform_api_conn, j, i)
                if self.expect(
                        speed_tolerance is not None,
                        "Unable to retrieve psu {} fan {} speed tolerance".
                        format(j, i)):
                    if self.expect(
                            isinstance(speed_tolerance, int),
                            "psu {} fan {} speed tolerance appears incorrect".
                            format(j, i)):
                        self.expect(
                            speed_tolerance > 0 and speed_tolerance <= 100,
                            "psu {} fan {} speed tolerance {} reading does not make sense"
                            .format(j, i, speed_tolerance))

        self.assert_expectations()