From b47e35d1999b77df1f9d2fae3f48e2dbc7699e27 Mon Sep 17 00:00:00 2001 From: Gerorge Liao Date: Mon, 9 Oct 2023 13:01:16 +0200 Subject: [PATCH] Fix the formatting of the branch --- src/daemon/daemon.cpp | 39 ++++++++++++++--------- src/daemon/instance_settings_handler.cpp | 11 +++++-- src/daemon/instance_settings_handler.h | 3 +- tests/lxd/test_lxd_backend.cpp | 5 +-- tests/test_base_virtual_machine.cpp | 3 +- tests/test_cli_prompters.cpp | 3 +- tests/test_instance_settings_handler.cpp | 40 ++++++++++++++++++------ 7 files changed, 73 insertions(+), 31 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 276f328463..e29b4175c0 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -1174,16 +1174,20 @@ auto timeout_for(const int requested_timeout, const int blueprint_timeout) return mp::default_timeout; } -mp::SettingsHandler* -register_instance_mod(std::unordered_map& vm_instance_specs, - std::unordered_map& vm_instances, - const std::unordered_map& deleted_instances, - const std::unordered_set& preparing_instances, - std::function instance_persister, std::function bridged_interface) -{ - return MP_SETTINGS.register_handler(std::make_unique( - vm_instance_specs, vm_instances, deleted_instances, preparing_instances, std::move(instance_persister), - std::move(bridged_interface))); +mp::SettingsHandler* register_instance_mod( + std::unordered_map& vm_instance_specs, + std::unordered_map& vm_instances, + const std::unordered_map& deleted_instances, + const std::unordered_set& preparing_instances, + std::function instance_persister, + std::function bridged_interface) +{ + return MP_SETTINGS.register_handler(std::make_unique(vm_instance_specs, + vm_instances, + deleted_instances, + preparing_instances, + std::move(instance_persister), + std::move(bridged_interface))); } std::string generate_netplan_script(int index, const std::string& mac_address) @@ -1201,7 +1205,8 @@ std::string generate_netplan_script(int index, const std::string& mac_address) " optional: true\n" " version: 2" "\" | sudo dd of=/etc/netplan/51-extra{0}.yaml oflag=append conv=notrunc", - index, mac_address); + index, + mac_address); } } // namespace @@ -1212,8 +1217,12 @@ mp::Daemon::Daemon(std::unique_ptr the_config) mp::utils::backend_directory_path(config->cache_directory, config->factory->get_backend_directory_name()))}, daemon_rpc{config->server_address, *config->cert_provider, config->client_cert_store.get()}, instance_mod_handler{register_instance_mod( - vm_instance_specs, operative_instances, deleted_instances, preparing_instances, - [this] { persist_instances(); }, get_bridged_interface_name)} + vm_instance_specs, + operative_instances, + deleted_instances, + preparing_instances, + [this] { persist_instances(); }, + get_bridged_interface_name)} { connect_rpc(daemon_rpc, *this); std::vector invalid_specs; @@ -3062,7 +3071,9 @@ mp::Daemon::async_wait_for_ready_all(grpc::ServerReaderWriterInterfacessh_hostname(), vm->ssh_port(), vm_specs.ssh_username, + mp::SSHSession session{vm->ssh_hostname(), + vm->ssh_port(), + vm_specs.ssh_username, *config->ssh_key_provider}; for (const auto& command : commands->second) diff --git a/src/daemon/instance_settings_handler.cpp b/src/daemon/instance_settings_handler.cpp index e771b20b36..0757f14834 100644 --- a/src/daemon/instance_settings_handler.cpp +++ b/src/daemon/instance_settings_handler.cpp @@ -157,11 +157,15 @@ void update_disk(const QString& key, const QString& val, mp::VirtualMachine& ins bool is_bridged(const mp::VMSpecs& spec, const std::string& br_interface) { - return std::any_of(spec.extra_interfaces.cbegin(), spec.extra_interfaces.cend(), + return std::any_of(spec.extra_interfaces.cbegin(), + spec.extra_interfaces.cend(), [&br_interface](const auto& network) -> bool { return network.id == br_interface; }); } -void update_bridged(const QString& key, const QString& val, mp::VirtualMachine& instance, mp::VMSpecs& spec, +void update_bridged(const QString& key, + const QString& val, + mp::VirtualMachine& instance, + mp::VMSpecs& spec, const std::string& br_interface) { auto bridged = mp::BoolSettingSpec{key, "false"}.interpret(val) == "true"; @@ -191,7 +195,8 @@ mp::InstanceSettingsHandler::InstanceSettingsHandler( std::unordered_map& vm_instance_specs, std::unordered_map& vm_instances, const std::unordered_map& deleted_instances, - const std::unordered_set& preparing_instances, std::function instance_persister, + const std::unordered_set& preparing_instances, + std::function instance_persister, std::function bridged_interface) : vm_instance_specs{vm_instance_specs}, vm_instances{vm_instances}, diff --git a/src/daemon/instance_settings_handler.h b/src/daemon/instance_settings_handler.h index 98e84d2428..074e7b7a87 100644 --- a/src/daemon/instance_settings_handler.h +++ b/src/daemon/instance_settings_handler.h @@ -41,7 +41,8 @@ class InstanceSettingsHandler : public SettingsHandler std::unordered_map& vm_instances, const std::unordered_map& deleted_instances, const std::unordered_set& preparing_instances, - std::function instance_persister, std::function bridged_interface); + std::function instance_persister, + std::function bridged_interface); std::set keys() const override; QString get(const QString& key) const override; diff --git a/tests/lxd/test_lxd_backend.cpp b/tests/lxd/test_lxd_backend.cpp index 062f3f0e13..ae2c0f2a2a 100644 --- a/tests/lxd/test_lxd_backend.cpp +++ b/tests/lxd/test_lxd_backend.cpp @@ -2217,8 +2217,9 @@ TEST_F(LXDBackend, addsNetworkInterface) { ++times_called; - EXPECT_EQ(data.toStdString(), "{\"devices\":{\"eth2\":{\"hwaddr\":\"52:54:00:56:78:90\",\"name\":" - "\"eth2\",\"nictype\":\"bridged\",\"parent\":\"id\",\"type\":\"nic\"}}}"); + EXPECT_EQ(data.toStdString(), + "{\"devices\":{\"eth2\":{\"hwaddr\":\"52:54:00:56:78:90\",\"name\":" + "\"eth2\",\"nictype\":\"bridged\",\"parent\":\"id\",\"type\":\"nic\"}}}"); return new mpt::MockLocalSocketReply(mpt::stop_vm_data); } diff --git a/tests/test_base_virtual_machine.cpp b/tests/test_base_virtual_machine.cpp index 0d8d6c5be5..102b4186f4 100644 --- a/tests/test_base_virtual_machine.cpp +++ b/tests/test_base_virtual_machine.cpp @@ -153,7 +153,8 @@ TEST_F(BaseVM, add_network_interface_throws) StubBaseVirtualMachine base_vm(mp::VirtualMachine::State::off); MP_EXPECT_THROW_THAT(base_vm.add_network_interface(1, {"eth1", "52:54:00:00:00:00", true}), - mp::NotImplementedOnThisBackendException, mpt::match_what(HasSubstr("bridging"))); + mp::NotImplementedOnThisBackendException, + mpt::match_what(HasSubstr("bridging"))); } struct IpTestParams diff --git a/tests/test_cli_prompters.cpp b/tests/test_cli_prompters.cpp index c3e98f1b42..1d8225543f 100644 --- a/tests/test_cli_prompters.cpp +++ b/tests/test_cli_prompters.cpp @@ -198,7 +198,8 @@ TEST_P(BridgePrompterTests, correctlyReturns) EXPECT_EQ(prompter.bridge_prompt(nets), ret); } -INSTANTIATE_TEST_SUITE_P(CLIPrompters, BridgePrompterTests, +INSTANTIATE_TEST_SUITE_P(CLIPrompters, + BridgePrompterTests, Values(std::make_tuple(std::vector{"eth1"}, "yes", true), std::make_tuple(std::vector{"eth1", "eth3"}, "y", true), std::make_tuple(std::vector{"eth1", "eth3"}, "no", false), diff --git a/tests/test_instance_settings_handler.cpp b/tests/test_instance_settings_handler.cpp index 4f420ed671..f8998afc21 100644 --- a/tests/test_instance_settings_handler.cpp +++ b/tests/test_instance_settings_handler.cpp @@ -49,8 +49,12 @@ struct TestInstanceSettingsHandler : public Test { mp::InstanceSettingsHandler make_handler() { - return mp::InstanceSettingsHandler{ - specs, vms, deleted_vms, preparing_vms, make_fake_persister(), make_fake_bridged_interface()}; + return mp::InstanceSettingsHandler{specs, + vms, + deleted_vms, + preparing_vms, + make_fake_persister(), + make_fake_bridged_interface()}; } void fake_instance_state(const char* name, SpecialInstanceState special_state) @@ -219,7 +223,8 @@ TEST_P(TestBridgedInstanceSettings, getFetchesBridged) EXPECT_EQ(got, bridged ? "true" : "false"); } -INSTANTIATE_TEST_SUITE_P(getFetchesBridged, TestBridgedInstanceSettings, +INSTANTIATE_TEST_SUITE_P(getFetchesBridged, + TestBridgedInstanceSettings, Values(std::make_pair("eth8", true), std::make_pair("eth9", false))); TEST_F(TestInstanceSettingsHandler, getFetchesPropertiesOfInstanceInSpecialState) @@ -531,7 +536,8 @@ TEST_P(TestInstanceModOnStoppedInstance, setWorksOnOtherStates) EXPECT_THAT(props, Contains(QString{val}.toLongLong())); } -INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, TestInstanceModOnStoppedInstance, +INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, + TestInstanceModOnStoppedInstance, Combine(ValuesIn(TestInstanceSettingsHandler::numeric_properties), Values(VMSt::off, VMSt::stopped))); @@ -552,7 +558,8 @@ TEST_P(TestInstanceModPersists, setPersistsInstances) EXPECT_TRUE(fake_persister_called); } -INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, TestInstanceModPersists, +INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, + TestInstanceModPersists, ValuesIn(TestInstanceSettingsHandler::numeric_properties)); TEST_F(TestInstanceSettingsHandler, setRefusesToModifyInstancesInSpecialState) @@ -631,10 +638,24 @@ TEST_P(TestInstanceSettingsHandlerBadNumericValues, setRefusesBadNumericValues) EXPECT_EQ(original_specs, specs[target_instance_name]); } -INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, TestInstanceSettingsHandlerBadNumericValues, +INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, + TestInstanceSettingsHandlerBadNumericValues, Combine(ValuesIn(TestInstanceSettingsHandler::numeric_properties), - Values("0", "2u", "1.5f", "2.0", "0xa", "0x8", "-4", "-1", "rubbish", " 123nonsense ", - "¤9", "\n", "\t", "^", ""))); + Values("0", + "2u", + "1.5f", + "2.0", + "0xa", + "0x8", + "-4", + "-1", + "rubbish", + " 123nonsense ", + "¤9", + "\n", + "\t", + "^", + ""))); struct TestInstanceSettingsHandlerBadBooleanValues : public TestInstanceSettingsHandler, public WithParamInterface @@ -656,7 +677,8 @@ TEST_P(TestInstanceSettingsHandlerBadBooleanValues, setRefusesBadBooleanValues) EXPECT_EQ(original_specs, specs[target_instance_name]); } -INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, TestInstanceSettingsHandlerBadBooleanValues, +INSTANTIATE_TEST_SUITE_P(TestInstanceSettingsHandler, + TestInstanceSettingsHandlerBadBooleanValues, Combine(ValuesIn(TestInstanceSettingsHandler::boolean_properties), Values("apostrophe", "(')", "1974"))); } // namespace