예제 #1
0
파일: lvm_root.py 프로젝트: mizdebsk/mock
 def create_base(self):
     pool_id = self.vg_name + '/' + self.pool_name
     size = self.lvm_conf['size']
     lvm_do(['lvcreate', '-T', pool_id, '-V', str(size), '-n', self.head_lv])
     mkfs = self.lvm_conf.get('mkfs_command', 'mkfs.' + self.fs_type)
     mkfs_args = self.lvm_conf.get('mkfs_args', [])
     util.do([mkfs, self.get_lv_path()] + mkfs_args)
예제 #2
0
 def _compress_logs(self):
     logger = getLog()
     for f_name in ('root.log', 'build.log', 'state.log'):
         f_path = os.path.join(self.buildroot.resultdir, f_name)
         if os.path.exists(f_path):
             command = "{0} {1}".format(self.command, f_path)
             logger.debug("Running {0}".format(command))
             util.do(command, shell=True)
예제 #3
0
파일: mock.py 프로젝트: heysion/mock_clone
 def createrepo_on_rpms():
     if config_opts["createrepo_on_rpms"]:
         log.info("Running createrepo on binary rpms in resultdir")
         buildroot.uid_manager.dropPrivsTemp()
         cmd = config_opts["createrepo_command"].split()
         cmd.append(buildroot.resultdir)
         util.do(cmd)
         buildroot.uid_manager.restorePrivs()
예제 #4
0
 def _compress_logs(self):
     logger = getLog()
     for f_name in ('root.log', 'build.log', 'state.log', 'available_pkgs.log', 'installed_pkgs.log', 'hw_info.log'):
         f_path = os.path.join(self.buildroot.resultdir, f_name)
         if os.path.exists(f_path):
             command = "{0} {1}".format(self.command, f_path)
             logger.debug("Running %s", command)
             util.do(command, shell=True)
예제 #5
0
 def _show_installed_packages(self):
     '''report the installed packages in the chroot to the root log'''
     self.buildroot.root_log.info("Installed packages:")
     self.buildroot._nuke_rpm_db()
     util.do(
         "%s --root %s -qa" % (self.config['rpm_command'],
                               self.buildroot.make_chroot_path()),
         raiseExc=False,
         shell=True,
         env=self.buildroot.env,
         uid=self.buildroot.chrootuid,
         user=self.buildroot.chrootuser,
         gid=self.buildroot.chrootgid,
         )
예제 #6
0
파일: mock.py 프로젝트: ianburrell/mock
    def post_build():
        if config_opts['post_install']:
            if buildroot.chroot_was_initialized:
                commands.install_build_results(commands.build_results)
            else:
                commands.init()
                commands.install_build_results(commands.build_results)
                commands.clean()

        if config_opts["createrepo_on_rpms"]:
            log.info("Running createrepo on binary rpms in resultdir")
            with buildroot.uid_manager:
                cmd = shlex.split(config_opts["createrepo_command"])
                cmd.append(buildroot.resultdir)
                util.do(cmd)
예제 #7
0
파일: mock.py 프로젝트: sfowl/mock
    def post_build():
        if config_opts['post_install']:
            if buildroot.chroot_was_initialized:
                commands.install_build_results(commands.build_results)
            else:
                commands.init()
                commands.install_build_results(commands.build_results)
                commands.clean()

        if config_opts["createrepo_on_rpms"]:
            log.info("Running createrepo on binary rpms in resultdir")
            with buildroot.uid_manager:
                cmd = shlex.split(config_opts["createrepo_command"])
                cmd.append(buildroot.resultdir)
                util.do(cmd)
