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

Add libvirt loader and qemu child plugin #654

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

Conversation

Miauwkeru
Copy link
Contributor

No description provided.

@Miauwkeru Miauwkeru linked an issue Mar 27, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.86%. Comparing base (8397141) to head (9ae003b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #654      +/-   ##
==========================================
+ Coverage   74.83%   74.86%   +0.03%     
==========================================
  Files         288      290       +2     
  Lines       24024    24058      +34     
==========================================
+ Hits        17978    18012      +34     
  Misses       6046     6046              
Flag Coverage Δ
unittests 74.86% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

if path.suffix.lower() != ".xml":
return False

return "<domain>" in path.read_text().lower()
Copy link
Member

Choose a reason for hiding this comment

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

Is this the first element? Maybe better to limit how many bytes you read to a sensible limit. You may accidentally read a .xml of several GB large.

xml_data = ElementTree.XML(self.path.read_text())
for disk in xml_data.findall("devices/disk/source"):
if file := disk.get("file"):
target.disk.add(container.open(file))
Copy link
Member

Choose a reason for hiding this comment

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

Are these absolute paths? You should join on self.path regardless to ensure that you're reading the file from the same target (local Path or a bound TargetPath).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I've seen, these paths are absolute. But it is fair it should be joined with self.path

@Miauwkeru Miauwkeru force-pushed the 653-add-support-for-libvirtqemu-child-targets branch from 78ff93c to 9ae003b Compare March 28, 2024 11:45
return False

with path.open("rb") as fh:
return b"<domain>" in fh.read(512)
Copy link
Member

@Schamper Schamper Mar 28, 2024

Choose a reason for hiding this comment

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

This doesn't seem to match the qemu.xml that you included in the test file. Also <domain> seems a little too generic, can you make this check more strict? Maybe include some of the other elements that are common/required in a libvirt XML file.

xml_data = ElementTree.XML(self.path.read_text())
for disk in xml_data.findall("devices/disk/source"):
if file := disk.get("file"):
target_file = self.path.joinpath(file)
Copy link
Member

Choose a reason for hiding this comment

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

Another question - in a common libvirt setup, is there a relation between where the .xml file is and where the virtual disk files are? E.g. are they in the same directory?

I'm asking because sometimes we get a bunch of files in a single directory as "evidence". In that case, we may want to check if a file with the disk name exists in the same directory as the .xml file. The original absolute path is usually only checked as a last resort. This is also done in all similar loaders (.vmx etc)



@patch(f"{LibvirtLoader.__module__}.container.open")
def test_libvirt_map(mocked_container_open: Mock, target_bare: Target, fs_linux: VirtualFilesystem):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_libvirt_map(mocked_container_open: Mock, target_bare: Target, fs_linux: VirtualFilesystem):
def test_libvirt_map(mocked_container_open: Mock, target_bare: Target, fs_linux: VirtualFilesystem) -> None:

from tests.conftest import absolute_path


def test_libvirt_detection(target_bare: Target, tmp_path: Path) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Why not also test against the actual qemu.xml you included as test file?

QemuChildTargetPlugin(target_linux).check_compatible()


def test_list_children(target_linux: Target, fs_linux: VirtualFilesystem):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_list_children(target_linux: Target, fs_linux: VirtualFilesystem):
def test_list_children(target_linux: Target, fs_linux: VirtualFilesystem) -> None:

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.

Add support for libvirt/qemu child targets
3 participants