Support local mic-bootstrap rpm package to run mic.
authormao xiaojuan <xiaojuan.mao@samsung.com>
Thu, 23 Nov 2017 08:05:04 +0000 (16:05 +0800)
committermao xiaojuan <xiaojuan.mao@samsung.com>
Mon, 27 Nov 2017 06:03:50 +0000 (14:03 +0800)
Change-Id: I80298991eea5a9552a497b6e4b290e7b5b94555c

mic/bootstrap.py

index 5cfa8c7..2653c35 100644 (file)
@@ -22,10 +22,13 @@ import tempfile
 import shutil
 import subprocess
 import rpm
+import glob
+
 from mic import msger
 from mic.utils import errors, proxy, misc
 from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
 from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv
+from mic.conf import configmgr
 
 PATH_BOOTSTRAP = "/usr/sbin:/usr/bin:/sbin:/bin"
 
@@ -87,6 +90,21 @@ class MiniBackend(object):
         if not pkg in self.dlpkgs:
             self.dlpkgs.append(pkg)
 
+    def _get_local_packages(self, pkg):
+        """Return local mic-bootstrap rpm path."""
+        cropts = configmgr.create
+        if cropts['local_pkgs_path']:
+            if os.path.isdir(cropts['local_pkgs_path']):
+                pkglist = glob.glob(
+                           os.path.join(cropts['local_pkgs_path'], pkg + '*.rpm'))
+                if len(pkglist) > 1:
+                    raise errors.BootstrapError("Many %s packages in folder, put only one %s package in it." % (pkg, pkg))
+                elif len(pkglist) == 1:
+                    return ''.join(pkglist)
+            elif os.path.splitext(cropts['local_pkgs_path'])[-1] == '.rpm':
+                if cropts['local_pkgs_path'].index(pkg) > -1:
+                    return cropts['local_pkgs_path']
+        return None
     def runInstall(self):
         # FIXME: check space
         self.downloadPkgs()
@@ -105,7 +123,9 @@ class MiniBackend(object):
     def downloadPkgs(self):
         nonexist = []
         for pkg in self.dlpkgs:
-            localpth = misc.get_package(pkg, self.repomd, self.arch)
+            localpth = self._get_local_packages(pkg)
+            if localpth is None:
+                localpth = misc.get_package(pkg, self.repomd, self.arch)
             if localpth:
                 self.localpkgs[pkg] = localpth
             elif pkg in self.optionals: