stages/ovf: vmware's ostype as option

Let the user of the stage set the os type for the vmware bits.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2025-06-30 08:35:50 +02:00 committed by Simon de Vlieger
parent 9559cd0528
commit ce2bda719c
3 changed files with 26 additions and 5 deletions

View file

@ -24,7 +24,7 @@ OVF_TEMPLATE = """<?xml version="1.0"?>
<VirtualSystem ovf:id="image">
<Info>A virtual machine</Info>
<Name>VM</Name>
<OperatingSystemSection ovf:id="100" vmw:osType="other26xLinux64Guest">
<OperatingSystemSection ovf:id="100" vmw:osType="{vmware_os_type}">
<Info>The kind of installed guest operating system</Info>
</OperatingSystemSection>
<VirtualHardwareSection ovf:transport="com.vmware.guestInfo">
@ -148,12 +148,13 @@ def virtual_size(vmdk):
return json.loads(res.stdout)["virtual-size"]
def write_template(vmdk):
def write_template(vmdk, options):
dirname, basename = os.path.split(vmdk)
ovf_data = OVF_TEMPLATE.format(
vmdk_size=os.stat(vmdk).st_size,
vmdk_capacity=virtual_size(vmdk),
vmware_os_type=options.get("vmware", {}).get("os_type", "other26xLinux64Guest"),
vbox_machine_uuid=str(uuid.uuid4()),
vbox_disk_uuid=str(uuid.uuid4()),
vbox_os_type="ArchLinux_64",
@ -186,7 +187,8 @@ def write_manifest(vmdk, ovf):
def main(options, tree):
vmdk = os.path.join(tree, options["vmdk"])
ovf = write_template(vmdk)
print(options)
ovf = write_template(vmdk, options)
write_manifest(vmdk, ovf)
return 0

View file

@ -18,6 +18,17 @@
"description": "The vmdk image filename present in the root of the tree",
"type": "string",
"pattern": "[a-zA-Z0-9+_.-]+.vmdk"
},
"vmware": {
"description": "Settings for VMWare specific parts of the OVF file.",
"type": "object",
"additionalProperties": false,
"properties": {
"os_type": {
"type": "string",
"default": "other26xLinux64Guest"
}
}
}
}
}

View file

@ -39,14 +39,22 @@ def test_schema_validation_ovf(stage_schema, test_data, expected_err):
@pytest.mark.skipif(not testutil.has_executable("qemu-img"), reason="need qemu-img")
def test_ovf_default_template(tmp_path, stage_module):
@pytest.mark.parametrize("test_opts, expected_substrings", [
# Replacements
({"vmware": {"os_type": "my-os-type"}}, ["my-os-type"],),
])
def test_ovf_default_template(tmp_path, stage_module, test_opts, expected_substrings):
faked_vmdk_path = tmp_path / "some-image.vmdk"
faked_vmdk_path.write_bytes(b"1234")
opts = {
"vmdk": faked_vmdk_path,
}
opts.update(test_opts)
stage_module.main(opts, tmp_path)
expected_template_path = tmp_path / "some-image.ovf"
assert "other26xLinux64Guest" in expected_template_path.read_text()
for substring in expected_substrings:
assert substring in expected_template_path.read_text()