Skip to content
71 changes: 61 additions & 10 deletions tests/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let
hugepages ? false,
prefault ? false,
serial ? "pty",
# Whether all device will be assigned a static BDF through the XML or only some
all_static_bdf ? false,
}:
''
<domain type='kvm' id='21050'>
Expand Down Expand Up @@ -113,15 +115,38 @@ let
<on_crash>destroy</on_crash>
<devices>
<emulator>cloud-hypervisor</emulator>
${
# Add the implicitly created RNG device explicitly
if all_static_bdf then
''
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<alias name='explicit-rng-device'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</rng>
''
else
""
}
<disk type='file' device='disk'>
<source file='${image}'/>
<target dev='vda' bus='virtio'/>
${
# Assign a fixed BDF that would normally be acquired by the implicit RNG device
if all_static_bdf then
''
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
''
else
""
}
</disk>
<interface type='ethernet'>
<mac address='52:54:00:e5:b8:ef'/>
<target dev='vnet0'/>
<model type='virtio'/>
<driver queues='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</interface>
${
if serial == "pty" then
Expand Down Expand Up @@ -154,14 +179,26 @@ let
</domain>
'';

new_interface = ''
<interface type='ethernet'>
<mac address='52:54:00:e5:b8:dd'/>
<target dev='tap0'/>
<model type='virtio'/>
<driver queues='1'/>
</interface>
'';
new_interface =
{
explicit_bdf ? false,
}:
''
<interface type='ethernet'>
<mac address='52:54:00:e5:b8:dd'/>
<target dev='tap0'/>
<model type='virtio'/>
<driver queues='1'/>
${
if explicit_bdf then
''
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
''
else
""
}
</interface>
'';
in
{
# Silence the monolithic libvirtd, which otherwise starts before the virtchd
Expand Down Expand Up @@ -263,7 +300,7 @@ in
matchConfig.Name = "br0";
networkConfig = {
Description = "Main Bridge";
DHCPServer = "yes";
DHCPServer = "no";
};

# Static IP configuration for the bridge itself
Expand Down Expand Up @@ -424,9 +461,23 @@ in
})}";
};
};
"/etc/domain-chv-static-bdf.xml" = {
"C+" = {
argument = "${pkgs.writeText "domain-chv-static-bdf.xml" (virsh_ch_xml {
all_static_bdf = true;
})}";
};
};
"/etc/new_interface.xml" = {
"C+" = {
argument = "${pkgs.writeText "new_interface.xml" new_interface}";
argument = "${pkgs.writeText "new_interface.xml" (new_interface { })}";
};
};
"/etc/new_interface_explicit_bdf.xml" = {
"C+" = {
argument = "${pkgs.writeText "new_interface_explicit_bdf.xml" (new_interface {
explicit_bdf = true;
})}";
};
};
"/var/log/libvirt/" = {
Expand Down
Loading