From 20739262563aea75c59aa14044c59b8e25f11be4 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 27 May 2021 16:10:06 -0400 Subject: [PATCH] Improve ctrl-c and other behaviors of osdeploy import More reliably delete an import attempt to avoid odd behaviors. --- confluent_server/bin/osdeploy | 34 ++++++++++++++------------- confluent_server/confluent/osimage.py | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/confluent_server/bin/osdeploy b/confluent_server/bin/osdeploy index 779966ac..88697fce 100644 --- a/confluent_server/bin/osdeploy +++ b/confluent_server/bin/osdeploy @@ -361,22 +361,24 @@ def osimport(imagefile): print('Importing from {0} to {1}'.format(imagefile, rsp['target'])) else: print(repr(rsp)) - while importing: - for rsp in c.read('/deployment/importing/{0}'.format(shortname)): - if 'progress' in rsp: - sys.stdout.write('{0}: {1:.2f}% \r'.format(rsp['phase'], - rsp['progress'])) - if rsp['phase'] == 'complete': - importing = False - sys.stdout.write('\n') - for profile in rsp['profiles']: - print('Deployment profile created: {0}'.format(profile)) - sys.stdout.flush() - else: - print(repr(rsp)) - time.sleep(0.5) - if shortname: - list(c.delete('/deployment/importing/{0}'.format(shortname))) + try: + while importing: + for rsp in c.read('/deployment/importing/{0}'.format(shortname)): + if 'progress' in rsp: + sys.stdout.write('{0}: {1:.2f}% \r'.format(rsp['phase'], + rsp['progress'])) + if rsp['phase'] == 'complete': + importing = False + sys.stdout.write('\n') + for profile in rsp['profiles']: + print('Deployment profile created: {0}'.format(profile)) + sys.stdout.flush() + else: + print(repr(rsp)) + time.sleep(0.5) + finally: + if shortname: + list(c.delete('/deployment/importing/{0}'.format(shortname))) if __name__ == '__main__': main(sys.argv) diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 6db8820e..88127db0 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -703,6 +703,7 @@ class MediaImporter(object): targpath += '/' + identity['subname'] self.targpath = '/var/lib/confluent/distributions/' + targpath if os.path.exists(self.targpath): + del importing[importkey] raise Exception('{0} already exists'.format(self.targpath)) self.filename = os.path.abspath(media) self.medfile = medfile