def test_power_on_not_installed(self, zboot, ipmi):
     instance = ZerobootIpmiHost(name="test", data=self._valid_data)
     with pytest.raises(
             StateCheckError,
             message=
             "power_on should be not be able to be called before install"):
         instance.power_on()
    def test_power_on(self, zboot, ipmi):
        instance = ZerobootIpmiHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')

        instance.power_on()
        ipmi.get().power_on.assert_called_with()

        # check if instance power state True
        assert instance.data['powerState']
    def test_monitor_power_off(self):
        instance = ZerobootIpmiHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')
        instance.power_on = MagicMock()
        instance.power_off = MagicMock()
        instance.power_status = MagicMock(return_value=True)
        instance.data['powerState'] = False

        instance.monitor()

        # power state mismatched, power_off should have been called
        instance.power_on.assert_not_called()
        instance.power_off.assert_called_with()
    def test_monitor_matching_state(self):
        instance = ZerobootIpmiHost(name="test", data=self._valid_data)
        instance.state.set('actions', 'install', 'ok')
        instance.power_on = MagicMock()
        instance.power_off = MagicMock()
        instance.power_status = MagicMock(return_value=True)
        instance.data['powerState'] = True

        instance.monitor()

        # no power calls should be make
        instance.power_on.assert_not_called()
        instance.power_off.assert_not_called()