예제 #8
0
    def _setup_devices(self):
        if self.config['internal_dev_setup']:
            util.rmtree(self.make_chroot_path("dev"), selinux=self.selinux)
            util.mkdirIfAbsent(self.make_chroot_path("dev", "pts"))
            util.mkdirIfAbsent(self.make_chroot_path("dev", "shm"))
            prevMask = os.umask(0000)
            devFiles = [
                (stat.S_IFCHR | 0o666, os.makedev(1, 3), "dev/null"),
                (stat.S_IFCHR | 0o666, os.makedev(1, 7), "dev/full"),
                (stat.S_IFCHR | 0o666, os.makedev(1, 5), "dev/zero"),
                (stat.S_IFCHR | 0o666, os.makedev(1, 8), "dev/random"),
                (stat.S_IFCHR | 0o444, os.makedev(1, 9), "dev/urandom"),
                (stat.S_IFCHR | 0o666, os.makedev(5, 0), "dev/tty"),
                (stat.S_IFCHR | 0o600, os.makedev(5, 1), "dev/console"),
                (stat.S_IFCHR | 0o666, os.makedev(5, 2), "dev/ptmx"),
                ]
            kver = os.uname()[2]
            #getLog().debug("kernel version == %s" % kver)
            for i in devFiles:
                # create node
                os.mknod(self.make_chroot_path(i[2]), i[0], i[1])
                # set context. (only necessary if host running selinux enabled.)
                # fails gracefully if chcon not installed.
                if self.selinux:
                    util.do(
                        ["chcon", "--reference=/" + i[2], self.make_chroot_path(i[2])],
                         raiseExc=0, shell=False, env=self.env)

            os.symlink("/proc/self/fd/0", self.make_chroot_path("dev/stdin"))
            os.symlink("/proc/self/fd/1", self.make_chroot_path("dev/stdout"))
            os.symlink("/proc/self/fd/2", self.make_chroot_path("dev/stderr"))

            if os.path.isfile(self.make_chroot_path('etc', 'mtab')):
                os.remove(self.make_chroot_path('etc', 'mtab'))
                os.symlink("/proc/self/mounts", self.make_chroot_path('etc', 'mtab'))

            os.chown(self.make_chroot_path('dev/tty'), pwd.getpwnam('root')[2], grp.getgrnam('tty')[2])
            os.chown(self.make_chroot_path('dev/ptmx'), pwd.getpwnam('root')[2], grp.getgrnam('tty')[2])

            # symlink /dev/fd in the chroot for everything except RHEL4
            if util.cmpKernelVer(kver, '2.6.9') > 0:
                os.symlink("/proc/self/fd", self.make_chroot_path("dev/fd"))

            os.umask(prevMask)

            if util.cmpKernelVer(kver, '2.6.18') >= 0:
                os.unlink(self.make_chroot_path('/dev/ptmx'))
            os.symlink("pts/ptmx", self.make_chroot_path('/dev/ptmx'))
예제 #9
0
파일: lvm_root.py 프로젝트: mizdebsk/mock
 def hook_scrub(self, what):
     if what not in ('lvm', 'all') or not self.lv_exists(self.pool_name):
         return
     self.pool_lock.lock(exclusive=True)
     lvs = self.list_our_lvs('lv_path')
     for name, lv_path in lvs:
         for src, _ in current_mounts():
             if src == os.path.realpath(lv_path):
                 util.do(['umount', '-l', src])
         self.buildroot.root_log.info("removing {0} volume".format(name))
         lvm_do(['lvremove', '-f', self.vg_name + '/' + name])
     remaining = [name for name, attr, pool_lv in self.query_lvs('lv_name', 'lv_attr', 'pool_lv')
                  if pool_lv == self.pool_name and attr[0] == 'V']
     if not remaining:
         lvm_do(['lvremove', '-f', self.vg_name + '/' + self.pool_name])
         self.buildroot.root_log.info("deleted LVM cache thinpool")
     self.unset_current_snapshot()
예제 #10
0
파일: lvm_root.py 프로젝트: remicollet/mock
 def hook_scrub(self, what):
     if what not in ('lvm', 'all') or not self.lv_exists(self.pool_name):
         return
     self.pool_lock.lock(exclusive=True)
     lvs = self.list_our_lvs('lv_path')
     for name, lv_path in lvs:
         for src, _ in current_mounts():
             if src == os.path.realpath(lv_path):
                 util.do(['umount', '-l', src])
         self.buildroot.root_log.info("removing {0} volume".format(name))
         lvm_do(['lvremove', '-f', self.vg_name + '/' + name])
     remaining = [name for name, attr, pool_lv in self.query_lvs('lv_name', 'lv_attr', 'pool_lv')
                  if pool_lv == self.pool_name and attr[0] == 'V']
     if not remaining:
         lvm_do(['lvremove', '-f', self.vg_name + '/' + self.pool_name])
         self.buildroot.root_log.info("deleted LVM cache thinpool")
     self.unset_current_snapshot()
예제 #11
0
 def get_container_id(self):
     """ start a container and detach immediately """
     cmd = [
         "podman", "run", "--quiet", "-i", "--detach", self.image,
         "/bin/bash"
     ]
     container_id = util.do(cmd, returnOutput=True)
     self.container_id = container_id.strip()
     return self.container_id
예제 #12
0
파일: lvm_root.py 프로젝트: tbaederr/mock
def lvm_do(*args, **kwargs):
    env = os.environ.copy()
    env['LC_ALL'] = 'C.UTF-8'
    output = util.do(*args,
                     returnOutput=True,
                     env=env,
                     returnStderr=False,
                     **kwargs)
    return output
