Esempio n. 1
0
 def do_mount(self):
     if self.has_mounted: return True
     if not self.blk_path: logger.e('MiDevice.do_mount block path is "%s" ' % self.blk_path); return False
     # Priority to treat iso virtual device
     if self.fstype == 'iso9660':
         if not cdrom_available(self.blk_path):
             logger.w('MiDevice.do_mount %s type device "%s" cannot be used\n' % (self.fstype, self.blk_path))
             return False
         else:
             isopath = self.blk_path
             mountdir = self.mntdir_fixed and self.mntdir or self.loopmntdir
             ret, errmsg = mount_dev('iso9660', isopath, mountdir, flags='loop')
             if not ret:
                 logger.e("LoMount %s on %s as %s failed: %s" %  (isopath, mountdir, 'iso9660', str(errmsg)))
                 return False
             else:
                 if not self.mntdir_fixed: self.mntdir = self.loopmntdir
                 self.has_mounted = True
                 return True
                 
     # Then treat Harddisk Device
     if not self.mntdir_fixed:
         ret, mntdir = mount_dev(self.fstype, self.blk_path)
     else:
         ret, mntdir = mount_dev(self.fstype, self.blk_path, self.mntdir)
     if not ret:
         logger.e("MiDevice.do_mount Mount %s on %s as %s failed: %s" % \
                       (self.blk_path, mntdir, self.fstype, str(mntdir)))
         return False
     else:
         if not self.mntdir_fixed: self.mntdir = mntdir
         self.has_mounted = True
         return True
 def _install(self, pkgpath, progress_cb, noscripts=False):
     try:
         #             pkgname = get_pkg_name
         rpmfd = os.open(pkgpath, os.O_RDONLY)
         hdr = self.ts.hdrFromFdno(rpmfd)
         # because addInstall package each time will accumulate package set in transaction, so init transaction every time.
         self.initTs()
         if noscripts:
             self.ts.setFlags(rpm.RPMTRANS_FLAG_NOSCRIPTS)
         self.ts.addInstall(hdr, pkgpath, "i")
         os.close(rpmfd)
         # Sign the installing pkg name in stderr.
         # print >>sys.stderr, '%s ERROR :\n' % pkgname
         problems = self.ts.run(_rpm_installcb, (progress_cb,))
         if problems is not None:
             msg = "PROBLEMS: with package %s result %s (maybe prescript error)\n" % (
                 os.path.basename(pkgpath),
                 str(problems),
             )
             logger.w(msg)
             # problems is a list that each elements is a tuple.
             # The first element of the tuple is a human-readable string
             # and the second is another tuple such as:
             #    (rpm.RPMPROB_FILE_CONFLICT, conflict_filename, 0L)
             return msg
     except Exception, errmsg:
         logger.w("FAILED: %s\n" % str(errmsg))
         return str(errmsg)
Esempio n. 3
0
    def _install(self, pkgpath, progress_cb, noscripts=False):
        try:
#             pkgname = get_pkg_name
            rpmfd = os.open(pkgpath, os.O_RDONLY)
            hdr = self.ts.hdrFromFdno(rpmfd)
            # because addInstall package each time will accumulate package set in transaction, so init transaction every time.
            self.initTs()
            if noscripts:
                self.ts.setFlags(rpm.RPMTRANS_FLAG_NOSCRIPTS)
            self.ts.addInstall(hdr, pkgpath, 'i')
            os.close(rpmfd)
            # Sign the installing pkg name in stderr.
            #print >>sys.stderr, '%s ERROR :\n' % pkgname
            problems = self.ts.run(_rpm_installcb, (progress_cb, ))
            if problems is not None:
                msg = 'PROBLEMS: with package %s result %s (maybe prescript error)\n' % (os.path.basename(pkgpath), str(problems))
                logger.w(msg)
                # problems is a list that each elements is a tuple.
                # The first element of the tuple is a human-readable string
                # and the second is another tuple such as:
                #    (rpm.RPMPROB_FILE_CONFLICT, conflict_filename, 0L)
                return  msg
        except Exception, errmsg:
            logger.w('FAILED: %s\n' % str(errmsg))
            return str(errmsg)
 def _install(self, pkgpath, progress_cb):
     try:
         tar_size = os.path.getsize(pkgpath)
     except:
         errstr = _('Failed on get tar pakcage size "%s"') % (pkgpath, )
         logger.e(errstr)
         return errstr
     
     try:
         tarobj = tarfile.open(fileobj=CBFileObj(pkgpath, (progress_cb, tar_size)))
     except:
         errstr = _('Failed on create tarfile object on file "%s" size"%d"\n') % (pkgpath, tar_size)
         logger.e(errstr)
         return errstr
     
     try:
         tarobj.extractall(path=self.tgtsys_root)
     except:
         if tarobj:
             tarobj.close()
         errstr = _('Failed on extract file "%s" size"%d" to directory "%s"\n') % (pkgpath, tar_size, self.tgtsys_root)
         logger.e(errstr)
         return errstr
     
     try:
         tarobj.close()
     except:
         logger.w('Close tar pakcage failed path %s size %s' % (pkgpath, tar_size))
         
     return 0
Esempio n. 5
0
 def try_format(devn, id_):
     # Wait for device block appear.
     fblk = False
     time.sleep(1)
     # We attemp to detect device file whether exists
     for trycnt in range(10):
         # os.path.exists cannot detect file exists real time
         #if os.path.exists(devn):
         if os.system('ls %s' % devn) == 0:
             fblk = True
             break
         else:
             time.sleep(1)
             
     if not fblk:
         msg = _('Not exists device block on %s: \ntry time: %d\n') % (devpath, trycnt)
         logger.w(msg)
         return msg
     else:
         logger.d('try_format %s ls device %s time' % (id_, trycnt))
     # Run command to format partition
     cmd_format = CF.D.FSTYPE_MAP[fstype][1]
     cmd_f_list = cmd_format.split()
     cmd = cmd_f_list[0]
     argv = cmd_f_list[1:]
     argv.append(devn)
     cmdres = run_bash(cmd, argv)
     logger.d('%s %s' % (cmd, ' '.join(argv)))
     logger.d(' '.join(cmdres['out']))
     if cmdres['ret'] != 0:
         errmsg = _('Run "%s %s" failed: %s\ntry time: %d\n')
         return  errmsg % ( cmd, ' '.join(argv), str(cmdres['err']), trycnt )
     else:
         return  0
Esempio n. 6
0
    def umount_tgt_device(self):
        self.mounted_devs.reverse()
        for dev in self.mounted_devs:
            if type(dev) is MiDevice:
                if not dev.do_umount():
                    logger.w('Umount device %s Failed, but we continue')
            else:
                umount_dev(dev)
        res = run_bash('mount')
        logger.d(''''UMount target system partition finished, check the mount output please:)
%s
%s
        ''' % ('\n'.join(res['out']), '\n'.join(res['err'])))
Esempio n. 7
0
            def try_format(devn, id_):
                # Wait for device block appear.
                fblk = False
                time.sleep(1)
                # We attemp to detect device file whether exists
                for trycnt in range(10):
                    # os.path.exists cannot detect file exists real time
                    #if os.path.exists(devn):
                    if os.system('ls %s' % devn) == 0:
                        fblk = True
                        break
                    else:
                        time.sleep(1)

                if not fblk:
                    msg = _('Not exists device block on %s: \ntry time: %d\n'
                            ) % (devpath, trycnt)
                    logger.w(msg)
                    return msg
                else:
                    logger.d('try_format %s ls device %s time' % (id_, trycnt))
                # Run command to format partition
                cmd_format = CF.D.FSTYPE_MAP[fstype][1]
                cmd_f_list = cmd_format.split()
                cmd = cmd_f_list[0]
                argv = cmd_f_list[1:]
                argv.append(devn)
                cmdres = run_bash(cmd, argv)
                logger.d('%s %s' % (cmd, ' '.join(argv)))
                logger.d(' '.join(cmdres['out']))
                if cmdres['ret'] != 0:
                    errmsg = _('Run "%s %s" failed: %s\ntry time: %d\n')
                    return errmsg % (cmd, ' '.join(argv), str(
                        cmdres['err']), trycnt)
                else:
                    return 0
