new feature: runtime support and bootstrap runtime
authorZhang Qiang <qiang.z.zhang@intel.com>
Thu, 29 Dec 2011 06:24:21 +0000 (14:24 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Sat, 31 Dec 2011 08:28:42 +0000 (16:28 +0800)
1) Using --runtime=bootstrap option to run mic in bootstrap mode
   example: mic cr fs netbook.ks --runtime=bootstrap
2) Get target image rpm version(from ks file's repo url), which
   can be used to select correct bootstap.
3) Check local available bootstrap from default bootstrap directory
   (/var/mic/bootstrap/), if any local bootstrap can be used, then
   goto 5)
4) Check available bootstrap info from /etc/mic/mic.conf, rpm version
   of bootstrap is got from repodata, if rpmversion matched with target
   image rpm version, then select that bootstrap info.
5) Use zypp package manager to create bootstrap
6) We assume host mic is what user want to use, so copy host mic to
   bootstrap
7) copy host necessary files to bootstrap: /etc/resolv.conf, repos,
   proxy info.
8) run mic in bootstrap.

Note: Currently zypp backend is used to creating bootstrap env, but it's
not a good ideal, because zypp backend has some dependencies, such as
python-zypp, libzypp, libsatsolver. Next step, we would use general
depdendency resolve algorithm to replace zypp backend.

14 files changed:
distfiles/mic.conf
mic/bootstrap.py [new file with mode: 0644]
mic/chroot.py
mic/conf.py
mic/creator.py
mic/rt_util.py [new file with mode: 0644]
mic/utils/errors.py
mic/utils/misc.py
plugins/backend/zypppkgmgr.py
plugins/imager/fs_plugin.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index f244820..7b8d702 100644 (file)
@@ -7,6 +7,8 @@ distro_name = Tizen
 tmpdir= /var/tmp/mic
 cachedir= /var/tmp/mic/cache
 outdir= ./mic-output
+bootstrapdir= /var/tmp/mic/bootstrap
+
 pkgmgr = zypp
 
 ; proxy = http://proxy.yourcompany.com:8080/
@@ -21,3 +23,19 @@ pkgmgr = zypp
 [chroot]
 ; settings for chroot subcommand
 
+[bootstrap1]
+; This bootstrap can be used to create image with rpm 4.8.x
+name=meego-1.2.0
+1.2.0-oss=http://repo.meego.com/MeeGo/releases/1.2.0/repos/oss/ia32/packages/
+1.2.0-tools=http://download.meego.com/live/devel:/tools:/building/MeeGo_1.2.0/
+; 1.2.0-oss_proxy=http://proxy.yourcompany.com:port
+; 1.2.0-tools_proxy=http://proxy.yourcompany.com:port
+
+[bootstrap2]
+; This bootstrap can be used to create image with rpm 4.9.x
+name=meego-trunk
+trunk-oss=http://repo.meego.com/MeeGo/builds/trunk/latest/repos/oss/ia32/packages/
+trunk-tools=http://download.meego.com/live/devel:/tools:/building/Trunk/
+; trunk-oss_proxy=http://proxy.yourcompany.com:port
+; trunk-tools_proxy=http://proxy.yourcompany.com:port
+
diff --git a/mic/bootstrap.py b/mic/bootstrap.py
new file mode 100644 (file)
index 0000000..6bcde9b
--- /dev/null
@@ -0,0 +1,235 @@
+#/usr/bin/env python
+
+from __future__ import with_statement
+import os
+import sys
+import pickle
+import shutil
+import subprocess
+import rpm
+
+from mic import msger
+from mic import chroot
+from mic.plugin import pluginmgr
+from mic.utils import proxy
+from mic.utils import rpmmisc
+from mic.utils import errors
+
+minibase_pkgs = [ "kernel", "rpm", "setup", "filesystem", "basesystem",
+                  "tzdata", "libgcc", "ncurses-base", "ncurses", "glibc",
+                  "glibc-common", "ncurses-libs", "nss-softokn-freebl",
+                  "bash", "zlib", "info", "cpio", "coreutils", "zypper" ]
+
+required_pkgs = [ "pam", "passwd", "meego-release", "nss", "genisoimage",
+                  "bzip2", "gzip", "perl", "make", "file", "psmisc", "wget",
+                  "syslinux-extlinux", "btrfs-progs", "satsolver-tools",
+                  "isomd5sum", "mtd-utils", "mtd-utils-ubi", "libzypp",
+                  "python-zypp", "grep", "mic" ]
+
+
+def query_package_rpmdb(root='/', tag='name', pattern=None):
+    name = pattern
+    version = None
+    ts = rpm.TransactionSet(root)
+    mi = ts.dbMatch(tag, pattern)
+    for hdr in mi:
+        version = hdr['version']
+    return (name, version)
+
+def query_package_metadat(root='/', tag='name', pattern=None):
+    name = pattern
+    version = None
+    try:
+        with open(root + '/.metadata', 'r') as f:
+            metadata = pickle.load(f)
+        f.close()
+    except:
+        raise errors.BootstrapError("Load %s/.metadata error" % root)
+    else:
+        for pkg in metadata.keys():
+            (n, v, r, e, a) = rpmmisc.splitFilename(pkg)
+            if n == pattern:
+                version = v
+    return (name, version)
+
+class Bootstrap(object):
+    def __init__(self, homedir='/var/mic/bootstrap', **kwargs):
+        self._pkgmgr = None
+        self._rootdir = None
+        self._bootstraps = []
+        self.homedir = homedir
+
+        if not os.path.exists(self.homedir):
+            os.makedirs(self.homedir)
+
+        self.__dict__.update(**kwargs)
+
+    def _setRootdir(self, name):
+        self._rootdir = os.path.join(self.homedir, name)
+
+    def _getRootdir(self):
+        if not os.path.exists(self._rootdir):
+            raise errors.BootstrapError("Root dir: %s not exist" % self._rootdir)
+        return self._rootdir
+
+    rootdir = property(fget = lambda self: self._getRootdir(),
+                       fset = lambda self, name: self._setRootdir(name),
+                       doc = 'root directory')
+
+    def _setPkgmgr(self, name):
+        backend_plugins = pluginmgr.get_plugins('backend')
+        for (key, cls) in backend_plugins.iteritems():
+            if key == name:
+                self._pkgmgr = cls
+        if not self._pkgmgr:
+            raise errors.BootstrapError("Backend: %s can't be loaded correctly" % name)
+
+    pkgmgr = property(fget = lambda self: self._pkgmgr,
+                      fset = lambda self, name: self._setPkgmgr(name),
+                      doc = 'package manager')
+
+    @property
+    def bootstraps(self):
+        if self._bootstraps:
+            return self._bootstraps
+        for dir in os.listdir(self.homedir):
+            metadata_fp = os.path.join(self.homedir, dir, '.metadata')
+            if os.path.exists(metadata_fp) \
+                and 0 != os.path.getsize(metadata_fp):
+                self._bootstraps.append(dir)
+        return self._bootstraps
+
+    def run(self, name, cmd, chdir='/', bindmounts=None):
+        self.rootdir = name
+        def mychroot():
+            os.chroot(self.rootdir)
+            os.chdir(chdir)
+
+        if isinstance(cmd, list):
+            cmd = ' '.join(cmd)
+
+        lvl = msger.get_loglevel()
+        msger.set_loglevel('quiet')
+        globalmounts = chroot.setup_chrootenv(self.rootdir, bindmounts)
+        try:
+            proxy.set_proxy_environ()
+            subprocess.call(cmd, preexec_fn=mychroot, shell=True)
+            proxy.unset_proxy_environ()
+        except:
+            raise errors.BootstrapError("Run in bootstrap fail")
+        finally:
+            chroot.cleanup_chrootenv(self.rootdir, bindmounts, globalmounts)
+
+        msger.set_loglevel(lvl)
+
+    def list(self, **kwargs):
+        bslist = []
+        for binst in self.bootstraps:
+            (mver, kver, rver) = self.status(binst)
+            bsinfo = {'name':binst, 'meego':mver, 'kernel':kver, 'rpm': rver}
+            bslist.append(bsinfo)
+
+        return bslist
+
+    def status(self, name):
+        self.rootdir = name
+        if os.path.exists(self.rootdir + '/.metadata'):
+            query_package = query_package_metadat
+        else:
+            query_package = query_package_rpmdb
+
+        name, mver = query_package(self.rootdir, 'name', 'meego-release')
+        #print "MeeGo Release: %s" % mver
+        name, kver = query_package(self.rootdir, 'name', 'kernel')
+        #print "Kernel Version: %s" % kver
+        name, rver = query_package(self.rootdir, 'name', 'rpm')
+        #print "RPM Version: %s" % rver
+        return (mver, kver, rver)
+
+    def create(self, name, repolist, **kwargs):
+        self.name = name
+        self.pkgmgr = 'zypp'
+        self.arch = 'i686'
+        self.rootdir = name
+        self.cachedir = '/var/tmp/mic/cache'
+
+        if 'arch' in kwargs:
+            self.arch = kwargs['arch']
+        if 'cachedir' in kwargs:
+            self.cachedir = kwargs['cachedir']
+
+        if os.path.exists(self._rootdir):
+            metadata_fp = os.path.join(self._rootdir, '.metadata')
+            if os.path.exists(metadata_fp) and \
+                0 != os.path.getsize(metadata_fp):
+                print "Already exists"
+                return
+            else:
+                shutil.rmtree(self._rootdir)
+
+        if not os.path.exists(self._rootdir):
+            os.makedirs(self._rootdir)
+
+        pkg_manager = self.pkgmgr(self.arch, self.rootdir, self.cachedir)
+
+        pkg_manager.setup()
+
+        for repo in repolist:
+            if 'proxy' in repo.keys():
+                pkg_manager.addRepository(repo['name'], repo['baseurl'], proxy = repo['proxy'])
+            else:
+                pkg_manager.addRepository(repo['name'], repo['baseurl'])
+
+        rpm.addMacro("_dbpath", "/var/lib/rpm")
+        rpm.addMacro("__file_context_path", "%{nil}")
+
+        for pkg in minibase_pkgs:
+            pkg_manager.selectPackage(pkg)
+        for pkg in required_pkgs:
+            pkg_manager.selectPackage(pkg)
+
+        try:
+            pkg_manager.runInstall(512 * 1024L * 1024L)
+        except:
+            raise errors.BootstrapError("Create bootstrap fail")
+        else:
+            metadata = pkg_manager.getAllContent()
+            metadata_fp = os.path.join(self.rootdir, '.metadata')
+            with open(metadata_fp, 'w') as f:
+                pickle.dump(metadata, f)
+            f.close()
+        finally:
+            pkg_manager.closeRpmDB()
+            pkg_manager.close()
+
+        # Copy bootstrap repo files
+        srcdir = "%s/etc/zypp/repos.d/" % self.cachedir
+        destdir= "%s/etc/zypp/repos.d/" % os.path.abspath(self.rootdir)
+        shutil.rmtree(destdir, ignore_errors = True)
+        shutil.copytree(srcdir, destdir)
+
+        print "Bootstrap done"
+
+    def rebuild(self):
+        pass
+
+    def update(self, name):
+        self.rootdir = name
+        chrootdir = self.rootdir
+
+        def mychroot():
+            os.chroot(chrootdir)
+
+        shutil.copyfile("/etc/resolv.conf", chrootdir + "/etc/resolv.conf")
+        try:
+            subprocess.call("zypper -n --no-gpg-checks update", preexec_fn=mychroot, shell=True)
+        except OSError, err:
+            raise errors.BootstrapError("Bootstrap: %s Update fail" % chrootdir)
+
+    def cleanup(self, name):
+        self.rootdir = name
+        try:
+            chroot.cleanup_mounts(self.rootdir)
+            shutil.rmtree(self.rootdir, ignore_errors=True)
+        except:
+            raise errors.BootstrapError("Bootstrap: %s clean up fail " % self.rootdir)
index 958c2ae..b4cffa5 100644 (file)
@@ -83,6 +83,9 @@ def cleanup_mounts(chrootdir):
     for point in BIND_MOUNTS:
         args = [ umountcmd, "-l", chrootdir + point ]
         runner.quiet(args)