예제 #13
0
 def hook_scrub(self, what):
     self.pool_lock.lock(exclusive=True)
     if what not in ('lvm', 'all'):
         return
     with volume_group(self.vg_name, mode='w+') as vg:
         lvs = vg.listLVs()
         for lv in lvs:
             if self._open_lv_is_our(lv):
                 try:
                     for src, _ in current_mounts():
                         if src == os.path.realpath(lv.getProperty('lv_path')[0]):
                             util.do(['umount', '-l', src])
                 except lvm.LibLVMError:
                     pass
                 self.buildroot.root_log.info(
                         "removing {0} volume".format(lv.getName()))
                 lv.remove()
         remaining = [lv for lv in vg.listLVs() if lv.getAttr()[0] == 'V' and
                      lv.getProperty('pool_lv')[0] == self.pool_name]
         if not remaining:
             pool = vg.lvFromName(self.pool_name)
             pool.remove()
             self.buildroot.root_log.info("deleted LVM cache thinpool")
     self.unset_current_snapshot()
예제 #14
0
 def execute(self, *args, **kwargs):
     self.plugins.call_hooks("preyum")
     env = self.config['environment'].copy()
     env.update(util.get_proxy_environment(self.config))
     env['LC_MESSAGES'] = 'C'
     invocation = self.build_invocation(*args)
     self.buildroot.root_log.debug(invocation)
     kwargs['printOutput'] = kwargs.get('printOutput', True)
     if self.config['verbose'] == 0:
         kwargs.pop('printOutput', None)
     else:
         kwargs['pty'] = kwargs.get('pty', True)
     self.buildroot._nuke_rpm_db()
     out = util.do(invocation, env=env, **kwargs)
     self.plugins.call_hooks("postyum")
     return out
예제 #15
0
 def remove(self):
     """ remove the container """
     cmd = ["podman", "rm", "-f", self.container_id]
     util.do(cmd)
     self.container_id = None
예제 #16
0
 def exec(self, command):
     """ exec command in container """
     cmd = ["podman", "exec", self.container_id] + command
     util.do(cmd, printOutput=True, env=self.buildroot.env)
예제 #17
0
 def pull_image(self):
     """ pull the latest image """
     getLog().info("Pulling image: %s", self.image)
     cmd = ["podman", "pull", self.image]
     util.do(cmd, printOutput=True, env=self.buildroot.env)
예제 #18
0
파일: lvm_root.py 프로젝트: mizdebsk/mock
 def force_umount_root(self):
     self.buildroot.root_log.warning("Forcibly unmounting root volume")
     util.do(['umount', '-l', self.root_path], env=self.buildroot.env)
예제 #19
0
def lvm_do(*args, **kwargs):
    with restored_ipc_ns():
        env = os.environ.copy()
        env['LC_ALL'] = 'C'
        output = util.do(*args, returnOutput=True, env=env, **kwargs)
    return output
예제 #20
0
 def doChroot(self, command, shell=True, *args, **kargs):
     """execute given command in root"""
     self._nuke_rpm_db()
     return util.do(command, chrootPath=self.make_chroot_path(),
                              env=self.env, shell=shell, *args, **kargs)
예제 #21
0
def lvm_do(*args, **kwargs):
    with restored_ipc_ns():
        util.do(*args, **kwargs)
예제 #22
0
 def force_umount(mountpoint):
     cmd = "umount -n -l %s" % mountpoint
     self.root_log.warning("Forcibly unmounting '%s' from chroot." % mountpoint)
     util.do(cmd, raiseExc=0, shell=True, env=self.env)
예제 #23
0
 def _show_path_user(self, path):
     cmd = ['/sbin/fuser', '-a', '-v', path]
     self.buildroot.root_log.debug("using 'fuser' to find users of %s" % path)
     out = util.do(cmd, returnOutput=1, raiseExc=False, env=self.buildroot.env)
     self.buildroot.root_log.debug(out)
     return out
예제 #24
0
파일: lvm_root.py 프로젝트: scvenema/mock
 def force_umount_root(self):
     self.buildroot.root_log.warning("Forcibly unmounting root volume")
     util.do(['umount', '-l', self.root_path], env=self.buildroot.env)
예제 #25
0
파일: lvm_root.py 프로젝트: mizdebsk/mock
def lvm_do(*args, **kwargs):
    env = os.environ.copy()
    env['LC_ALL'] = 'C.UTF-8'
    output = util.do(*args, returnOutput=True, env=env, **kwargs)
    return output