From 6cc7987627ba74fac040200570aedba2a058cbc0 Mon Sep 17 00:00:00 2001 From: Hugues Fafard Date: Wed, 28 Jul 2021 16:42:45 +0200 Subject: [PATCH] Finish reordering stuff and cleaning up Finishes shuffling bits of code around to make the options better grouped in the code so it's easier to read and understand what's what at a glance. --- .../compare/virt-install-boot-container.xml | 8 +-- .../virt-install-boot-guest-loader-bios.xml | 2 +- .../virt-install-boot-guest-loader-efi.xml | 2 +- .../cli/compare/virt-install-boot-uefi.xml | 2 +- .../virt-install-singleton-config-1.xml | 4 +- .../virt-install-singleton-config-2.xml | 30 +++++----- .../virt-install-singleton-config-3.xml | 2 +- .../cli/compare/virt-xml-edit-simple-boot.xml | 2 +- tests/data/xmlparse/change-guest-out.xml | 6 +- virtinst/cli.py | 46 +++++++++------- virtinst/domain/os.py | 55 +++++++++++-------- 11 files changed, 87 insertions(+), 72 deletions(-) diff --git a/tests/data/cli/compare/virt-install-boot-container.xml b/tests/data/cli/compare/virt-install-boot-container.xml index bc8107169..a4acc0c4f 100644 --- a/tests/data/cli/compare/virt-install-boot-container.xml +++ b/tests/data/cli/compare/virt-install-boot-container.xml @@ -6,15 +6,15 @@ 1 hvm - /my/custom/cwd - tester - 1000 - /bin/systemd --unit emergency.service some value bar + /my/custom/cwd + tester + 1000 + diff --git a/tests/data/cli/compare/virt-install-boot-guest-loader-bios.xml b/tests/data/cli/compare/virt-install-boot-guest-loader-bios.xml index ae9572bce..c1bbdad77 100644 --- a/tests/data/cli/compare/virt-install-boot-guest-loader-bios.xml +++ b/tests/data/cli/compare/virt-install-boot-guest-loader-bios.xml @@ -6,7 +6,7 @@ 1 hvm - /path/to/loader + /path/to/loader diff --git a/tests/data/cli/compare/virt-install-boot-guest-loader-efi.xml b/tests/data/cli/compare/virt-install-boot-guest-loader-efi.xml index d3a213136..fd4b4c4f3 100644 --- a/tests/data/cli/compare/virt-install-boot-guest-loader-efi.xml +++ b/tests/data/cli/compare/virt-install-boot-guest-loader-efi.xml @@ -6,7 +6,7 @@ 1 hvm - /path/to/loader + /path/to/loader /path/to/nvram diff --git a/tests/data/cli/compare/virt-install-boot-uefi.xml b/tests/data/cli/compare/virt-install-boot-uefi.xml index c97f86fc8..83e5c1dde 100644 --- a/tests/data/cli/compare/virt-install-boot-uefi.xml +++ b/tests/data/cli/compare/virt-install-boot-uefi.xml @@ -6,7 +6,7 @@ 1 hvm - /usr/share/ovmf/OVMF_CODE.secboot.fd + /usr/share/ovmf/OVMF_CODE.secboot.fd diff --git a/tests/data/cli/compare/virt-install-singleton-config-1.xml b/tests/data/cli/compare/virt-install-singleton-config-1.xml index 49e0cd856..f7430de20 100644 --- a/tests/data/cli/compare/virt-install-singleton-config-1.xml +++ b/tests/data/cli/compare/virt-install-singleton-config-1.xml @@ -23,11 +23,11 @@ hvm /usr/share/OVMF/OVMF_CODE.fd + foo + bar=baz - foo - bar=baz diff --git a/tests/data/cli/compare/virt-install-singleton-config-2.xml b/tests/data/cli/compare/virt-install-singleton-config-2.xml index 40dcf8e60..0107a4a7d 100644 --- a/tests/data/cli/compare/virt-install-singleton-config-2.xml +++ b/tests/data/cli/compare/virt-install-singleton-config-2.xml @@ -93,20 +93,20 @@ /new/bootld hvm - /foo/bar - /my/custom/cwd - tester - 1000 - - - - + /foo/bar foo=bar baz=woo + /my/custom/cwd + tester + 1000 + + + + @@ -345,7 +345,13 @@ /new/bootld hvm + + + + /foo/bar + foo=bar + baz=woo /my/custom/cwd tester 1000 @@ -353,15 +359,9 @@ - - - - - - foo=bar - baz=woo + diff --git a/tests/data/cli/compare/virt-install-singleton-config-3.xml b/tests/data/cli/compare/virt-install-singleton-config-3.xml index 46e7ce406..45d63a02b 100644 --- a/tests/data/cli/compare/virt-install-singleton-config-3.xml +++ b/tests/data/cli/compare/virt-install-singleton-config-3.xml @@ -46,9 +46,9 @@ /tmp/foo root=/foo - + diff --git a/tests/data/cli/compare/virt-xml-edit-simple-boot.xml b/tests/data/cli/compare/virt-xml-edit-simple-boot.xml index 142a8c0dd..80c05a7cd 100644 --- a/tests/data/cli/compare/virt-xml-edit-simple-boot.xml +++ b/tests/data/cli/compare/virt-xml-edit-simple-boot.xml @@ -4,8 +4,8 @@ - /usr/lib/xen/boot/hvmloader + foo.bar + /test/nvram.img -+ + /bin/bash ++ diff --git a/tests/data/xmlparse/change-guest-out.xml b/tests/data/xmlparse/change-guest-out.xml index 457156550..9fbb06fdc 100644 --- a/tests/data/xmlparse/change-guest-out.xml +++ b/tests/data/xmlparse/change-guest-out.xml @@ -11,13 +11,13 @@ xen /foo/loader - /sbin/init - - foo bar baz frib + + + diff --git a/virtinst/cli.py b/virtinst/cli.py index fe22ee8db..bc8df22a3 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -2659,7 +2659,9 @@ class ParserBoot(VirtCLIParser): cls.add_arg("network", None, lookup_cb=None, cb=cls.noset_cb) # UEFI depends on these bits, so set them first + cls.add_arg("os_type", "os_type") cls.add_arg("arch", "arch") + cls.add_arg("machine", "machine") cls.add_arg("bootloader", None, lookup_cb=None, cb=cls.set_bootloader_cb) cls.add_arg("bootloader_args", None, lookup_cb=None, @@ -2670,9 +2672,30 @@ class ParserBoot(VirtCLIParser): cb=cls.set_emulator_cb) cls.add_arg("uefi", None, lookup_cb=None, cb=cls.set_uefi_cb) - cls.add_arg("os_type", "os_type") - cls.add_arg("machine", "machine") + # Common/Shared boot options + cls.add_arg("loader", "loader") + cls.add_arg("loader.readonly", "loader_ro", is_onoff=True) + cls.add_arg("loader.type", "loader_type") + cls.add_arg("loader.secure", "loader_secure", is_onoff=True) + + # Guest-Based bootloader options + cls.add_arg("firmware", "firmware") + cls.add_arg("firmware.feature[0-9]*.enabled", "enabled", + find_inst_cb=cls.feature_find_inst_cb, is_onoff=True) + cls.add_arg("firmware.feature[0-9]*.name", "name", + find_inst_cb=cls.feature_find_inst_cb) + cls.add_arg("nvram", "nvram") + cls.add_arg("nvram.template", "nvram_template") + cls.add_arg("boot[0-9]*.dev", "dev", + find_inst_cb=cls.boot_find_inst_cb) + cls.add_arg("bootmenu.enable", "bootmenu_enable", is_onoff=True) + cls.add_arg("bootmenu.timeout", "bootmenu_timeout") + cls.add_arg("bios.useserial", "bios_useserial", is_onoff=True) + cls.add_arg("bios.rebootTimeout", "bios_rebootTimeout") + cls.add_arg("smbios.mode", "smbios_mode") + + # Direct kernel boot options cls.add_arg("kernel", "kernel") cls.add_arg("initrd", "initrd") cls.add_arg("cmdline", "kernel_args", can_comma=True) @@ -2680,17 +2703,7 @@ class ParserBoot(VirtCLIParser): cls.add_arg("acpi.table", "acpi_tb") cls.add_arg("acpi.table.type", "acpi_tb_type") - cls.add_arg("firmware", "firmware") - cls.add_arg("firmware.feature[0-9]*.enabled", "enabled", - find_inst_cb=cls.feature_find_inst_cb, is_onoff=True) - cls.add_arg("firmware.feature[0-9]*.name", "name", - find_inst_cb=cls.feature_find_inst_cb) - cls.add_arg("boot[0-9]*.dev", "dev", - find_inst_cb=cls.boot_find_inst_cb) - cls.add_arg("bootmenu.enable", "bootmenu_enable", is_onoff=True) - cls.add_arg("bootmenu.timeout", "bootmenu_timeout") - cls.add_arg("bios.useserial", "bios_useserial", is_onoff=True) - cls.add_arg("bios.rebootTimeout", "bios_rebootTimeout") + # Container boot options cls.add_arg("init", "init") cls.add_arg("initargs", "initargs", cb=cls.set_initargs_cb) cls.add_arg("initarg[0-9]*", "val", @@ -2702,13 +2715,6 @@ class ParserBoot(VirtCLIParser): cls.add_arg("initdir", "initdir") cls.add_arg("inituser", "inituser") cls.add_arg("initgroup", "initgroup") - cls.add_arg("loader", "loader") - cls.add_arg("loader.readonly", "loader_ro", is_onoff=True) - cls.add_arg("loader.type", "loader_type") - cls.add_arg("loader.secure", "loader_secure", is_onoff=True) - cls.add_arg("nvram", "nvram") - cls.add_arg("nvram.template", "nvram_template") - cls.add_arg("smbios.mode", "smbios_mode") ################### diff --git a/virtinst/domain/os.py b/virtinst/domain/os.py index 2e65a5236..e2cea7554 100644 --- a/virtinst/domain/os.py +++ b/virtinst/domain/os.py @@ -78,13 +78,30 @@ class DomainOs(XMLBuilder): def is_riscv_virt(self): return self.is_riscv() and str(self.machine).startswith("virt") - XML_NAME = "os" - _XML_PROP_ORDER = ["arch", "os_type", "loader", "loader_ro", "loader_type", - "nvram", "nvram_template", "kernel", "initrd", - "initdir", "inituser", "initgroup", - "kernel_args", "dtb", "bootdevs", "smbios_mode"] + ################## + # XML properties # + ################## - # BIOS bootloader + XML_NAME = "os" + _XML_PROP_ORDER = [ + "firmware", "os_type", "arch", "machine", "firmware_features", + "loader", "loader_ro", "loader_secure", "loader_type", + "nvram", "nvram_template", + "init", "initargs", "initenvs", "initdir", "inituser", "initgroup", + "kernel", "initrd", "kernel_args", "dtb", "acpi_tb", "acpi_tb_type", + "bootdevs", "bootmenu_enable", "bootmenu_timeout", + "bios_useserial", "bios_rebootTimeout", "smbios_mode"] + + # Shared/Generic boot options + os_type = XMLProperty("./type") + arch = XMLProperty("./type/@arch") + machine = XMLProperty("./type/@machine") + loader = XMLProperty("./loader") + loader_ro = XMLProperty("./loader/@readonly", is_yesno=True) + loader_type = XMLProperty("./loader/@type") + loader_secure = XMLProperty("./loader/@secure", is_yesno=True) + + # BIOS bootloader options def _get_bootorder(self): return [dev.dev for dev in self.bootdevs] def _set_bootorder(self, newdevs): @@ -96,18 +113,22 @@ class DomainOs(XMLBuilder): dev.dev = d bootorder = property(_get_bootorder, _set_bootorder) bootdevs = XMLChildProperty(_BootDevice) - smbios_mode = XMLProperty("./smbios/@mode") + firmware = XMLProperty("./@firmware") + firmware_features = XMLChildProperty(_FirmwareFeature, relative_xpath="./firmware") + nvram = XMLProperty("./nvram", do_abspath=True) + nvram_template = XMLProperty("./nvram/@template") bootmenu_enable = XMLProperty("./bootmenu/@enable", is_yesno=True) bootmenu_timeout = XMLProperty("./bootmenu/@timeout", is_int=True) - bios_rebootTimeout = XMLProperty("./bios/@rebootTimeout", is_int=True) bios_useserial = XMLProperty("./bios/@useserial", is_yesno=True) + bios_rebootTimeout = XMLProperty("./bios/@rebootTimeout", is_int=True) + smbios_mode = XMLProperty("./smbios/@mode") - # Host bootloader + # Host bootloader options # Since the elements for a host bootloader are actually directly under # rather than , they are handled via callbacks in # the CLI. This is just a placeholder to remind of that fact. - # Direct kernel boot + # Direct kernel boot options kernel = XMLProperty("./kernel", do_abspath=True) initrd = XMLProperty("./initrd", do_abspath=True) kernel_args = XMLProperty("./cmdline") @@ -115,7 +136,7 @@ class DomainOs(XMLBuilder): acpi_tb = XMLProperty("./acpi/table", do_abspath=True) acpi_tb_type = XMLProperty("./acpi/table/@type") - # Container boot + # Container boot options init = XMLProperty("./init") initargs = XMLChildProperty(_InitArg) initenvs = XMLChildProperty(_InitEnv) @@ -130,18 +151,6 @@ class DomainOs(XMLBuilder): obj = self.initargs.add_new() obj.val = val - loader = XMLProperty("./loader") - loader_ro = XMLProperty("./loader/@readonly", is_yesno=True) - loader_type = XMLProperty("./loader/@type") - loader_secure = XMLProperty("./loader/@secure", is_yesno=True) - nvram = XMLProperty("./nvram", do_abspath=True) - nvram_template = XMLProperty("./nvram/@template") - arch = XMLProperty("./type/@arch") - machine = XMLProperty("./type/@machine") - os_type = XMLProperty("./type") - firmware = XMLProperty("./@firmware") - firmware_features = XMLChildProperty(_FirmwareFeature, relative_xpath="./firmware") - ################## # Default config #