From af8429ebf9527acb6b5454f9c510198fea363970 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 26 Oct 2020 12:22:56 -0400 Subject: [PATCH] Fix esxi updateboot Updateboot was confounded by a normal of 'file exists' problems. --- confluent_server/confluent/osimage.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index cd660a6d..072303e3 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -40,6 +40,22 @@ from libarchive.ffi import ( def relax_umask(): os.umask(0o22) + +def makedirs(path, mode): + try: + os.makedirs(path, 0o755) + except OSError as e: + if e.errno != 17: + raise + +def symlink(src, targ): + try: + os.symlink(src, targ) + except OSError as e: + if e.errno != 17: + raise + + def update_boot(profilename): if profilename.startswith('/var/lib/confluent/public'): profiledir = profilename @@ -89,7 +105,7 @@ def update_boot_esxi(profiledir, profile, label): else: newbootcfg += cfgline + '\n' efibootcfg += cfgline + '\n' - os.makedirs('{0}/boot/efi/boot/'.format(profiledir), 0o755) + 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|os.O_TRUNC, 0o644) bcfg = os.fdopen(bcfgout, 'w') try: @@ -102,7 +118,7 @@ def update_boot_esxi(profiledir, profile, label): bcfg.write(newbootcfg) finally: bcfg.close() - os.symlink('/var/lib/confluent/public/site/initramfs.tgz', + symlink('/var/lib/confluent/public/site/initramfs.tgz', '{0}/boot/site.tgz'.format(profiledir)) for fn in filesneeded: if fn.startswith('/'): @@ -110,8 +126,8 @@ def update_boot_esxi(profiledir, profile, label): sourcefile = '{0}/distribution/{1}'.format(profiledir, fn) if not os.path.exists(sourcefile): 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)) + symlink(sourcefile, '{0}/boot/{1}'.format(profiledir, fn)) + 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|os.O_TRUNC, 0o644) ipxeout = os.fdopen(ipout, 'w') try: