Exemplo n.º 1
0
 def test(self):
     targetId = 666
     srcFd, srcPath = tempfile.mkstemp()
     os.close(srcFd)
     fileUtils.chown(srcPath, targetId, targetId)
     stat = os.stat(srcPath)
     self.assertTrue(stat.st_uid == stat.st_gid == targetId)
     os.unlink(srcPath)
Exemplo n.º 2
0
 def test(self):
     targetId = 666
     srcFd, srcPath = tempfile.mkstemp()
     os.close(srcFd)
     fileUtils.chown(srcPath, targetId, targetId)
     stat = os.stat(srcPath)
     self.assertTrue(stat.st_uid == stat.st_gid == targetId)
     os.unlink(srcPath)
Exemplo n.º 3
0
def main():
    try:
        logging.config.fileConfig(LOG_CONF_PATH)
    except:
        logging.basicConfig(filename='/dev/stdout',
                            filemode='w+',
                            level=logging.DEBUG)
        log = logging.getLogger("SuperVdsm.Server")
        log.warn("Could not init proper logging", exc_info=True)

    log = logging.getLogger("SuperVdsm.Server")
    try:
        log.debug("Making sure I'm root")
        if os.geteuid() != 0:
            sys.exit(errno.EPERM)

        log.debug("Parsing cmd args")
        authkey, parentPid = sys.argv[1:]

        log.debug("Creating PID file")
        with open(PIDFILE, "w") as f:
            f.write(str(os.getpid()) + "\n")

        log.debug("Cleaning old socket")
        if os.path.exists(ADDRESS):
            os.unlink(ADDRESS)

        log.debug("Setting up keep alive thread")
        monThread = threading.Thread(target=__pokeParent,
                                     args=[int(parentPid)])
        monThread.setDaemon(True)
        monThread.start()

        log.debug("Creating remote object manager")
        manager = _SuperVdsmManager(address=ADDRESS, authkey=authkey)
        manager.register('instance', callable=_SuperVdsm)

        server = manager.get_server()
        servThread = threading.Thread(target=server.serve_forever)
        servThread.setDaemon(True)
        servThread.start()

        chown(ADDRESS, METADATA_USER, METADATA_GROUP)

        log.debug("Started serving super vdsm object")
        servThread.join()
    except Exception:
        log.error("Could not start Super Vdsm", exc_info=True)
        sys.exit(1)
    finally:
        try:
            os.unlink(ADDRESS)
        except OSError:
            pass
Exemplo n.º 4
0
    def testNames(self):
        # I convert to some id because I have no
        # idea what users are defined and what
        # there IDs are apart from root
        tmpId = 666
        with temporaryPath() as srcPath:
            fileUtils.chown(srcPath, tmpId, tmpId)
            stat = os.stat(srcPath)
            self.assertTrue(stat.st_uid == stat.st_gid == tmpId)

            fileUtils.chown(srcPath, "root", "root")
            stat = os.stat(srcPath)
            self.assertTrue(stat.st_uid == stat.st_gid == 0)
Exemplo n.º 5
0
    def testNames(self):
        # I convert to some id because I have no
        # idea what users are defined and what
        # there IDs are apart from root
        tmpId = 666
        with temporaryPath() as srcPath:
            fileUtils.chown(srcPath, tmpId, tmpId)
            stat = os.stat(srcPath)
            self.assertTrue(stat.st_uid == stat.st_gid == tmpId)

            fileUtils.chown(srcPath, "root", "root")
            stat = os.stat(srcPath)
            self.assertTrue(stat.st_uid == stat.st_gid == 0)
Exemplo n.º 6
0
def main():
    try:
        logging.config.fileConfig(LOG_CONF_PATH)
    except:
        logging.basicConfig(filename='/dev/stdout', filemode='w+', level=logging.DEBUG)
        log = logging.getLogger("SuperVdsm.Server")
        log.warn("Could not init proper logging", exc_info=True)

    log = logging.getLogger("SuperVdsm.Server")
    try:
        log.debug("Making sure I'm root")
        if os.geteuid() != 0:
            sys.exit(errno.EPERM)

        log.debug("Parsing cmd args")
        authkey, parentPid = sys.argv[1:]

        log.debug("Creating PID file")
        with open(PIDFILE, "w") as f:
            f.write(str(os.getpid()) + "\n")

        log.debug("Cleaning old socket")
        if os.path.exists(ADDRESS):
            os.unlink(ADDRESS)

        log.debug("Setting up keep alive thread")
        monThread = threading.Thread(target=__pokeParent, args=[int(parentPid)])
        monThread.setDaemon(True)
        monThread.start()

        log.debug("Creating remote object manager")
        manager = _SuperVdsmManager(address=ADDRESS, authkey=authkey)
        manager.register('instance', callable=_SuperVdsm)

        server = manager.get_server()
        servThread = threading.Thread(target=server.serve_forever)
        servThread.setDaemon(True)
        servThread.start()

        chown(ADDRESS, METADATA_USER, METADATA_GROUP)

        log.debug("Started serving super vdsm object")
        servThread.join()
    except Exception:
        log.error("Could not start Super Vdsm", exc_info=True)
        sys.exit(1)
    finally:
        try:
            os.unlink(ADDRESS)
        except OSError:
            pass
Exemplo n.º 7
0
    def testNames(self):
        # I convert to some id because I have no
        # idea what users are defined and what
        # there IDs are apart from root
        tmpId = 666
        srcFd, srcPath = tempfile.mkstemp()
        os.close(srcFd)
        fileUtils.chown(srcPath, tmpId, tmpId)
        stat = os.stat(srcPath)
        self.assertTrue(stat.st_uid == stat.st_gid == tmpId)

        fileUtils.chown(srcPath, "root", "root")
        stat = os.stat(srcPath)
        self.assertTrue(stat.st_uid == stat.st_gid == 0)
Exemplo n.º 8
0
    def testNames(self):
        # I convert to some id because I have no
        # idea what users are defined and what
        # there IDs are apart from root
        tmpId = 666
        srcFd, srcPath = tempfile.mkstemp()
        os.close(srcFd)
        fileUtils.chown(srcPath, tmpId, tmpId)
        stat = os.stat(srcPath)
        self.assertTrue(stat.st_uid == stat.st_gid == tmpId)

        fileUtils.chown(srcPath, "root", "root")
        stat = os.stat(srcPath)
        self.assertTrue(stat.st_uid == stat.st_gid == 0)
Exemplo n.º 9
0
 def __init__(self, upgradeName):
     self._upgradeName = upgradeName
     self._upgradeFilePath = os.path.join(P_VDSM_LIB, 'upgrade',
                                          self._upgradeName)
     try:
         # First load normal VDSM loggers, then the upgrade logger.
         # This will override VDSM's root logger but will keep the other
         # loggers intact. During an upgrade we add the update handler
         # to all loggers.
         logging.config.fileConfig(P_VDSM_CONF + 'logger.conf',
                                   disable_existing_loggers=False)
         logging.config.fileConfig(P_VDSM_CONF + 'upgrade.logger.conf',
                                   disable_existing_loggers=False)
         chown(os.path.join(P_VDSM_LOG, 'upgrade.log'), VDSM_USER,
               VDSM_GROUP)
     except Exception:
         logging.getLogger('upgrade').addHandler(SysLogHandler('/dev/log'))
         logging.exception("Could not init proper logging")
     finally:
         self.log = logging.getLogger('upgrade')
Exemplo n.º 10
0
 def __init__(self, upgradeName):
     self._upgradeName = upgradeName
     self._upgradeFilePath = os.path.join(P_VDSM_LIB,
                                          'upgrade', self._upgradeName)
     try:
         # First load normal VDSM loggers, then the upgrade logger.
         # This will override VDSM's root logger but will keep the other
         # loggers intact. During an upgrade we add the update handler
         # to all loggers.
         logging.config.fileConfig(P_VDSM_CONF + 'logger.conf')
         logging.config.fileConfig(P_VDSM_CONF + 'upgrade.logger.conf',
                                   disable_existing_loggers=False)
         chown(
             os.path.join(P_VDSM_LOG, 'upgrade.log'),
             VDSM_USER,
             VDSM_GROUP)
     except Exception:
         logging.getLogger('upgrade').addHandler(SysLogHandler('/dev/log'))
         logging.exception("Could not init proper logging")
     finally:
         self.log = logging.getLogger('upgrade')
Exemplo n.º 11
0
 def test(self):
     targetId = 666
     with temporaryPath() as srcPath:
         fileUtils.chown(srcPath, targetId, targetId)
         stat = os.stat(srcPath)
         self.assertTrue(stat.st_uid == stat.st_gid == targetId)
Exemplo n.º 12
0
 def test(self):
     targetId = 666
     with temporaryPath() as srcPath:
         fileUtils.chown(srcPath, targetId, targetId)
         stat = os.stat(srcPath)
         self.assertTrue(stat.st_uid == stat.st_gid == targetId)
Exemplo n.º 13
0
def main():
    def bind(func):
        def wrapper(_SuperVdsm, *args, **kwargs):
            return func(*args, **kwargs)
        return wrapper

    for name, func in listPublicFunctions():
        setattr(_SuperVdsm, name, logDecorator(bind(func)))

    try:
        logging.config.fileConfig(LOG_CONF_PATH)
    except:
        logging.basicConfig(filename='/dev/stdout', filemode='w+',
                            level=logging.DEBUG)
        log = logging.getLogger("SuperVdsm.Server")
        log.warn("Could not init proper logging", exc_info=True)

    log = logging.getLogger("SuperVdsm.Server")

    try:
        log.debug("Making sure I'm root - SuperVdsm")
        if os.geteuid() != 0:
            sys.exit(errno.EPERM)

        pidfile = P_VDSM_RUN + 'supervdsmd.pid'
        pid = str(os.getpid())
        with open(pidfile, 'w') as f:
            f.write(pid + "\n")

        log.debug("Parsing cmd args")
        address = sys.argv[1]

        log.debug("Cleaning old socket %s", address)
        if os.path.exists(address):
            os.unlink(address)

        log.debug("Setting up keep alive thread")

        try:
            log.debug("Creating remote object manager")
            manager = _SuperVdsmManager(address=address, authkey='')
            manager.register('instance', callable=_SuperVdsm)

            server = manager.get_server()
            servThread = threading.Thread(target=server.serve_forever)
            servThread.setDaemon(True)
            servThread.start()

            chown(address, getpwnam(VDSM_USER).pw_uid, METADATA_GROUP)

            log.debug("Started serving super vdsm object")

            threading.Thread(target=sourceRouteThread.subscribeToInotifyLoop(),
                             name='sourceRoute').start()

            # Python bug of thread.join() will block signal
            # http://bugs.python.org/issue1167930
            while servThread.isAlive():
                servThread.join(5)
        finally:
            if os.path.exists(address):
                utils.rmFile(address)

    except Exception:
        log.error("Could not start Super Vdsm", exc_info=True)
        sys.exit(1)