diff options
author | Lihong <lihongx.sun@intel.com> | 2014-11-10 22:26:44 -0500 |
---|---|---|
committer | Lihong Sun <lihongx.sun@intel.com> | 2015-01-21 04:36:32 -0500 |
commit | 96c3236aea063b13d693e727da061bcbd8d4e097 (patch) | |
tree | 866fce6216402fcc51d0fd4aa00d05bad12ddfe0 | |
parent | b21bcdf33b51838cea3e175e84cf203568c5501d (diff) | |
download | mic-96c3236aea063b13d693e727da061bcbd8d4e097.tar.gz mic-96c3236aea063b13d693e727da061bcbd8d4e097.tar.bz2 mic-96c3236aea063b13d693e727da061bcbd8d4e097.zip |
Put log file in 'release' output always.
When image creation failed, log created by '--release' will be
located under 'outdir' instead of 'release_dir'. Also put the
log file under 'release_dir' when image creation failed.
mic-appliance create images through executing '/etc/init.d/mic'
script in the appliance. 'time mic cr auto $extra /media/out/$ks'
is called, and '--release' option is used when creating images.
In the past, 3 points about the logfile created by '--release':
1. Create logfile in default 'out_dir' which is specified in
'/etc/mic/mic.conf'. 2. Before creating images, check whether the
'release_dir' exists, if it exists, remove the whole directory. 3.
After the image creation finished, copy the logfile to the final
'release_dir' where the images located. So when the image creation
failed, no logfile found in 'release_dir', the logfile is under default
'out_dir'.
If directly change the 'out_dir' to 'dest_dir' in conf.py, the image
creation will fail if there already exist a same 'release_dir', because
this existed 'release_dir' will be removed when creating images, but the
logfile use this dir at the time, so it cannot be removed, then mic will
fail and exit. So right now, if 'release_dir' already existed, just remove
the files under it except the newly created logfile, and remain the dir.
Fixes: #2212
Change-Id: Ibdc9af3d0e03ca966517d05b1e519d4d9fb3ad43
-rw-r--r-- | mic/conf.py | 2 | ||||
-rw-r--r-- | mic/imager/baseimager.py | 3 | ||||
-rw-r--r-- | mic/pluginbase.py | 9 |
3 files changed, 7 insertions, 7 deletions
diff --git a/mic/conf.py b/mic/conf.py index 9816245..742fcd5 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -217,7 +217,7 @@ class ConfigMgr(object): self.create['name'] = self.create['release'] + '_' + self.create['name'] if not self.create['logfile']: - self.create['logfile'] = os.path.join(self.create['outdir'], + self.create['logfile'] = os.path.join(self.create['destdir'], self.create['name'] + ".log") self.create['releaselog'] = True self.set_logfile() diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 09499c2..5f7b014 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1290,9 +1290,6 @@ class BaseImageCreator(object): # save log file, logfile is only available in creator attrs if hasattr(self, 'releaselog') and self.releaselog: - final_logfile = _rpath(self.name+'.log') - shutil.move(self.logfile, final_logfile) - self.logfile = final_logfile outimages.append(self.logfile) # rename iso and usbimg diff --git a/mic/pluginbase.py b/mic/pluginbase.py index ef4dcde..541ac8a 100644 --- a/mic/pluginbase.py +++ b/mic/pluginbase.py @@ -64,11 +64,14 @@ class ImagerPlugin(_Plugin): image = os.path.join(destdir, name) if not os.path.exists(image): continue - if msger.ask("Target image/dir: %s already exists, " - "clean up and continue?" % image): + "clean up the old files and continue?" % image): if os.path.isdir(image): - shutil.rmtree(image) + for path, dirs, files in os.walk(os.path.abspath(image)): + for fname in files: + fpath = os.path.join(path, fname) + if not fpath.endswith('.log'): + os.remove(fpath) else: os.unlink(image) else: |