Exemple #1
0
 def monitor(self, mock_simulator):
     monitor = ConsumedEnergyMonitor(mock_simulator)
     mock_simulator.current_time = 0
     watt_on = [(100, 200), (200, 300)]
     pstates = BatsimPlatformAPI.get_resource_properties(watt_on=watt_on)
     pstates = Converters.json_to_power_states(pstates)
     hosts = [
         Host(0, "0", pstates=pstates),
         Host(1, "1", pstates=pstates),
     ]
     mock_simulator.platform = Platform(hosts)
     monitor.on_simulation_begins(mock_simulator)
     return monitor
Exemple #2
0
    def test_json_to_power_states(self):
        prop = BatsimPlatformAPI.get_resource_properties(
            watt_off=10,
            watt_switch_off=50,
            watt_switch_on=75,
            watt_on=[(10, 100)],
        )
        ps = Converters.json_to_power_states(prop)
        assert len(ps) == 4

        sleep_ps = next(p for p in ps if p.type == PowerStateType.SLEEP)
        s_off_ps = next(p for p in ps
                        if p.type == PowerStateType.SWITCHING_OFF)
        s_on_ps = next(p for p in ps if p.type == PowerStateType.SWITCHING_ON)
        on_ps = next(p for p in ps if p.type == PowerStateType.COMPUTATION)

        assert sleep_ps.watt_full == 10 and sleep_ps.id == 0
        assert s_off_ps.watt_full == 50 and s_off_ps.id == 1
        assert s_on_ps.watt_full == 75 and s_on_ps.id == 2
        assert on_ps.watt_full == 100 and on_ps.watt_idle == 10 and on_ps.id == 3
Exemple #3
0
 def test_json_to_power_states_without_property_must_raise(self):
     prop = BatsimPlatformAPI.get_resource_properties()
     del prop["watt_per_state"]
     with pytest.raises(RuntimeError):
         Converters.json_to_power_states(prop)