def test_power_budget(self):
        chassis = MockChassis()
        psu1 = MockPsu("PSU 1", 0, True, True)
        psu1_power = 510.0
        psu1.set_maximum_supplied_power(psu1_power)
        chassis._psu_list.append(psu1)

        fan_drawer1 = MockFanDrawer("FanDrawer 1", 0, True, True)
        fan_drawer1_power = 510.0
        fan_drawer1.set_maximum_consumed_power(fan_drawer1_power)
        chassis._fan_drawer_list.append(fan_drawer1)

        module1 = MockModule("Module 1", 0, True, True)
        module1_power = 700.0
        module1.set_maximum_consumed_power(module1_power)
        chassis._module_list.append(module1)

        state_db = daemon_base.db_connect("STATE_DB")
        chassis_tbl = mock_swsscommon.Table(state_db, CHASSIS_INFO_TABLE)
        chassis_info = psud.PsuChassisInfo(SYSLOG_IDENTIFIER, chassis)
        chassis_info.first_run = False

        # Check case where supplied_power < consumed_power
        chassis_info.run_power_budget(chassis_tbl)
        chassis_info.update_master_status()
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))

        assert float(fvs[CHASSIS_INFO_TOTAL_POWER_SUPPLIED_FIELD]) < float(
            fvs[CHASSIS_INFO_TOTAL_POWER_CONSUMED_FIELD])
        assert chassis_info.master_status_good == False

        # We cannot call get_status_master_led() on our mocked PSUs, because
        # they are not instantiated from the same Psu class loaded in psud,
        # so we must call it on the class there.
        assert psud.Psu.get_status_master_led() == MockPsu.STATUS_LED_COLOR_RED

        # Add a PSU
        psu2 = MockPsu("PSU 2", 1, True, True)
        psu2_power = 800.0
        psu2.set_maximum_supplied_power(psu2_power)
        chassis._psu_list.append(psu2)

        # Check case where supplied_power > consumed_power
        chassis_info.run_power_budget(chassis_tbl)
        chassis_info.update_master_status()
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))

        assert float(fvs[CHASSIS_INFO_TOTAL_POWER_SUPPLIED_FIELD]) > float(
            fvs[CHASSIS_INFO_TOTAL_POWER_CONSUMED_FIELD])
        assert chassis_info.master_status_good == True

        # We cannot call get_status_master_led() on our mocked PSUs, because
        # they are not instantiated from the same Psu class loaded in psud,
        # so we must call it on the class there.
        assert psud.Psu.get_status_master_led(
        ) == MockPsu.STATUS_LED_COLOR_GREEN
Exemplo n.º 2
0
    def test_supplied_power(self):
        chassis = MockChassis()
        psu1 = MockPsu("PSU 1", 0, True, True)
        psu1_power = 510.0
        psu1.set_maximum_supplied_power(psu1_power)
        chassis._psu_list.append(psu1)

        psu2 = MockPsu("PSU 2", 1, True, True)
        psu2_power = 800.0
        psu2.set_maximum_supplied_power(psu2_power)
        chassis._psu_list.append(psu2)

        psu3 = MockPsu("PSU 3", 2, True, True)
        psu3_power = 350.0
        psu3.set_maximum_supplied_power(psu3_power)
        chassis._psu_list.append(psu3)

        total_power = psu1_power + psu2_power + psu3_power
        state_db = daemon_base.db_connect("STATE_DB")
        chassis_tbl = mock_swsscommon.Table(state_db, CHASSIS_INFO_TABLE)
        chassis_info = psud.PsuChassisInfo(SYSLOG_IDENTIFIER, chassis)
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))

        # Check if supplied power is recorded in DB
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_SUPPLIED_FIELD])

        # Check if psu1 is not present
        psu1.set_presence(False)
        total_power = psu2_power + psu3_power
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_SUPPLIED_FIELD])

        # Check if psu2 status is NOT_OK
        psu2.set_status(False)
        total_power = psu3_power
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_SUPPLIED_FIELD])
Exemplo n.º 3
0
    def test_consumed_power(self):
        chassis = MockChassis()
        fan_drawer1 = MockFanDrawer("FanDrawer 1", 0, True, True)
        fan_drawer1_power = 510.0
        fan_drawer1.set_maximum_consumed_power(fan_drawer1_power)
        chassis._fan_drawer_list.append(fan_drawer1)

        module1 = MockModule("Module 1", 0, True, True)
        module1_power = 700.0
        module1.set_maximum_consumed_power(module1_power)
        chassis._module_list.append(module1)

        total_power = fan_drawer1_power + module1_power
        state_db = daemon_base.db_connect("STATE_DB")
        chassis_tbl = mock_swsscommon.Table(state_db, CHASSIS_INFO_TABLE)
        chassis_info = psud.PsuChassisInfo(SYSLOG_IDENTIFIER, chassis)
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))

        # Check if supplied power is recorded in DB
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_CONSUMED_FIELD])

        # Check if fan_drawer1 present
        fan_drawer1.set_presence(False)
        total_power = module1_power
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_CONSUMED_FIELD])

        # Check if module1 present
        fan_drawer1.set_presence(True)
        module1.set_presence(False)
        total_power = fan_drawer1_power
        chassis_info.run_power_budget(chassis_tbl)
        fvs = chassis_tbl.get(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1))
        assert total_power == float(
            fvs[CHASSIS_INFO_TOTAL_POWER_CONSUMED_FIELD])