diff --git a/include/multipass/utils.h b/include/multipass/utils.h index 73f9936a8a..cc3cee53fd 100644 --- a/include/multipass/utils.h +++ b/include/multipass/utils.h @@ -31,9 +31,7 @@ #include #include #include -#include #include -#include #include #include @@ -321,4 +319,6 @@ std::string multipass::utils::qenum_to_string(RegisteredQtEnum val) return qenum_to_qstring(val).toStdString(); } +std::string deprecation_warning_message_driver_concatenated( + const QString driver_name); // TODO lxd and libvirt migration, remove #endif // MULTIPASS_UTILS_H diff --git a/src/client/cli/cmd/set.cpp b/src/client/cli/cmd/set.cpp index 03f3d43e98..66494a68b0 100644 --- a/src/client/cli/cmd/set.cpp +++ b/src/client/cli/cmd/set.cpp @@ -96,6 +96,14 @@ mp::ParseCode cmd::Set::parse_args(mp::ArgParser* parser) { key = keyval.at(0); val = keyval.at(1); + +#ifdef MULTIPASS_PLATFORM_LINUX + // TODO lxd and libvirt migration, remove + if (key == mp::driver_key && (val == "lxd" || val == "libvirt")) + { + std::cout << deprecation_warning_message_driver_concatenated(val); + } +#endif } else { diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 16183fd200..51b7676c1e 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -1285,6 +1285,21 @@ void populate_snapshot_info(mp::VirtualMachine& vm, populate_snapshot_fundamentals(snapshot, fundamentals); } + +template +void lxd_and_libvirt_deprecation_warning( + grpc::ServerReaderWriterInterface& server) // TODO lxd and libvirt migration, remove +{ +#ifdef MULTIPASS_PLATFORM_LINUX + const auto current_driver = MP_SETTINGS.get(mp::driver_key); + if (current_driver == "lxd" || current_driver == "libvirt") + { + Reply reply{}; + reply.set_log_line(deprecation_warning_message_driver_concatenated(current_driver)); + server.Write(reply); + } +#endif +} } // namespace mp::Daemon::Daemon(std::unique_ptr the_config) @@ -1544,6 +1559,7 @@ void mp::Daemon::launch(const LaunchRequest* request, std::promise* status_promise) // clang-format off try // clang-format on { + lxd_and_libvirt_deprecation_warning(*server); // TODO lxd and libvirt migration, remove mpl::ClientLogger logger{mpl::level_from(request->verbosity_level()), *config->logger, server}; @@ -1728,6 +1744,7 @@ void mp::Daemon::info(const InfoRequest* request, grpc::ServerReaderWriterInterf std::promise* status_promise) // clang-format off try // clang-format on { + lxd_and_libvirt_deprecation_warning(*server); // TODO lxd and libvirt migration, remove mpl::ClientLogger logger{mpl::level_from(request->verbosity_level()), *config->logger, server}; InfoReply response; @@ -1818,6 +1835,7 @@ void mp::Daemon::list(const ListRequest* request, grpc::ServerReaderWriterInterf std::promise* status_promise) // clang-format off try // clang-format on { + lxd_and_libvirt_deprecation_warning(*server); // TODO lxd and libvirt migration, remove mpl::ClientLogger logger{mpl::level_from(request->verbosity_level()), *config->logger, server}; ListReply response; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 877b6ece06..c38ad67635 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -583,3 +583,23 @@ auto mp::utils::find_bridge_with(const std::vector& ne }); return it == std::cend(networks) ? std::nullopt : std::make_optional(*it); } + +std::string deprecation_warning_message_driver_concatenated( + const QString driver_name) // TODO lxd and libvirt migration, remove +{ + constexpr auto driver_deprecation_warning_template_common_part = + "*** Warning! The {0} driver is deprecated and will be removed in an future " + "release. ***\n\n"; + + constexpr auto driver_deprecation_warning_lxd_part = "Instances will no longer be available in Multipass then, " + "but they will remain in LXD.\n\n"; + + constexpr auto driver_deprecation_warning_libvirt_part = + "Instances will remain available with the QEMU driver.\n\n"; + + const std::string deprecation_warning_message_driver_specific_part = + driver_name == "lxd" ? driver_deprecation_warning_lxd_part : driver_deprecation_warning_libvirt_part; + + return fmt::format(driver_deprecation_warning_template_common_part, driver_name) + + deprecation_warning_message_driver_specific_part; +} diff --git a/tests/test_daemon.cpp b/tests/test_daemon.cpp index 8ceaf74de1..0c663ba92d 100644 --- a/tests/test_daemon.cpp +++ b/tests/test_daemon.cpp @@ -132,6 +132,8 @@ struct Daemon : public mpt::DaemonTestFixture a few more tests for `false`, since there are different portions of code depending on it */ EXPECT_CALL(mock_settings, get(Eq(mp::winterm_key))).WillRepeatedly(Return("none")); EXPECT_CALL(mock_settings, get(Eq(mp::bridged_interface_key))).WillRepeatedly(Return("eth8")); + EXPECT_CALL(mock_settings, get(Eq(mp::driver_key))) + .WillRepeatedly(Return("qemu")); // TODO lxd and libvirt migration, remove } mpt::MockUtils::GuardedMock mock_utils_injection{mpt::MockUtils::inject()}; diff --git a/tests/test_daemon_launch.cpp b/tests/test_daemon_launch.cpp index e01bff9f80..b2a441a16f 100644 --- a/tests/test_daemon_launch.cpp +++ b/tests/test_daemon_launch.cpp @@ -16,19 +16,14 @@ */ #include "blueprint_test_lambdas.h" -#include "common.h" #include "daemon_test_fixture.h" -#include "mock_image_host.h" #include "mock_json_utils.h" #include "mock_permission_utils.h" #include "mock_platform.h" #include "mock_server_reader_writer.h" #include "mock_settings.h" -#include "mock_virtual_machine.h" #include "mock_vm_blueprint_provider.h" #include "mock_vm_image_vault.h" -#include "stub_virtual_machine.h" -#include "stub_vm_image_vault.h" #include @@ -46,6 +41,8 @@ struct TestDaemonLaunch : public mpt::DaemonTestFixture EXPECT_CALL(mock_settings, register_handler).WillRepeatedly(Return(nullptr)); EXPECT_CALL(mock_settings, unregister_handler).Times(AnyNumber()); EXPECT_CALL(mock_settings, get(Eq(mp::mounts_key))).WillRepeatedly(Return("true")); + EXPECT_CALL(mock_settings, get(Eq(mp::driver_key))) + .WillRepeatedly(Return("qemu")); // TODO lxd and libvirt migration, remove } mpt::MockPlatform::GuardedMock attr{mpt::MockPlatform::inject()};