def test_uninstall(self):
        # install
        reservation = ZerobootReservation(name="test", data=self._valid_data)
        reservation.api = MagicMock()
        reserved_host = "host1"
        mock_pool1 = MagicMock()
        mock_pool1.schedule_action().wait().result = reserved_host
        reservation.api.services.get = MagicMock(return_value=mock_pool1)
        reservation.install()

        # should not fail as service was installed
        reservation.state.check("actions", "install", "ok")

        # uninstall
        reservation.uninstall()

        # check power off called
        reservation.api.services.get().schedule_action.assert_called_with("power_off")

        # check 'hostInstance' cleared
        if reservation.data.get('hostInstance'):
            pytest.fail("'hostInstance' should be cleared after uninstall")

        # check action install state
        with pytest.raises(StateCheckError, message="reservation service should now be uninstalled"):
            reservation.state.check("actions", "install", "ok")
    def test_configure_ipxe_boot_installed(self):
        reservation = ZerobootReservation(name="test", data=self._valid_data)
        reservation.api = MagicMock()

        with pytest.raises(StateCheckError, message="configure_ipxe_boot should failed as the service in not installed"):
            reservation.configure_ipxe_boot("some.boot.url")

        reservation.install()

        reservation.configure_ipxe_boot("some.boot.url")
    def test_monitor_installed(self):
        reservation = ZerobootReservation(name="test", data=self._valid_data)
        reservation.api = MagicMock()

        with pytest.raises(StateCheckError, message="monitor should failed as the service in not installed"):
            reservation.monitor()

        reservation.install()

        reservation.monitor()
    def test_install(self):
        reservation = ZerobootReservation(name="test", data=self._valid_data)
        reservation.api = MagicMock()
        reserved_host = "host1"
        mock_pool1 = MagicMock()
        mock_pool1.schedule_action().wait().result = reserved_host
        reservation.api.services.get = MagicMock(return_value=mock_pool1)

        reservation.install()

        reservation.state.check("actions", "install", "ok")