def test_update(self): """BootLoaderArguments.update reorders things as expected.""" args = BootLoaderArguments() args.update(["one", "two", "three"]) args.update("abc") self.assertEqual(str(args), "one two three a b c") args.update(["three", "two"]) self.assertEqual(str(args), "one a b c three two")
def test_add(self): """BootLoaderArguments.add reorders things as expected.""" args = BootLoaderArguments() args.add("first") args.add("second") self.assertEqual(str(args), "first second") self.assertEqual(list(args), ["first", "second"]) args.add("first") self.assertEqual(str(args), "second first") self.assertEqual(list(args), ["second", "first"])
def test_add(self): """BootLoaderArguments.add reorders things as expected.""" args = BootLoaderArguments() args.add("first") args.add("second") assert str(args) == "first second" assert list(args) == ["first", "second"] args.add("first") assert str(args) == "second first" assert list(args) == ["second", "first"]
def test_ip_merge(self): """BootLoaderArguments.__str__ reorders ip= as expected.""" args = BootLoaderArguments() args.update(["start", "blah"]) args.update( ["ip=ens0p3:dhcp6", "ip=::::tester::dhcp", "ip=ens0p3:dhcp"]) args.add("end") assert list(args) == \ ["start", "blah", "ip=ens0p3:dhcp6", "ip=::::tester::dhcp", "ip=ens0p3:dhcp", "end"] assert str(args) == \ "start blah ip=::::tester::dhcp end ip=ens0p3:dhcp,dhcp6" assert list(args) == \ ["start", "blah", "ip=::::tester::dhcp", "end", "ip=ens0p3:dhcp,dhcp6"]
def write_config_images(self, config): for image in self.images: if "kdump" in (image.initrd or image.kernel): # no need to create bootloader entries for kdump continue args = BootLoaderArguments() args.add("root=%s" % image.device.fstab_spec) args.update(self.boot_args) if image.device.type == "btrfs subvolume": args.add("rootflags=subvol=%s" % image.device.name) log.info("bootloader.py: used boot args: %s ", args) if self.use_bls: self.update_bls_args(image, args) else: self.write_config_image(config, image, args)
def ip_merge_test(self): """BootLoaderArguments.__str__ reorders ip= as expected.""" args = BootLoaderArguments() args.update(["start", "blah"]) args.update( ["ip=ens0p3:dhcp6", "ip=::::tester::dhcp", "ip=ens0p3:dhcp"]) args.add("end") self.assertEqual(list(args), [ "start", "blah", "ip=ens0p3:dhcp6", "ip=::::tester::dhcp", "ip=ens0p3:dhcp", "end" ]) self.assertEqual( str(args), "start blah ip=::::tester::dhcp end ip=ens0p3:dhcp,dhcp6") self.assertEqual(list(args), [ "start", "blah", "ip=::::tester::dhcp", "end", "ip=ens0p3:dhcp,dhcp6" ])
def write_config_images(self, config): self.write_config_console(config) for image in self.images: args = BootLoaderArguments() args.update(["root=%s" % image.device.fstab_spec, "ro"]) if image.device.type == "btrfs subvolume": args.add("rootflags=subvol=%s" % image.device.name) args.update(self.boot_args) log.info("bootloader.py: used boot args: %s ", args) # extlinux labels cannot have spaces label = "%s(%s)" % (self.image_label(image), image.version) label = label.replace(" ", "") stanza = ("label %(label)s\n" "\tkernel %(boot_prefix)s/%(kernel)s\n" "\tinitrd %(boot_prefix)s/%(initrd)s\n" "\tappend %(args)s\n\n" % { "label": label, "kernel": image.kernel, "initrd": image.initrd, "args": args, "boot_prefix": self.boot_prefix }) config.write(stanza)