Merge pull request #2 from geaaru/master
Fix PEP08 and removed unused import
This commit is contained in:
+27
-28
@@ -19,12 +19,10 @@
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import glob
|
||||
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.i18n import _
|
||||
from molecule.output import red, brown, blue, green, purple, darkgreen, \
|
||||
darkred, bold, darkblue, readtext
|
||||
from molecule.output import blue, darkred
|
||||
from molecule.specs.skel import GenericExecutionStep, GenericSpec
|
||||
|
||||
import molecule.utils
|
||||
@@ -42,7 +40,7 @@ class BuiltinHandlerMixin(object):
|
||||
os.environ['PRECHROOT'] = ' '.join(self.metadata.get('prechroot', []))
|
||||
|
||||
def _run_error_script(self, source_chroot_dir, chroot_dir, cdroot_dir,
|
||||
env = None):
|
||||
env=None):
|
||||
|
||||
error_script = self.metadata.get('error_script')
|
||||
if error_script:
|
||||
@@ -63,14 +61,14 @@ class BuiltinHandlerMixin(object):
|
||||
_("spawning"), " ".join(error_script),
|
||||
)
|
||||
)
|
||||
molecule.utils.exec_cmd(error_script, env = env)
|
||||
molecule.utils.exec_cmd(error_script, env=env)
|
||||
|
||||
def _exec_inner_script(self, exec_script, dest_chroot):
|
||||
|
||||
source_exec = exec_script[0]
|
||||
with open(source_exec, "rb") as f_src:
|
||||
tmp_fd, tmp_exec = tempfile.mkstemp(dir = dest_chroot,
|
||||
prefix = "molecule_inner")
|
||||
tmp_fd, tmp_exec = tempfile.mkstemp(dir=dest_chroot,
|
||||
prefix="molecule_inner")
|
||||
f_dst = os.fdopen(tmp_fd, "wb")
|
||||
try:
|
||||
shutil.copyfileobj(f_src, f_dst)
|
||||
@@ -84,19 +82,22 @@ class BuiltinHandlerMixin(object):
|
||||
if not dest_exec.startswith("/"):
|
||||
dest_exec = "/%s" % (dest_exec,)
|
||||
|
||||
rc = 0
|
||||
try:
|
||||
rc = molecule.utils.exec_chroot_cmd([dest_exec] + exec_script[1:],
|
||||
dest_chroot, pre_chroot = self.metadata.get('prechroot', []))
|
||||
except:
|
||||
rc = molecule.utils.exec_chroot_cmd(
|
||||
[dest_exec] + exec_script[1:],
|
||||
dest_chroot,
|
||||
pre_chroot=self.metadata.get('prechroot', [])
|
||||
)
|
||||
|
||||
except Exception:
|
||||
# kill all the pids inside chroot, no matter what just happened
|
||||
molecule.utils.kill_chroot_pids(dest_chroot, sleep = True)
|
||||
molecule.utils.kill_chroot_pids(dest_chroot, sleep=True)
|
||||
raise
|
||||
finally:
|
||||
os.remove(tmp_exec)
|
||||
|
||||
if rc != 0:
|
||||
molecule.utils.kill_chroot_pids(dest_chroot, sleep = True)
|
||||
molecule.utils.kill_chroot_pids(dest_chroot, sleep=True)
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("BuiltinHandler"), darkred(self.spec_name),
|
||||
_("inner chroot hook failed"), rc,
|
||||
@@ -138,7 +139,7 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
exec_script = self.metadata.get('inner_source_chroot_script')
|
||||
if exec_script:
|
||||
if os.path.isfile(exec_script[0]) and \
|
||||
os.access(exec_script[0], os.R_OK):
|
||||
os.access(exec_script[0], os.R_OK):
|
||||
rc = self._exec_inner_script(exec_script, self.source_dir)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
@@ -148,7 +149,6 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
return rc
|
||||
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("pre_run completed successfully"),
|
||||
@@ -165,7 +165,7 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
self._run_error_script(self.source_dir, self.dest_dir, None)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
@@ -241,7 +241,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
@@ -340,7 +340,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
@@ -351,7 +351,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
self._run_error_script(self.source_dir, self.dest_dir, None)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
@@ -377,7 +377,6 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks completed succesfully"),
|
||||
@@ -433,10 +432,10 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
self._run_error_script(None, self.source_chroot,
|
||||
self.dest_root)
|
||||
self.dest_root)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
@@ -590,7 +589,7 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
@@ -619,7 +618,7 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
@@ -630,10 +629,10 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
self._run_error_script(self.source_chroot, self.chroot_dir,
|
||||
self.source_path)
|
||||
self.source_path)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
@@ -716,8 +715,8 @@ class LivecdSpec(GenericSpec):
|
||||
'parser': self._command_splitter,
|
||||
},
|
||||
'release_string': {
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
},
|
||||
'release_version': {
|
||||
'verifier': lambda x: len(x) != 0,
|
||||
|
||||
+55
-40
@@ -73,8 +73,8 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
return sts
|
||||
try:
|
||||
self._tmp_loop_device_fd, self.tmp_loop_device_file = \
|
||||
tempfile.mkstemp(prefix = "molecule", dir = self._config['tmp_dir'])
|
||||
except (OSError, IOError,) as err:
|
||||
tempfile.mkstemp(prefix="molecule", dir=self._config['tmp_dir'])
|
||||
except (OSError, IOError,):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
_("setup hook failed"), _("cannot create temporary file"),
|
||||
@@ -84,7 +84,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
# bind loop device
|
||||
args = [ImageHandler.LOSETUP_EXEC, loop_device,
|
||||
self.tmp_loop_device_file]
|
||||
self.tmp_loop_device_file]
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
@@ -124,7 +124,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
@@ -215,8 +215,10 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
return 1
|
||||
|
||||
# format image file
|
||||
image_formatter = self.metadata.get('image_formatter',
|
||||
ImageHandler.DEFAULT_IMAGE_FORMATTER)
|
||||
image_formatter = self.metadata.get(
|
||||
'image_formatter',
|
||||
ImageHandler.DEFAULT_IMAGE_FORMATTER
|
||||
)
|
||||
formatter_args = image_formatter + [self.loop_device]
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
@@ -233,8 +235,10 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
return rc
|
||||
|
||||
# mount image file
|
||||
mounter = self.metadata.get('image_mounter',
|
||||
ImageHandler.DEFAULT_IMAGE_MOUNTER)
|
||||
mounter = self.metadata.get(
|
||||
'image_mounter',
|
||||
ImageHandler.DEFAULT_IMAGE_MOUNTER
|
||||
)
|
||||
mount_args = mounter + [self.loop_device, self.tmp_image_mount]
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
@@ -257,16 +261,19 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
""" Nothing to do """
|
||||
return 0
|
||||
|
||||
def _kill_loop_device(self, preserve_loop_device_file = False):
|
||||
def _kill_loop_device(self, preserve_loop_device_file=False):
|
||||
|
||||
kill_rc = 0
|
||||
if self.image_mounted:
|
||||
umounter = self.metadata.get('image_umounter',
|
||||
ImageHandler.DEFAULT_IMAGE_UMOUNTER)
|
||||
umounter = self.metadata.get(
|
||||
'image_umounter',
|
||||
ImageHandler.DEFAULT_IMAGE_UMOUNTER
|
||||
)
|
||||
args = umounter + [self.tmp_image_mount]
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
_("unable to umount loop device"), self.loop_device,
|
||||
)
|
||||
@@ -284,7 +291,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
# kill loop device
|
||||
if self.loop_device is not None:
|
||||
rc = molecule.utils.exec_cmd([ImageHandler.LOSETUP_EXEC, "-d",
|
||||
self.loop_device])
|
||||
self.loop_device])
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
@@ -296,7 +303,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
self.loop_device = None
|
||||
|
||||
if (self.tmp_loop_device_file is not None) and \
|
||||
(not preserve_loop_device_file):
|
||||
(not preserve_loop_device_file):
|
||||
try:
|
||||
os.remove(self.tmp_loop_device_file)
|
||||
self.tmp_loop_device_file = None
|
||||
@@ -311,7 +318,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
return kill_rc
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
|
||||
# kill tmp files
|
||||
if self._tmp_loop_device_fd is not None:
|
||||
@@ -328,7 +335,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if not success:
|
||||
env = os.environ.copy()
|
||||
env["LOOP_DEVICE"] = self.loop_device
|
||||
self._run_error_script(None, None, None, env = env)
|
||||
self._run_error_script(None, None, None, env=env)
|
||||
self._kill_loop_device()
|
||||
|
||||
return 0
|
||||
@@ -338,7 +345,7 @@ class ImageIsoUnpackHandler(RemasterIsoUnpackHandler):
|
||||
|
||||
def setup(self):
|
||||
|
||||
unpack_prefix = molecule.utils.mkdtemp(suffix = "chroot")
|
||||
unpack_prefix = molecule.utils.mkdtemp(suffix="chroot")
|
||||
|
||||
self.metadata['chroot_tmp_dir'] = unpack_prefix
|
||||
self.metadata['chroot_unpack_path'] = \
|
||||
@@ -368,9 +375,11 @@ class ImageIsoUnpackHandler(RemasterIsoUnpackHandler):
|
||||
# copy data into chroot, in our case, destination dir already
|
||||
# exists, so copy_dir() is a bit tricky
|
||||
try:
|
||||
rc = molecule.utils.copy_dir_existing_dest(self.tmp_squash_mount,
|
||||
self.metadata['chroot_unpack_path'])
|
||||
except:
|
||||
rc = molecule.utils.copy_dir_existing_dest(
|
||||
self.tmp_squash_mount,
|
||||
self.metadata['chroot_unpack_path']
|
||||
)
|
||||
except Exception:
|
||||
dorm()
|
||||
raise
|
||||
|
||||
@@ -379,11 +388,11 @@ class ImageIsoUnpackHandler(RemasterIsoUnpackHandler):
|
||||
|
||||
return rc
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
# ImageHandler sets this
|
||||
if not success:
|
||||
self.metadata['ImageHandler_kill_loop_device']()
|
||||
RemasterIsoUnpackHandler.kill(self, success = success)
|
||||
RemasterIsoUnpackHandler.kill(self, success=success)
|
||||
|
||||
# we don't need the whole dir
|
||||
tmp_dir = self.metadata['chroot_tmp_dir']
|
||||
@@ -391,7 +400,8 @@ class ImageIsoUnpackHandler(RemasterIsoUnpackHandler):
|
||||
try:
|
||||
shutil.rmtree(tmp_dir, True)
|
||||
except (shutil.Error, OSError,):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("ImageIsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("unable to remove temp. dir"), tmp_dir,
|
||||
)
|
||||
@@ -408,8 +418,9 @@ class ImageChrootHandler(RemasterChrootHandler):
|
||||
self.dest_dir = self.source_dir
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
def kill(self, success=True):
|
||||
self._output.output(
|
||||
"[%s|%s] %s" % (
|
||||
blue("ImageChrootHandler"),
|
||||
darkred(self.spec_name), _("executing kill"),
|
||||
)
|
||||
@@ -420,7 +431,7 @@ class ImageChrootHandler(RemasterChrootHandler):
|
||||
if loop_device is not None:
|
||||
env["LOOP_DEVICE"] = loop_device
|
||||
self._run_error_script(self.source_dir, self.dest_dir, None,
|
||||
env = env)
|
||||
env=env)
|
||||
self.metadata['ImageHandler_kill_loop_device']()
|
||||
return 0
|
||||
|
||||
@@ -442,19 +453,21 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
self.metadata['ImageHandler_loop_device_file']
|
||||
# umount all, but don't remove our loop device file
|
||||
kill_rc = self.metadata['ImageHandler_kill_loop_device'](
|
||||
preserve_loop_device_file = True)
|
||||
preserve_loop_device_file=True
|
||||
)
|
||||
if kill_rc:
|
||||
self._loop_device_killed = True
|
||||
|
||||
image_name = self.metadata.get('image_name',
|
||||
os.path.basename(self.metadata['source_iso']) + \
|
||||
FinalImageHandler.IMAGE_EXT)
|
||||
image_name = self.metadata.get(
|
||||
'image_name',
|
||||
os.path.basename(self.metadata['source_iso']) +
|
||||
FinalImageHandler.IMAGE_EXT)
|
||||
self.dest_path = os.path.join(
|
||||
self.metadata['destination_image_directory'], image_name)
|
||||
|
||||
dest_path_dir = os.path.dirname(self.dest_path)
|
||||
if (not os.path.lexists(dest_path_dir)) and \
|
||||
(not os.path.isdir(dest_path_dir)):
|
||||
(not os.path.isdir(dest_path_dir)):
|
||||
os.makedirs(dest_path_dir, 0o755)
|
||||
|
||||
return 0
|
||||
@@ -497,7 +510,7 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
md5file = self.dest_path + FinalImageHandler.MD5_EXT
|
||||
with open(md5file, "w") as f:
|
||||
f.write("%s %s\n" % (digest,
|
||||
os.path.basename(self.dest_path),))
|
||||
os.path.basename(self.dest_path),))
|
||||
f.flush()
|
||||
|
||||
def post_run(self):
|
||||
@@ -513,9 +526,10 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("FinalImageHandler"), darkred(self.spec_name),
|
||||
_("post image hook failed"), rc,
|
||||
)
|
||||
@@ -523,14 +537,15 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
return rc
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
if not (self._loop_device_file_removed and \
|
||||
self._loop_device_killed):
|
||||
if not (self._loop_device_file_removed and
|
||||
self._loop_device_killed):
|
||||
self.metadata['ImageHandler_kill_loop_device']()
|
||||
""" Nothing to do """
|
||||
return 0
|
||||
|
||||
|
||||
class IsoToImageSpec(GenericSpec):
|
||||
|
||||
PLUGIN_API_VERSION = 1
|
||||
@@ -557,8 +572,8 @@ class IsoToImageSpec(GenericSpec):
|
||||
'parser': self._command_splitter,
|
||||
},
|
||||
'release_string': {
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
},
|
||||
'release_version': {
|
||||
'verifier': lambda x: len(x) != 0,
|
||||
@@ -684,4 +699,4 @@ class IsoToImageSpec(GenericSpec):
|
||||
|
||||
def execution_steps(self):
|
||||
return [ImageHandler, ImageIsoUnpackHandler, ImageChrootHandler,
|
||||
FinalImageHandler]
|
||||
FinalImageHandler]
|
||||
|
||||
+22
-20
@@ -60,7 +60,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
@@ -91,7 +91,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
@@ -102,7 +102,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
""" Nothing to do """
|
||||
return 0
|
||||
|
||||
@@ -123,8 +123,8 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks completed succesfully"),
|
||||
)
|
||||
@@ -153,10 +153,10 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
try:
|
||||
self._tmp_image_file_fd, self._tmp_image_file = \
|
||||
tempfile.mkstemp(prefix = "molecule",
|
||||
dir = self._config['tmp_dir'],
|
||||
tempfile.mkstemp(prefix="molecule",
|
||||
dir=self._config['tmp_dir'],
|
||||
suffix=".mmc_img")
|
||||
except (OSError, IOError,) as err:
|
||||
except (OSError, IOError,):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
_("setup hook failed"), _("cannot create temporary file"),
|
||||
@@ -187,9 +187,10 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
_("pre image hook failed"), rc,
|
||||
)
|
||||
@@ -233,7 +234,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ImageHandler"), darkred(self.spec_name),
|
||||
@@ -248,7 +249,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
""" Nothing to run """
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
|
||||
# kill tmp files
|
||||
if self._tmp_image_file_fd is not None:
|
||||
@@ -264,7 +265,7 @@ class ImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
if not success:
|
||||
env = os.environ.copy()
|
||||
self._run_error_script(None, None, None, env = env)
|
||||
self._run_error_script(None, None, None, env=env)
|
||||
if self._tmp_image_file is not None:
|
||||
os.remove(self._tmp_image_file)
|
||||
self._tmp_image_file = None
|
||||
@@ -295,7 +296,7 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
dest_path_dir = os.path.dirname(self.dest_path)
|
||||
if (not os.path.lexists(dest_path_dir)) and \
|
||||
(not os.path.isdir(dest_path_dir)):
|
||||
(not os.path.isdir(dest_path_dir)):
|
||||
os.makedirs(dest_path_dir, 0o755)
|
||||
|
||||
return 0
|
||||
@@ -338,7 +339,7 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
md5file = self.dest_path + FinalImageHandler.MD5_EXT
|
||||
with open(md5file, "w") as f:
|
||||
f.write("%s %s\n" % (digest,
|
||||
os.path.basename(self.dest_path),))
|
||||
os.path.basename(self.dest_path),))
|
||||
f.flush()
|
||||
|
||||
def post_run(self):
|
||||
@@ -346,7 +347,7 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
exec_script = self.metadata.get('post_image_script')
|
||||
if exec_script:
|
||||
env = os.environ.copy()
|
||||
env['IMAGE_NAME'] = self.image_name # self.metadata['image_name']
|
||||
env['IMAGE_NAME'] = self.image_name # self.metadata['image_name']
|
||||
env['DESTINATION_IMAGE_DIR'] = self.dest_path
|
||||
# self.metadata['destination_image_directory']
|
||||
env['CHROOT_DIR'] = self.source_dir
|
||||
@@ -358,7 +359,7 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("FinalImageHandler"), darkred(self.spec_name),
|
||||
@@ -368,13 +369,14 @@ class FinalImageHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
return rc
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
if self._tmp_image_file is not None:
|
||||
if os.path.isfile(self._tmp_image_file):
|
||||
os.remove(self._tmp_image_file)
|
||||
return 0
|
||||
|
||||
|
||||
class ChrootToMmcImageSpec(GenericSpec):
|
||||
|
||||
PLUGIN_API_VERSION = 1
|
||||
@@ -420,8 +422,8 @@ class ChrootToMmcImageSpec(GenericSpec):
|
||||
'parser': self._command_splitter,
|
||||
},
|
||||
'release_string': {
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
},
|
||||
'release_version': {
|
||||
'verifier': lambda x: len(x) != 0,
|
||||
|
||||
+61
-46
@@ -17,12 +17,10 @@
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
from molecule.i18n import _
|
||||
from molecule.output import red, blue, green, purple, darkgreen, \
|
||||
darkred, bold, darkblue, readtext
|
||||
from molecule.output import blue, darkred
|
||||
from molecule.specs.skel import GenericExecutionStep, GenericSpec
|
||||
|
||||
import molecule.utils
|
||||
@@ -62,10 +60,12 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
# setup chroot unpack dir
|
||||
# can't use /tmp because it could be mounted with "special" options
|
||||
unpack_prefix = molecule.utils.mkdtemp(suffix = "chroot")
|
||||
unpack_prefix = molecule.utils.mkdtemp(suffix="chroot")
|
||||
self.metadata['chroot_tmp_dir'] = unpack_prefix
|
||||
self.metadata['chroot_unpack_path'] = os.path.join(unpack_prefix,
|
||||
"root")
|
||||
self.metadata['chroot_unpack_path'] = os.path.join(
|
||||
unpack_prefix,
|
||||
"root"
|
||||
)
|
||||
|
||||
# setup upcoming new chroot path
|
||||
self.dest_root = os.path.join(unpack_prefix, "cdroot")
|
||||
@@ -110,7 +110,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
# mount squash
|
||||
mounter = self.metadata.get('squash_mounter',
|
||||
self._squash_mounter)
|
||||
self._squash_mounter)
|
||||
|
||||
output_file = BuiltinCdrootHandler.chroot_compressor_output_file
|
||||
if "chroot_compressor_output_file" in self.metadata:
|
||||
@@ -151,8 +151,8 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
# create chroot path
|
||||
try:
|
||||
rc = molecule.utils.copy_dir(self.tmp_squash_mount,
|
||||
self.metadata['chroot_unpack_path'])
|
||||
except:
|
||||
self.metadata['chroot_unpack_path'])
|
||||
except Exception:
|
||||
dorm()
|
||||
raise
|
||||
|
||||
@@ -169,7 +169,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
@@ -182,7 +182,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
rc = 0
|
||||
if self.squash_mounted:
|
||||
umounter = self.metadata.get('squash_umounter',
|
||||
self._squash_umounter)
|
||||
self._squash_umounter)
|
||||
args = umounter + [self.tmp_squash_mount]
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
|
||||
@@ -190,7 +190,8 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
try:
|
||||
os.rmdir(self.tmp_squash_mount)
|
||||
except OSError:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("unable to remove temp. dir"), self.tmp_squash_mount,
|
||||
)
|
||||
@@ -199,7 +200,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
rc = 0
|
||||
if self.iso_mounted:
|
||||
umounter = self.metadata.get('iso_umounter',
|
||||
self._iso_umounter)
|
||||
self._iso_umounter)
|
||||
args = umounter + [self.tmp_mount]
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
|
||||
@@ -208,7 +209,8 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
os.rmdir(self.tmp_mount)
|
||||
except OSError:
|
||||
# if not empty, skip
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("unable to remove temp. dir"), self.tmp_mount,
|
||||
)
|
||||
@@ -221,10 +223,10 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
shutil.rmtree(tmp_dir, True)
|
||||
except (shutil.Error, OSError,):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("unable to remove temp. dir"), tmp_dir,
|
||||
)
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("unable to remove temp. dir"), tmp_dir,
|
||||
)
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -241,8 +243,8 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
self.dest_dir = self.source_dir
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
BuiltinChrootHandler.kill(self, success = success)
|
||||
def kill(self, success=True):
|
||||
BuiltinChrootHandler.kill(self, success=success)
|
||||
if not success:
|
||||
try:
|
||||
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
|
||||
@@ -262,23 +264,26 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
'repositories_update_cmd',
|
||||
self._pkgs_updater)
|
||||
try:
|
||||
rc = molecule.utils.exec_chroot_cmd(update_cmd,
|
||||
rc = molecule.utils.exec_chroot_cmd(
|
||||
update_cmd,
|
||||
self.source_dir,
|
||||
pre_chroot = self.metadata.get('prechroot', []))
|
||||
except:
|
||||
pre_chroot=self.metadata.get('prechroot', [])
|
||||
)
|
||||
except Exception:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
raise
|
||||
if rc != 0:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
return rc
|
||||
|
||||
rc = BuiltinChrootHandler.run(self)
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s" % (
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks running"),
|
||||
)
|
||||
@@ -292,16 +297,18 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
self._pkgs_adder)
|
||||
args = add_cmd + packages_to_add
|
||||
try:
|
||||
rc = molecule.utils.exec_chroot_cmd(args,
|
||||
rc = molecule.utils.exec_chroot_cmd(
|
||||
args,
|
||||
self.source_dir,
|
||||
pre_chroot = self.metadata.get('prechroot', []))
|
||||
except:
|
||||
pre_chroot=self.metadata.get('prechroot', [])
|
||||
)
|
||||
except Exception:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
raise
|
||||
if rc != 0:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
return rc
|
||||
|
||||
packages_to_remove = self.metadata.get('packages_to_remove', [])
|
||||
@@ -311,23 +318,25 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
self._pkgs_remover)
|
||||
args = rm_cmd + packages_to_remove
|
||||
try:
|
||||
rc = molecule.utils.exec_chroot_cmd(args,
|
||||
rc = molecule.utils.exec_chroot_cmd(
|
||||
args,
|
||||
self.source_dir,
|
||||
pre_chroot = self.metadata.get('prechroot', []))
|
||||
except:
|
||||
pre_chroot=self.metadata.get('prechroot', [])
|
||||
)
|
||||
except Exception:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
raise
|
||||
if rc != 0:
|
||||
molecule.utils.kill_chroot_pids(self.source_dir,
|
||||
sleep = True)
|
||||
sleep=True)
|
||||
return rc
|
||||
|
||||
# run inner chroot script after pkgs handling
|
||||
exec_script = self.metadata.get('inner_chroot_script_after')
|
||||
if exec_script:
|
||||
if os.path.isfile(exec_script[0]) and \
|
||||
os.access(exec_script[0], os.R_OK):
|
||||
os.access(exec_script[0], os.R_OK):
|
||||
rc = self._exec_inner_script(exec_script, self.source_dir)
|
||||
if rc != 0:
|
||||
return rc
|
||||
@@ -342,8 +351,8 @@ class CdrootHandler(BuiltinCdrootHandler):
|
||||
self.source_chroot = self.metadata['chroot_unpack_path']
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
BuiltinCdrootHandler.kill(self, success = success)
|
||||
def kill(self, success=True):
|
||||
BuiltinCdrootHandler.kill(self, success=success)
|
||||
if not success:
|
||||
try:
|
||||
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
|
||||
@@ -351,22 +360,28 @@ class CdrootHandler(BuiltinCdrootHandler):
|
||||
pass
|
||||
return 0
|
||||
|
||||
|
||||
class IsoHandler(BuiltinIsoHandler):
|
||||
|
||||
def setup(self):
|
||||
# cdroot dir
|
||||
self.source_path = self.metadata['cdroot_path']
|
||||
dest_iso_filename = self.metadata.get('destination_iso_image_name',
|
||||
"remaster_" + os.path.basename(self.metadata['source_iso']))
|
||||
dest_iso_filename = self.metadata.get(
|
||||
'destination_iso_image_name',
|
||||
"remaster_" + os.path.basename(self.metadata['source_iso'])
|
||||
)
|
||||
self.dest_iso = os.path.join(self.metadata['destination_iso_directory'],
|
||||
dest_iso_filename)
|
||||
self.iso_title = self.metadata.get('iso_title', 'Molecule remaster')
|
||||
dest_iso_filename)
|
||||
self.iso_title = \
|
||||
os.getenv('MOLECULE_ISO_TITLE',
|
||||
self.metadata.get('iso_title', 'Molecule remaster')
|
||||
)
|
||||
self.source_chroot = self.metadata['chroot_unpack_path']
|
||||
self.chroot_dir = self.source_chroot
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
BuiltinIsoHandler.kill(self, success = success)
|
||||
def kill(self, success=True):
|
||||
BuiltinIsoHandler.kill(self, success=success)
|
||||
try:
|
||||
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
|
||||
except (shutil.Error, OSError,):
|
||||
@@ -399,8 +414,8 @@ class RemasterSpec(GenericSpec):
|
||||
'parser': self._command_splitter,
|
||||
},
|
||||
'release_string': {
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
},
|
||||
'release_version': {
|
||||
'verifier': lambda x: len(x) != 0,
|
||||
|
||||
+18
-12
@@ -29,6 +29,7 @@ import molecule.utils
|
||||
|
||||
SUPPORTED_COMPRESSION_METHODS = ["bz2", "gz"]
|
||||
|
||||
|
||||
class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
_TAR_EXEC = "/bin/tar"
|
||||
@@ -48,9 +49,11 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def setup(self):
|
||||
# setup compression method, default is gz
|
||||
tar_name = self.metadata.get('tar_name',
|
||||
os.path.basename(self.metadata['source_iso']) + ".tar." + \
|
||||
self.metadata.get('compression_method', "gz"))
|
||||
tar_name = self.metadata.get(
|
||||
'tar_name',
|
||||
os.path.basename(self.metadata['source_iso']) + ".tar." +
|
||||
self.metadata.get('compression_method', "gz")
|
||||
)
|
||||
self.dest_path = os.path.join(
|
||||
self.metadata['destination_tar_directory'], tar_name)
|
||||
self.chroot_path = self.metadata['chroot_unpack_path']
|
||||
@@ -76,9 +79,10 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
self._output.output(
|
||||
"[%s|%s] %s: %s" % (
|
||||
blue("TarHandler"), darkred(self.spec_name),
|
||||
_("pre tar hook failed"), rc,
|
||||
)
|
||||
@@ -96,7 +100,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
dest_path_dir = os.path.dirname(self.dest_path)
|
||||
if not os.path.isdir(dest_path_dir) and not \
|
||||
os.path.lexists(dest_path_dir):
|
||||
os.path.lexists(dest_path_dir):
|
||||
os.makedirs(dest_path_dir, 0o755)
|
||||
|
||||
current_dir = os.getcwd()
|
||||
@@ -104,7 +108,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
os.chdir(self.chroot_path)
|
||||
|
||||
args = (TarHandler._TAR_EXEC, "cfp" + self._get_tar_comp_method(),
|
||||
self.dest_path, ".", "--atime-preserve", "--numeric-owner")
|
||||
self.dest_path, ".", "--atime-preserve", "--numeric-owner")
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
os.chdir(current_dir)
|
||||
if rc != 0:
|
||||
@@ -147,7 +151,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
_("spawning"), " ".join(exec_script),
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env = env)
|
||||
rc = molecule.utils.exec_cmd(exec_script, env=env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("TarHandler"), darkred(self.spec_name),
|
||||
@@ -158,7 +162,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
return 0
|
||||
|
||||
def kill(self, success = True):
|
||||
def kill(self, success=True):
|
||||
if not success:
|
||||
self._run_error_script(None, self.chroot_path, None)
|
||||
try:
|
||||
@@ -167,6 +171,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
pass
|
||||
return 0
|
||||
|
||||
|
||||
class IsoToTarSpec(GenericSpec):
|
||||
|
||||
PLUGIN_API_VERSION = 1
|
||||
@@ -175,7 +180,8 @@ class IsoToTarSpec(GenericSpec):
|
||||
def execution_strategy():
|
||||
return "iso_to_tar"
|
||||
|
||||
def supported_compression_method(self, comp_m):
|
||||
@staticmethod
|
||||
def supported_compression_method(comp_m):
|
||||
return comp_m in SUPPORTED_COMPRESSION_METHODS
|
||||
|
||||
def vital_parameters(self):
|
||||
@@ -195,8 +201,8 @@ class IsoToTarSpec(GenericSpec):
|
||||
'parser': self._command_splitter,
|
||||
},
|
||||
'release_string': {
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
'verifier': lambda x: len(x) != 0, # validation callback
|
||||
'parser': lambda x: x.strip(), # value extractor
|
||||
},
|
||||
'release_version': {
|
||||
'verifier': lambda x: len(x) != 0,
|
||||
|
||||
+17
-13
@@ -1,15 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0,'.')
|
||||
sys.path.insert(0,'..')
|
||||
sys.path.insert(0, '.')
|
||||
sys.path.insert(0, '..')
|
||||
import unittest
|
||||
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.settings import SpecParser
|
||||
from molecule.specs.factory import PluginFactory
|
||||
from molecule.specs.skel import GenericSpec
|
||||
|
||||
|
||||
class ParsersTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
@@ -39,7 +38,7 @@ class ParsersTest(unittest.TestCase):
|
||||
'post_iso_script': ['specs/data/post_iso_script.sh'],
|
||||
'iso_title': 'Sabayon KDE',
|
||||
'extra_mkisofs_parameters': ['-b', 'isolinux/isolinux.bin', '-c',
|
||||
'isolinux/boot.cat'],
|
||||
'isolinux/boot.cat'],
|
||||
'release_version': '5.3',
|
||||
'source_iso': 'specs/data/Sabayon_Linux_SpinBase_DAILY_x86.iso',
|
||||
'__plugin__': None,
|
||||
@@ -47,10 +46,10 @@ class ParsersTest(unittest.TestCase):
|
||||
'release_desc': 'x86 TEST',
|
||||
'packages_to_remove': ['app-foo/foo', 'app-foo2/foo2'],
|
||||
'pre_iso_script': ['specs/data/pre_iso_script.sh',
|
||||
'KDE'],
|
||||
'KDE'],
|
||||
'custom_packages_add_cmd': ['equo', 'install', '--ask'],
|
||||
'packages_to_add': ['app-admin/packagekit-base',
|
||||
'app-admin/packagekit-qt4', 'app-admin/sulfur'],
|
||||
'app-admin/packagekit-qt4', 'app-admin/sulfur'],
|
||||
'release_file': '/etc/sabayon-edition',
|
||||
'outer_chroot_script': ['specs/data/outer_chroot_script.sh'],
|
||||
'execute_repositories_update': 'yes',
|
||||
@@ -81,7 +80,7 @@ class ParsersTest(unittest.TestCase):
|
||||
'destination_iso_image_name': 'Sabayon_Linux_5.3_x86_chroot_TEST.iso',
|
||||
'post_iso_script': ['specs/data/post_iso_script.sh'],
|
||||
'extra_mkisofs_parameters': ['-b', 'isolinux/isolinux.bin', '-c',
|
||||
'isolinux/boot.cat'],
|
||||
'isolinux/boot.cat'],
|
||||
'prechroot': ['linux32'],
|
||||
'pre_iso_script': ['specs/data/pre_iso_script.sh'],
|
||||
'paths_to_remove': [
|
||||
@@ -130,17 +129,21 @@ class ParsersTest(unittest.TestCase):
|
||||
'destination_livecd_root': 'specs/out/fake_livecd_root',
|
||||
'release_desc': 'x86 SpinBase',
|
||||
'inner_chroot_script': ['specs/data/inner_chroot_script.sh',
|
||||
'spinbase'],
|
||||
'extra_rsync_parameters': ['--one-file-system', '--exclude',
|
||||
'/proc/*', '--exclude', '/dev/pts/*'],
|
||||
'spinbase'],
|
||||
'extra_rsync_parameters': [
|
||||
'--one-file-system', '--exclude',
|
||||
'/proc/*', '--exclude', '/dev/pts/*'
|
||||
],
|
||||
'release_file': '/etc/sabayon-edition',
|
||||
'merge_livecd_root': 'specs/out/fake_merge_livecd_root',
|
||||
'release_string': 'Sabayon Linux',
|
||||
'paths_to_empty': ['/home/sabayonuser/.thumbnails/',
|
||||
'paths_to_empty': [
|
||||
'/home/sabayonuser/.thumbnails/',
|
||||
'/root/.ccache', '/var/tmp/portage', '/var/tmp/ccache',
|
||||
'/var/tmp/portage-pkg', '/var/tmp/binpkgs',
|
||||
'/var/lib/entropy/portage', '/var/lib/entropy/logs',
|
||||
'/var/cache/genkernel'],
|
||||
'/var/cache/genkernel'
|
||||
],
|
||||
'destination_iso_directory': 'specs/out'
|
||||
}
|
||||
|
||||
@@ -238,6 +241,7 @@ class ParsersTest(unittest.TestCase):
|
||||
extracted_data['__plugin__'] = None
|
||||
self.assertEqual(expected_data, extracted_data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
raise SystemExit(0)
|
||||
|
||||
@@ -20,8 +20,8 @@ os.environ["MOLECULE_PLUGIN_MODULES"] = ":".join(_plugins)
|
||||
|
||||
|
||||
import unittest
|
||||
sys.path.insert(0,'.')
|
||||
sys.path.insert(0,'..')
|
||||
sys.path.insert(0, '.')
|
||||
sys.path.insert(0, '..')
|
||||
|
||||
from tests import parsers
|
||||
rc = 0
|
||||
@@ -33,7 +33,7 @@ tests = []
|
||||
for mod in mods:
|
||||
tests.append(unittest.TestLoader().loadTestsFromModule(mod))
|
||||
|
||||
result = unittest.TextTestRunner(verbosity = 1).run(unittest.TestSuite(tests))
|
||||
result = unittest.TextTestRunner(verbosity=1).run(unittest.TestSuite(tests))
|
||||
if result.errors:
|
||||
rc = 1
|
||||
raise SystemExit(rc)
|
||||
|
||||
Reference in New Issue
Block a user