Esempio n. 8
0
                for pkgarr, relative_dir in midev_iso.iter_searchfiles(
                    [CF.D.PKGARR_FILE], CF.D.PKGARR_SER_CDPATH):
                    pos_id += 1
                    r = probe_position(pkgarr, 100 + pos_id, devpath,
                                       CF.D.FSTYPE_MAP[fstype][0],
                                       relative_dir, CF.D.BOOTCDFN)
                    if r:
                        r[-1] = os.path.join(
                            reldir, r[-1])  #### revise iso relative path
                        result.append(r)
            else:
                pos_id += 1
                r = probe_position(f, pos_id, devpath, fstype, reldir, '')
                if r: result.append(r)

    logger.w("pkgarr_probe %s" % result)
    return result


### Test Case
class MiaTest(object):
    def __init__(self):
        from mi.server.utils import FakeMiactions
        self.mia = FakeMiactions()
        self.operid = 999


class Test(MiaTest):
    def __init__(self):
        MiaTest.__init__(self)
Esempio n. 9
0
            if f.endswith('.iso'):
                midev_iso = MiDevice(f, 'iso9660')
                for pkgarr, relative_dir in midev_iso.iter_searchfiles([CF.D.PKGARR_FILE], CF.D.PKGARR_SER_CDPATH):
                    pos_id += 1
                    r = probe_position(pkgarr, 100 + pos_id,
                        devpath, CF.D.FSTYPE_MAP[fstype][0], relative_dir, CF.D.BOOTCDFN)
                    if r:
                        r[-1] = os.path.join(reldir, r[-1]) #### revise iso relative path
                        result.append(r)
            else:
                pos_id += 1
                r = probe_position(f, pos_id,
                    devpath, fstype, reldir, '')
                if r: result.append(r)

    logger.w("pkgarr_probe %s" % result)
    return result

### Test Case
class MiaTest(object):
    def __init__(self):
        from mi.server.utils import FakeMiactions
        self.mia = FakeMiactions()
        self.operid = 999
        
class Test(MiaTest):
    def __init__(self):
        MiaTest.__init__(self)
        
    def test_pkgarr_probe(self):
        hdpartlist = [
Esempio n. 10
0
 def _handleMissing(self, exn):
     logger.w('_handleMissing %s' % exn)
     return
Esempio n. 11
0
 def _handleMissing(self, exn):
     logger.w('_handleMissing %s' % exn)
     return
Esempio n. 12
0
 def umount_tgt_device(self):
     self.mounted_devs.reverse()
     for dev in self.mounted_devs:
         if not dev.do_umount():
             logger.w("Umount device %s Failed, but we continue")
Esempio n. 13
0
                        new_device,
                        CF.D.FSTYPE_MAP[fstype][0],
                        relative_dir,
                        CF.D.BOOTCDFN,
                    )
                    if r:
                        r[-1] = os.path.join(reldir, r[-1])  #### revise iso relative path
                        result.append(r)
            else:
                pos_id += 1
                r = probe_position(pkgarr, pos_id, device, new_device, fstype, reldir, "")
                if r:
                    result.append(r)

    #    del(cli)
    logger.w("_____________%s" % result)
    return result


@register.server_handler("long")
def probe_all_disc(mia, operid, device, devfstype, bootiso_relpath, pkgarr_reldir, disc_first_pkgs):
    """
        probe the package from all disk
        bootiso_relpath is the first iso path relative path of device /
        pkgarr_reldir is the relative directory path of pkgarr.py of device / OR iso dir /
    """
    dolog("probe_all_disc(%s, %s, %s, %s, %s)\n" % (device, devfstype, bootiso_relpath, pkgarr_reldir, disc_first_pkgs))

    midev = MiDevice(device, devfstype)

    bootiso_fn = CF.D.ISOFN_FMT % (CF.D.DISTNAME, CF.D.DISTVER, 1)