Esempio n. 1
0
 def test_switch_on(self, mocker):
     mocker.patch("batsim_py.simulator.SetResourceStateBatsimRequest")
     mocker.patch.object(batsim_py.resources.Host, '_switch_on')
     s = SimulatorHandler()
     s.start("p", "w")
     s.switch_on([1])
     ps = s.platform.get_host(1).get_default_pstate()
     batsim_py.resources.Host._switch_on.assert_called_once()
     simulator.SetResourceStateBatsimRequest.assert_called_once_with(  # type: ignore
         0, [1], ps.id)
Esempio n. 2
0
    def test_switch_on_must_dispatch_host_event(self, mocker):
        def foo(h: Host):
            self.__nb_called += 1

        self.__nb_called = 0
        mocker.patch.object(batsim_py.resources.Host, '_switch_on')
        s = SimulatorHandler()
        s.start("p", "w")
        s.subscribe(HostEvent.STATE_CHANGED, foo)
        s.switch_on([0, 1])
        assert self.__nb_called == 2
Esempio n. 3
0
    def test_on_batsim_host_ps_changed_must_set_on_and_dispatch_event(self, mocker):
        def foo_h(h: Host):
            self.__h_called, self.__h_id = True, h.id
        self.__j_id = self.__h_id = -1
        s = SimulatorHandler()
        s.start("p", "w")

        s.platform.get_host(0)._switch_off()
        s.platform.get_host(0)._set_off()
        s.switch_on([0])
        assert s.platform.get_host(0).is_switching_on

        # Setup
        p_id = s.platform.get_host(0).get_default_pstate().id
        e = BatsimEventAPI.get_resource_state_changed(150, [0], p_id)
        e = ResourcePowerStateChangedBatsimEvent(150, e['data'])
        msg = BatsimMessage(150, [e])
        mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg)
        s.subscribe(HostEvent.STATE_CHANGED, foo_h)
        s.proceed_time()

        assert s.platform.get_host(0).is_idle
        assert self.__h_called and self.__h_id == 0
Esempio n. 4
0
 def test_switch_on_not_found_must_raise(self):
     s = SimulatorHandler()
     s.start("p", "w")
     with pytest.raises(LookupError) as excinfo:
         s.switch_on([30])
     assert 'resources' in str(excinfo.value)
Esempio n. 5
0
 def test_switch_on_not_running_must_raise(self):
     s = SimulatorHandler()
     with pytest.raises(RuntimeError) as excinfo:
         s.switch_on([0])
     assert 'running' in str(excinfo.value)