+    point = '/parentroot'
+    args = [ umountcmd, "-l", chrootdir + point ]
+    runner.quiet(args)
 
     abs_chrootdir = os.path.abspath(chrootdir)
     with open('/proc/mounts') as f:
index 083f518..7eb2f22 100644 (file)
@@ -32,6 +32,8 @@ class ConfigMgr(object):
                     "tmpdir": '/var/tmp/mic',
                     "cachedir": '/var/tmp/mic/cache',
                     "outdir": './mic-output',
+                    "bootstrapdir": '/var/tmp/mic/bootstrap',
+
                     "arch": None, # None means auto-detect
                     "pkgmgr": "yum",
                     "name": "output",
@@ -47,9 +49,12 @@ class ConfigMgr(object):
                     "name_prefix": None,
                     "proxy": None,
                     "no_proxy": None,
+
+                    "runtime": None,
                 },
                 'chroot': {},
                 'convert': {},
+                'bootstraps': {},
                }
 
     # make the manager class as singleton
@@ -124,6 +129,33 @@ class ConfigMgr(object):
 
         proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])
 
+        for section in parser.sections():
+            if section.startswith('bootstrap'):
+                name = section
+                repostr = {}
+                for option in parser.options(section):
+                    if option == 'name':
+                        name = parser.get(section, 'name')
+                        continue
+
+                    val = parser.get(section, option)
+                    if '_' in option:
+                        (reponame, repoopt) = option.split('_')
+                        if repostr.has_key(reponame):
+                            repostr[reponame] += "%s:%s," % (repoopt, val)
+                        else:
+                            repostr[reponame] = "%s:%s," % (repoopt, val)
+                        continue
+
+                    if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
+                        if repostr.has_key(option):
+                            repostr[option] += "name:%s,baseurl:%s," % (option, val)
+                        else:
+                            repostr[option]  = "name:%s,baseurl:%s," % (option, val)
+                        continue
+
+                self.bootstraps[name] = repostr
+
     def _selinux_check(self, arch, ks):
         """If a user needs to use btrfs or creates ARM image,
         selinux must be disabled at start.
index 4f90a26..9cfcb7d 100644 (file)
@@ -87,6 +87,9 @@ class Creator(cmdln.Cmdln):
         optparser.add_option('', '--local-pkgs-path', type='string',
                              dest='local_pkgs_path', default=None,
                              help='Path for local pkgs(rpms) to be installed')
+        optparser.add_option('', '--runtime', type='string',
+                             dest='runtime', default=None,
+                             help='Specify  runtime mode, avaiable: bootstrap')
         optparser.add_option('', '--compress-disk-image', type='string',
                              dest='compress_disk_image', default=None,
                              help='Sets the disk image compression. NOTE: The '
@@ -181,6 +184,9 @@ class Creator(cmdln.Cmdln):
         if self.options.pkgmgr is not None:
             configmgr.create['pkgmgr'] = self.options.pkgmgr
 
+        if self.options.runtime:
+            configmgr.create['runtime'] = self.options.runtime
+
         if self.options.compress_disk_image is not None:
             configmgr.create['compress_disk_image'] = \
                                                 self.options.compress_disk_image
@@ -208,11 +214,11 @@ class Creator(cmdln.Cmdln):
             # optparser=None means no process for opts
             self.options, args = None, argv[1:]
 
-        self.postoptparse()
-
         if not args:
             return self.emptyline()
 
+        self.postoptparse()
+
         if os.geteuid() != 0:
             msger.error('Root permission is required to continue, abort')
 
diff --git a/mic/rt_util.py b/mic/rt_util.py
new file mode 100644 (file)
index 0000000..71a4882
--- /dev/null
@@ -0,0 +1,207 @@
+#!/usr/bin/python
+
+import os
+import sys
+import string
+import shutil
+import re
+import platform
+
+from mic import bootstrap
+from mic import msger
+from mic.conf import configmgr
+from mic.utils import errors
+import mic.utils.misc as misc
+
+SUPPORT_DISTS = (
+    'SuSE', 'debian', 'fedora', 'redhat', 'centos',
+    'meego', 'moblin', 'tizen')
+
+def uniq(lst=[]):
+    if not lst:
+        return
+    try:
+        st = set(lst)
+    except:
+        import sets
+        st = sets.Set(lst)
+    return list(st)
+
+# detect linux distribution, support "meego"
+def linux_distribution():
+    try:
+        (dist, ver, id) = platform.linux_distribution( \
+                              supported_dists = SUPPORT_DISTS)
+    except:
+        (dist, ver, id) = platform.dist( \
+                              supported_dists = SUPPORT_DISTS)
+    return (dist, ver, id)
+
+def runmic_in_runtime(runmode, opts, ksfile, argv=None):
+    if not runmode or "MeeGo" == linux_distribution()[0]:
+        return
+
+    if not argv:
+        argv = sys.argv
+    else:
+        argv = argv[:]
+
+    if runmode == 'bootstrap':
+        msger.info("Use bootstrap runtime environment")
+        (name, repostrs) = select_bootstrap(opts['repomd'], opts['cachedir'], opts['bootstrapdir'])
+        repolist = []
+        if not name:
+            # use ks repo to create bootstrap
+            # so far it can't be effective for mic not in repo
+            #name = os.path.basename(ksfile)
+            #repostrs = misc.get_repostrs_from_ks(opts['ks'])
+            #for item in repostrs:
+            #    repolist.append(convert_repostr(item))
+            msger.info("Failed to find propery bootstrap, please check config file")
+            msger.info("Back to native running")
+            return
+        else:
+            for reponame, repostr in repostrs.items():
+                repolist.append(convert_repostr(repostr))
+        runmic_in_bootstrap(name, argv, opts, ksfile, repolist)
+    else:
+        raise errors.RuntimeError('Invalid runmode: %s ' % runmode)
+
+    sys.exit(0)
+
+def compare_rpmversion(ver1, ver2):
+    return ver1.split('.')[0] == ver2.split('.')[0] and \
+        ver1.split('.')[1] == ver2.split('.')[1]
+
+def convert_repostr(repostr):
+    repo = {}
+    for item in repostr.split(','):
+        loc = item.find(':')
+        opt = item[0:loc]
+        if opt in ('name', 'baseurl', 'mirrolist', 'proxy', \
+            'proxy_username', 'proxy_password', 'debuginfo', \
+            'source', 'gpgkey', 'disable'):
+            if len(item) > loc:
+                repo[opt] = item[loc+1:]
+            else:
+                repo[opt] = None
+    return repo
+
+def select_bootstrap(repomd, cachedir, bootstrapdir):
+    cfgmgr = configmgr
+    lvl = msger.get_loglevel()
+    msger.set_loglevel('quiet')
+    repo_rpmver = misc.get_rpmver_in_repo(repomd)
+    if not repo_rpmver:
+        msger.set_loglevel(lvl)
+        return (None, None)
+
+    # Check avaliable bootstrap
+    bootstrap_env = bootstrap.Bootstrap(homedir = bootstrapdir)
+    for bs in bootstrap_env.list():
+        if compare_rpmversion(repo_rpmver, bs['rpm']):
+            return (bs['name'], {})
+
+    for bsname, bsrepo in cfgmgr.bootstraps.items():
+        repolist = []
+        for repo in bsrepo.keys():
+            repolist.append(bsrepo[repo])
+        repomd = misc.get_metadata_from_repos(repolist, cachedir)
+        rpmver = misc.get_rpmver_in_repo(repomd)
+        if not rpmver: 
+            continue
+        if compare_rpmversion(repo_rpmver, rpmver):
+            msger.set_loglevel(lvl)
+            return (bsname, bsrepo)
+    msger.set_loglevel(lvl)
+    return (None, None)
+
+def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
+    bootstrap_env = bootstrap.Bootstrap(homedir = opts['bootstrapdir'])
+    bootstrap_lst = bootstrap_env.bootstraps
+    setattr(bootstrap_env, 'rootdir', name)
+    if not bootstrap_lst or not name in bootstrap_lst:
+        msger.info("Creating bootstrap %s under %s" %  (name, bootstrap_env.homedir))
+        bootstrap_env.create(name, repolist)
+
+    msger.info("Use bootstrap: %s" % bootstrap_env.rootdir)
+    # copy mic
+    msger.info("Sync native mic to bootstrap")
+    copy_mic(bootstrap_env.rootdir)
+
+    # bind mounts , opts['cachedir'], opts['tmpdir'] 
+    cwd = os.getcwd()
+    lst = [cwd, opts['outdir']]
+    if ksfile:
+        ksfp = os.path.abspath(os.path.expanduser(ksfile))
+        lst.append(os.path.dirname(ksfp))
+    if opts['logfile']:
+        logfile = os.path.abspath(os.path.expanduser(opts['logfile']))
+        lst.append(os.path.dirname(logfile))
+    # local package path
+    # local repo
+
+    # make unique
+    lst = uniq(lst)
+    bindmounts = ';'.join(map(lambda p: os.path.abspath(os.path.expanduser(p)), lst))
+    msger.info("Start mic command in bootstrap")
+    bootstrap_env.run(name, argv, cwd, bindmounts)
+
+def get_mic_modpath():
+    try:
+        import mic
+    except ImportError:
+        raise errors.BootstrapError('Can\'t find mic module in host OS.')
+    else:
+        path = os.path.abspath(mic.__file__)
+        return os.path.dirname(path)
+
+def get_mic_binpath():
+    path = os.environ['PATH']
+    paths = string.split(path, os.pathsep)
+    for pth in paths:
+        fn = os.path.join(pth, 'mic')
+        if os.path.isfile(fn):
+            return fn
+    msger.warning("Can't find mic command")
+
+def get_mic_libpath():
+    # so far mic lib path is hard coded
+    return "/usr/lib/mic"
+
+# the hard code path is prepared for bootstrap
+def copy_mic(bootstrap_pth, bin_pth = '/usr/bin', lib_pth='/usr/lib', \
+             pylib_pth = '/usr/lib/python2.6/site-packages'):
+    # copy python lib files
+    mic_pylib = get_mic_modpath()
+    bs_mic_pylib = bootstrap_pth + os.path.join(pylib_pth, 'mic')
+    if os.path.commonprefix([mic_pylib, bs_mic_pylib]) == mic_pylib:
+        raise errors.BootstrapError('Invalid Bootstrap: %s' % bootstrap_pth)
+    shutil.rmtree(bs_mic_pylib, ignore_errors = True)
+    shutil.copytree(mic_pylib, bs_mic_pylib)
+    clean_files(".*\.py[co]$", bs_mic_pylib)
+
+    # copy lib files
+    mic_libpth = get_mic_libpath()
+    bs_mic_libpth = bootstrap_pth + os.path.join(lib_pth, 'mic')
+    if os.path.commonprefix([mic_libpth, bs_mic_libpth]) == mic_libpth:
+        raise errors.BootstrapError('Invalid Bootstrap: %s' % bootstrap_pth)
+    shutil.rmtree(bs_mic_libpth, ignore_errors = True)
+    shutil.copytree(mic_libpth, bs_mic_libpth)
+    os.system('cp -af %s %s' % (mic_libpth, os.path.dirname(bs_mic_libpth)))
+
+    # copy bin files
+    mic_binpth = get_mic_binpath()
+    bs_mic_binpth = bootstrap_pth + os.path.join(bin_pth, 'mic')
+    shutil.rmtree(bs_mic_binpth, ignore_errors = True)
+    shutil.copy2(mic_binpth, bs_mic_binpth)
+
+def clean_files(pattern, dir):
+    if not os.path.exists(dir):
+        return
+    for f in os.listdir(dir):
+        entry = os.path.join(dir, f)
+        if os.path.isdir(entry):
+            clean_files(pattern, entry)
+        elif re.match(pattern, entry):
+            os.unlink(entry)
index 4cf06b9..4b13010 100644 (file)
@@ -49,3 +49,9 @@ class SnapshotError(CreatorError):
 
 class SquashfsError(CreatorError):
     keyword = '<squashfs>'
+
+class BootstrapError(CreatorError):
+    keyword = '<bootstrap>'
+
+class RuntimeError(CreatorError):
+    keyword = '<runtime>'
index d4599a2..fe3c402 100644 (file)
@@ -85,11 +85,6 @@ def check_meego_chroot(rootdir):
         raise CreatorError("Directory %s is not a MeeGo/Tizen chroot env"\
                            % rootdir)
 
-    if not os.path.exists(rootdir + "/etc/inittab") or \
-       not os.path.exists(rootdir + "/etc/rc.sysinit"):
-        raise CreatorError("Lack of init scripts under %s: /etc/inittab, "\
-                           "/etc/rc.sysinit" % rootdir)
-
     if not glob.glob(rootdir + "/boot/vmlinuz-*"):
         raise CreatorError("Failed to find kernel module under %s" % rootdir)
 
index 5546a8f..e7dd6b4 100644 (file)
@@ -107,9 +107,10 @@ class Zypp(BackendPlugin):
         for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
             os.unlink(f)
 
-    def setup(self, confpath, installroot):
-        self._cleanupRpmdbLocks(installroot)
-        self.installroot = installroot
+    def setup(self, confpath=None, instroot=None):
+        if not self.instroot:
+            self.instroot = instroot
+        self._cleanupRpmdbLocks(self.instroot)
 
     def whatObsolete(self, pkg):
         query = zypp.PoolQuery()
@@ -296,10 +297,14 @@ class Zypp(BackendPlugin):
             if proxy:
                 (scheme, host, path, parm, query, frag) = urlparse.urlparse(proxy)
                 proxyinfo = host.split(":")
-                baseurl.setQueryParam ("proxy", proxyinfo[0])
+                host = proxyinfo[0]
                 port = "80"
                 if len(proxyinfo) > 1:
                     port = proxyinfo[1]
+                if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2:
+                    host = proxy.rsplit(':', 1)[0]
+                    port = proxy.rsplit(':', 1)[1]
+                baseurl.setQueryParam ("proxy", host)
                 baseurl.setQueryParam ("proxyport", port)
             repo_info.addBaseUrl(baseurl)
             if repo.priority:
index 3d5893e..960ed3d 100644 (file)
@@ -16,8 +16,9 @@
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import sys
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import cmdln, misc, errors
 from mic.imager import fs
 from mic.conf import configmgr
@@ -78,6 +79,9 @@ class FsPlugin(ImagerPlugin):
             pkgmgrs = pluginmgr.get_plugins('backend').keys()
             raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
 
+        if creatoropts['runtime']:
+            rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None)
+
         creator = fs.FsImageCreator(creatoropts, pkgmgr)
         creator._include_src = opts.include_src
 
index ab152e1..4738a80 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors
 from mic.conf import configmgr
 import mic.imager.livecd as livecd
@@ -79,6 +79,9 @@ class LiveCDPlugin(ImagerPlugin):
             pkgmgrs = pluginmgr.get_plugins('backend').keys()
             raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
 
+        if creatoropts['runtime']:
+            rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None)
+
         creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr)
 
         if len(recording_pkgs) > 0:
index c41c79b..ed393b4 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors
 from mic.utils.partitionedfs import PartitionedMount
 from mic.conf import configmgr
@@ -81,6 +81,9 @@ class LiveUSBPlugin(ImagerPlugin):
             pkgmgrs = pluginmgr.get_plugins('backend').keys()
             raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
 
+        if creatoropts['runtime']:
+            rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None)
+
         creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
 
         if len(recording_pkgs) > 0:
index 9e7ee25..9097fbd 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors, cmdln
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -84,6 +84,9 @@ class LoopPlugin(ImagerPlugin):
                                       % (creatoropts['pkgmgr'],
                                          ', '.join(pkgmgrs)))
 
+        if creatoropts['runtime']:
+            rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None)
+
         creator = LoopImageCreator(creatoropts, pkgmgr, opts.taring_to)
 
         if len(recording_pkgs) > 0:
index 3bbda69..0b151d1 100644 (file)
@@ -20,7 +20,7 @@ import shutil
 import re
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors, runner
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -78,6 +78,9 @@ class RawPlugin(ImagerPlugin):
             pkgmgrs = pluginmgr.get_plugins('backend').keys()
             raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
 
+        if creatoropts['runtime']:
+            rt_util.runmic_in_runtime(creatoropts['runtime'], creatoropts, ksconf, None)
+
         creator = raw.RawImageCreator(creatoropts, pkgmgr)
 
         if len(recording_pkgs) > 0: