Skip to content

Commit

Permalink
Fix the formatting of the branch
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeliao authored and luis4a0 committed Oct 18, 2023
1 parent 8b02e1c commit b47e35d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 31 deletions.
39 changes: 25 additions & 14 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, mp::VMSpecs>& vm_instance_specs,
std::unordered_map<std::string, mp::VirtualMachine::ShPtr>& vm_instances,
const std::unordered_map<std::string, mp::VirtualMachine::ShPtr>& deleted_instances,
const std::unordered_set<std::string>& preparing_instances,
std::function<void()> instance_persister, std::function<std::string()> bridged_interface)
{
return MP_SETTINGS.register_handler(std::make_unique<mp::InstanceSettingsHandler>(
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<std::string, mp::VMSpecs>& vm_instance_specs,
std::unordered_map<std::string, mp::VirtualMachine::ShPtr>& vm_instances,
const std::unordered_map<std::string, mp::VirtualMachine::ShPtr>& deleted_instances,
const std::unordered_set<std::string>& preparing_instances,
std::function<void()> instance_persister,
std::function<std::string()> bridged_interface)
{
return MP_SETTINGS.register_handler(std::make_unique<mp::InstanceSettingsHandler>(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)
Expand All @@ -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

Expand All @@ -1212,8 +1217,12 @@ mp::Daemon::Daemon(std::unique_ptr<const DaemonConfig> 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<std::string> invalid_specs;
Expand Down Expand Up @@ -3062,7 +3071,9 @@ mp::Daemon::async_wait_for_ready_all(grpc::ServerReaderWriterInterface<Reply, Re

try
{
mp::SSHSession session{vm->ssh_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)
Expand Down
11 changes: 8 additions & 3 deletions src/daemon/instance_settings_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -191,7 +195,8 @@ mp::InstanceSettingsHandler::InstanceSettingsHandler(
std::unordered_map<std::string, VMSpecs>& vm_instance_specs,
std::unordered_map<std::string, VirtualMachine::ShPtr>& vm_instances,
const std::unordered_map<std::string, VirtualMachine::ShPtr>& deleted_instances,
const std::unordered_set<std::string>& preparing_instances, std::function<void()> instance_persister,
const std::unordered_set<std::string>& preparing_instances,
std::function<void()> instance_persister,
std::function<std::string()> bridged_interface)
: vm_instance_specs{vm_instance_specs},
vm_instances{vm_instances},
Expand Down
3 changes: 2 additions & 1 deletion src/daemon/instance_settings_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class InstanceSettingsHandler : public SettingsHandler
std::unordered_map<std::string, VirtualMachine::ShPtr>& vm_instances,
const std::unordered_map<std::string, VirtualMachine::ShPtr>& deleted_instances,
const std::unordered_set<std::string>& preparing_instances,
std::function<void()> instance_persister, std::function<std::string()> bridged_interface);
std::function<void()> instance_persister,
std::function<std::string()> bridged_interface);

std::set<QString> keys() const override;
QString get(const QString& key) const override;
Expand Down
5 changes: 3 additions & 2 deletions tests/lxd/test_lxd_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli_prompters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>{"eth1"}, "yes", true),
std::make_tuple(std::vector<std::string>{"eth1", "eth3"}, "y", true),
std::make_tuple(std::vector<std::string>{"eth1", "eth3"}, "no", false),
Expand Down
40 changes: 31 additions & 9 deletions tests/test_instance_settings_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)));

Expand All @@ -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)
Expand Down Expand Up @@ -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<PropertyValue>
Expand All @@ -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

0 comments on commit b47e35d

Please sign in to comment.