def test_get_not_allocated_hosts(self):
        h1 = Host(0, "n")
        h2 = Host(1, "n")
        p = Platform([h1, h2])
        h1._allocate("j1")

        assert p.get_not_allocated_hosts() == [h2]
    def test_get_not_found_must_raise(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])
        with pytest.raises(LookupError) as excinfo:
            p.get(2)

        assert "no resources" in str(excinfo.value)
    def test_get_storage_with_host_id_must_raise(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        with pytest.raises(LookupError) as excinfo:
            p.get_storage(0)

        assert "storage" in str(excinfo.value)
 def test_state(self):
     p1 = PowerState(0, PowerStateType.SLEEP, 10, 10)
     p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     p3 = PowerState(2, PowerStateType.COMPUTATION, 15, 150)
     p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50)
     p5 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75)
     h1 = Host(0, "n", pstates=[p1, p3, p2, p4, p5])
     h2 = Host(1, "n")
     p = Platform([h1, h2])
     h1._switch_off()
     assert p.state == [HostState.SWITCHING_OFF, HostState.IDLE]
Beispiel #5
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
    def test_get_storage_by_id(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        assert p.get_storage(1) == s1
    def test_get_with_host(self):
        h1 = Host(0, "n")
        s1 = Storage(1, "n")
        p = Platform([h1, s1])

        assert p.get(0) == h1
 def test_power_when_pstates_defined(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 15, 100)
     p2 = PowerState(1, PowerStateType.COMPUTATION, 50, 100)
     res = [Host(0, "n", pstates=[p1]), Host(1, "n", pstates=[p2])]
     p = Platform(res)
     assert p.power == 15 + 50
 def test_power_when_pstates_not_defined(self):
     res = [Host(0, "n"), Host(1, "n")]
     p = Platform(res)
     assert p.power == 0
 def test_storages(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert len(list(p.storages)) == 1
 def test_size(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert p.size == len(res)
 def test_invalid_res_id_must_raise(self):
     with pytest.raises(SystemError) as excinfo:
         Platform([Host(1, "n"), Host(2, "n")])
     assert "resources id" in str(excinfo.value)
 def test_empty_res_must_raise(self):
     with pytest.raises(ValueError) as excinfo:
         Platform([])
     assert "one resource" in str(excinfo.value)
 def test_valid_instance(self):
     res = [Host(0, "n"), Host(1, "n"), Storage(2, "n")]
     p = Platform(res)
     assert all(h.id == i for i, h in enumerate(p.resources))