From 241800b1c9dd09f435662a58ff73739f3248a00c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 16 Feb 2023 09:13:05 -0500 Subject: [PATCH] Restore filename-only import The open file handle as implemented could not pass to the subprocess. Rather than figure out how to open and pass the filehandle, simply let the subprocess independently open the file if it isn't passed. --- confluent_server/confluent/osimage.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index bc61bbb5..7de5efe3 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -805,11 +805,17 @@ class MediaImporter(object): raise Exception('`osdeploy initialize` must be executed before importing any media') self.profiles = [] medfile = None + self.medfile = None if cfm and media in cfm.clientfiles: - medfile = cfm.clientfiles[media] + self.medfile = cfm.clientfiles[media] + medfile = self.medfile else: medfile = open(media, 'rb') - identity = fingerprint(medfile) + try: + identity = fingerprint(medfile) + finally: + if not self.medfile: + medfile.close() if not identity: raise exc.InvalidArgumentException('Unsupported Media') self.percent = 0.0 @@ -837,7 +843,6 @@ class MediaImporter(object): del importing[importkey] raise Exception('{0} already exists'.format(self.targpath)) self.filename = os.path.abspath(media) - self.medfile = medfile self.error = '' self.importer = eventlet.spawn(self.importmedia) @@ -851,7 +856,8 @@ class MediaImporter(object): def importmedia(self): os.environ['PYTHONPATH'] = ':'.join(sys.path) - os.environ['CONFLUENT_MEDIAFD'] = '{0}'.format(self.medfile.fileno()) + if self.medfile: + os.environ['CONFLUENT_MEDIAFD'] = '{0}'.format(self.medfile.fileno()) with open(os.devnull, 'w') as devnull: self.worker = subprocess.Popen( [sys.executable, __file__, self.filename, '-b'],