Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get local.instance.bridged #3513

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Fix get local.instance.bridged #3513

wants to merge 9 commits into from

Conversation

luis4a0
Copy link
Contributor

@luis4a0 luis4a0 commented Apr 26, 2024

The answer was wrong in some backends. This PR uses a more reliable mechanism, inspecting the contents of the platform networks data structure.

Fixes #3489.

@luis4a0 luis4a0 changed the title Fix get local.instance.bridged Fix get local.instance.bridged Apr 26, 2024
@luis4a0 luis4a0 force-pushed the fix-get-bridged branch 2 times, most recently from 6fd3996 to 6434e8e Compare May 2, 2024 13:59
Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.80%. Comparing base (2a16af2) to head (2f4ac45).

Files Patch % Lines
...orm/backends/qemu/qemu_virtual_machine_factory.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3513      +/-   ##
==========================================
- Coverage   88.82%   88.80%   -0.02%     
==========================================
  Files         254      254              
  Lines       14115    14115              
==========================================
- Hits        12537    12535       -2     
- Misses       1578     1580       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @luis4a0, thanks for this PR. I think the idea of replacing the bridge name with a bridge member check is what we need. However, I am afraid I don't follow the new logic in is_bridged.

I think the idea is just (in pseudocode):

alt_net = is_bridge(br_interface) ? nullopt : find_bridge_with(br_interface);
return std::any_of(spec.extra_interfaces.cbegin(),
                   spec.extra_interfaces.cend(),
                   [&br_interface, &alt_net](const auto& network) -> bool {
                       return network.id == br_interface || network.id == alt_net;
                   }); // this is there already

Regarding backends (or backend/platform combinations) where no bridge is necessary to connect the instance to the desired interface... Suppose that a user sets up a bridge (say custom-bridge) linked to the interface some-net. And suppose that they multipass launch --network custom-bridge. I don't think it is wrong to say that the resulting instance is bridged with some-net, even if the backend is VirtualBox and the bridge is unnecessary. I think it is actually more correct to say it is bridged.

IOW, the logic above should be mostly independent from backends. The exception I see is the bridge type (bridge vs switch).

As discussed, I ignored tests for now.

return true;
}

const auto& br_it = config->factory->find_bridge_with(host_nets, br_interface, "bridge");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can hardcode "bridge" here. It would be "switch" in Hyper-V. But let's perhaps deal with this later, after the rest is figured out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed.

Comment on lines 3560 to 3533
if (std::any_of(std::cbegin(host_nets),
std::cend(host_nets),
[&br_interface](const mp::NetworkInterfaceInfo& info) {
return info.id == br_interface && info.type == "bridge";
}))
{
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this. I read "if we find that the host has a bridge named like the configured bridge, return true". But this is unrelated to whether or not the instance is has that network. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. I removed this and modified the last one in the function.

Comment on lines +3572 to +3532
if (br_it == host_nets.cend())
{
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this either. If the configured network is a bridge, it won't be part of any other bridge. Yet we shouldn't just return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I changed the checks before this one.

@luis4a0 luis4a0 force-pushed the fix-get-bridged branch 4 times, most recently from 12fd884 to 238f240 Compare May 7, 2024 13:15
Copy link
Collaborator

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @luis4a0,

Why is there anything qemu related, particularly on Linux, in this PR? Shouldn't this be done in #3463 once this PR is in?

@luis4a0
Copy link
Contributor Author

luis4a0 commented May 9, 2024

Hey @townsend2010!

Why is there anything qemu related, particularly on Linux, in this PR? Shouldn't this be done in #3463 once this PR is in?

On one hand, moving to platform detail is needed because the code will be different for macOS QEMU. On the other hand, you are right in the sense that the particular function implementation will be needed after bridging is implemented in Linux QEMU. I can make the detail function on Linux throw, and then in the other PR introduce the code again.

@luis4a0
Copy link
Contributor Author

luis4a0 commented May 9, 2024

Hey @townsend2010, @ricab! I addressed all the concerns above, and added some tests. This is ready for review now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multipass does not recognize Hyper-V instances as bridged
3 participants