From 468f9758e5e1ba2a555cccee0a57b201c9dd021f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 7 Aug 2020 13:45:10 -0400 Subject: [PATCH] Fix update boot update boot would leave leftover content, truncate to get rid of it. --- confluent_server/confluent/core.py | 4 +++- confluent_server/confluent/osimage.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index 90b0097d..95df692b 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -169,8 +169,10 @@ def handle_deployment(configmanager, inputdata, pathcomponents, return if len(pathcomponents) == 3: profname = pathcomponents[-1] - if 'operation' == 'update': + if operation == 'update' and 'updateboot' in inputdata: osimage.update_boot(profname) + yield msg.KeyValueData({'updated': profname}) + return if pathcomponents[1] == 'importing': if len(pathcomponents) == 2 or not pathcomponents[-1]: if operation == 'retrieve': diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 685256ea..cd660a6d 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -90,13 +90,13 @@ def update_boot_esxi(profiledir, profile, label): newbootcfg += cfgline + '\n' efibootcfg += cfgline + '\n' os.makedirs('{0}/boot/efi/boot/'.format(profiledir), 0o755) - bcfgout = os.open('{0}/boot/efi/boot/boot.cfg'.format(profiledir), os.O_WRONLY|os.O_CREAT, 0o644) + bcfgout = os.open('{0}/boot/efi/boot/boot.cfg'.format(profiledir), os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o644) bcfg = os.fdopen(bcfgout, 'w') try: bcfg.write(efibootcfg) finally: bcfg.close() - bcfgout = os.open('{0}/boot/boot.cfg'.format(profiledir), os.O_WRONLY|os.O_CREAT, 0o644) + bcfgout = os.open('{0}/boot/boot.cfg'.format(profiledir), os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o644) bcfg = os.fdopen(bcfgout, 'w') try: bcfg.write(newbootcfg) @@ -112,7 +112,7 @@ def update_boot_esxi(profiledir, profile, label): sourcefile = '{0}/distribution/{1}'.format(profiledir, fn.upper()) os.symlink(sourcefile, '{0}/boot/{1}'.format(profiledir, fn)) os.symlink('{0}/distribution/EFI/BOOT/BOOTX64.EFI'.format(profiledir), '{0}/boot/efi/boot/bootx64.efi'.format(profiledir)) - ipout = os.open(profiledir + '/boot.ipxe', os.O_WRONLY|os.O_CREAT, 0o644) + ipout = os.open(profiledir + '/boot.ipxe', os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o644) ipxeout = os.fdopen(ipout, 'w') try: os.umask(oum) @@ -149,7 +149,7 @@ def update_boot_linux(profiledir, profile, label): for initramfs in initrds: ipxeargs += " initrd=" + initramfs oum = os.umask(0o22) - ipout = os.open(profiledir + '/boot.ipxe', os.O_WRONLY|os.O_CREAT, 0o644) + ipout = os.open(profiledir + '/boot.ipxe', os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o644) ipxeout = os.fdopen(ipout, 'w') try: os.umask(oum)