コード例 #1
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)
コード例 #2
0
ファイル: fileUtilTests.py プロジェクト: yingyun001/vdsm
    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)
コード例 #3
0
def main(args):
    try:
        __assertSingleInstance()
        parser = option_parser()
        args = parser.parse_args(args=args)

        # Override user and group if called with --user and --group.
        constants.VDSM_USER = args.user
        constants.VDSM_GROUP = args.group

        # Override storage-repository, used to verify file access.
        sc.REPO_DATA_CENTER = args.data_center
        sc.REPO_MOUNT_DIR = os.path.join(args.data_center, sc.DOMAIN_MNT_POINT)

        try:
            logging.config.fileConfig(args.logger_conf,
                                      disable_existing_loggers=False)
        except Exception as e:
            raise FatalError("Cannot configure logging: %s" % e)

        log = logging.getLogger("SuperVdsm.Server")
        sockfile = args.sockfile
        pidfile = args.pidfile
        if not config.getboolean('vars', 'core_dump_enable'):
            resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
        sigutils.register()
        zombiereaper.registerSignalHandler()

        def bind(func):
            def wrapper(_SuperVdsm, *args, **kwargs):
                return func(*args, **kwargs)

            return wrapper

        if args.enable_gluster:
            for name, func in listPublicFunctions(
                    constants.GLUSTER_MGMT_ENABLED):
                setattr(_SuperVdsm, name, bind(logDecorator(func)))

        for _, module_name, _ in pkgutil.iter_modules(
            [supervdsm_api.__path__[0]]):
            module = importlib.import_module(
                '%s.%s' % (supervdsm_api.__name__, module_name))
            api_funcs = [
                f for _, f in six.iteritems(module.__dict__)
                if callable(f) and getattr(f, 'exposed_api', False)
            ]
            for func in api_funcs:
                setattr(_SuperVdsm, func.__name__, bind(logDecorator(func)))

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

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

        log.debug("Parsing cmd args")
        address = sockfile

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

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

        try:
            signal.signal(signal.SIGTERM, terminate)
            signal.signal(signal.SIGINT, terminate)

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

            server = manager.get_server()
            servThread = concurrent.thread(server.serve_forever)
            servThread.start()

            chown(address, args.user, args.group)

            if args.enable_network:
                init_privileged_network_components()

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

            while _running:
                sigutils.wait_for_signal()

            log.debug("Terminated normally")
        finally:
            if os.path.exists(address):
                fileutils.rm_file(address)

    except Exception as e:
        syslog.syslog("Supervdsm failed to start: %s" % e)
        # Make it easy to debug via the shell
        raise
コード例 #4
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)
コード例 #5
0
ファイル: supervdsm_server.py プロジェクト: nirs/vdsm
def main(args):
    try:
        __assertSingleInstance()
        parser = option_parser()
        args = parser.parse_args(args=args)

        # Override user and group if called with --user and --group.
        constants.VDSM_USER = args.user
        constants.VDSM_GROUP = args.group

        # Override storage-repository, used to verify file access.
        sc.REPO_DATA_CENTER = args.data_center
        sc.REPO_MOUNT_DIR = os.path.join(args.data_center, sc.DOMAIN_MNT_POINT)

        try:
            logging.config.fileConfig(args.logger_conf,
                                      disable_existing_loggers=False)
        except Exception as e:
            raise FatalError("Cannot configure logging: %s" % e)

        log = logging.getLogger("SuperVdsm.Server")
        sockfile = args.sockfile
        pidfile = args.pidfile
        if not config.getboolean('vars', 'core_dump_enable'):
            resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
        sigutils.register()
        zombiereaper.registerSignalHandler()

        def bind(func):
            def wrapper(_SuperVdsm, *args, **kwargs):
                return func(*args, **kwargs)
            return wrapper

        if args.enable_gluster:
            for name, func in listPublicFunctions(
                    constants.GLUSTER_MGMT_ENABLED):
                setattr(_SuperVdsm, name, bind(logDecorator(func)))

        for _, module_name, _ in pkgutil.iter_modules([supervdsm_api.
                                                       __path__[0]]):
            module = importlib.import_module('%s.%s' %
                                             (supervdsm_api.__name__,
                                              module_name))
            api_funcs = [f for _, f in six.iteritems(module.__dict__)
                         if callable(f) and getattr(f, 'exposed_api', False)]
            for func in api_funcs:
                setattr(_SuperVdsm, func.__name__, bind(logDecorator(func)))

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

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

        log.debug("Parsing cmd args")
        address = sockfile

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

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

        try:
            signal.signal(signal.SIGTERM, terminate)
            signal.signal(signal.SIGINT, terminate)

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

            server = manager.get_server()
            servThread = concurrent.thread(server.serve_forever)
            servThread.start()

            chown(address, args.user, args.group)

            if args.enable_network:
                init_privileged_network_components()

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

            while _running:
                sigutils.wait_for_signal()

            log.debug("Terminated normally")
        finally:
            if os.path.exists(address):
                fileutils.rm_file(address)

    except Exception as e:
        syslog.syslog("Supervdsm failed to start: %s" % e)
        # Make it easy to debug via the shell
        raise
コード例 #6
0
ファイル: fileUtilTests.py プロジェクト: yingyun001/vdsm
 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)
コード例 #7
0
ファイル: supervdsm_server.py プロジェクト: gobindadas/vdsm
def main(args):
    log = logging.getLogger("SuperVdsm.Server")
    parser = option_parser()
    args = parser.parse_args(args=args)
    sockfile = args.sockfile
    pidfile = args.pidfile
    if not config.getboolean('vars', 'core_dump_enable'):
        resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
    sigutils.register()
    zombiereaper.registerSignalHandler()

    def bind(func):
        def wrapper(_SuperVdsm, *args, **kwargs):
            return func(*args, **kwargs)

        return wrapper

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

    for _, module_name, _ in pkgutil.iter_modules([supervdsm_api.__path__[0]]):
        module = importlib.import_module('%s.%s' %
                                         (supervdsm_api.__name__, module_name))
        api_funcs = [
            f for _, f in module.__dict__.iteritems()
            if callable(f) and getattr(f, 'exposed_api', False)
        ]
        for func in api_funcs:
            setattr(_SuperVdsm, func.__name__, bind(logDecorator(func)))

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

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

        log.debug("Parsing cmd args")
        address = sockfile

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

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

        try:
            signal.signal(signal.SIGTERM, terminate)
            signal.signal(signal.SIGINT, terminate)

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

            server = manager.get_server()
            servThread = concurrent.thread(server.serve_forever)
            servThread.start()

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

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

            init_privileged_network_components()

            while _running:
                sigutils.wait_for_signal()

            log.debug("Terminated normally")
        finally:
            if os.path.exists(address):
                fileutils.rm_file(address)

    except Exception:
        log.error("Could not start Super Vdsm", exc_info=True)
        sys.exit(1)
コード例 #8
0
ファイル: fileutil_test.py プロジェクト: guozhonghua216/vdsm
def test_chown():
    targetId = 666
    with temporaryPath() as srcPath:
        fileUtils.chown(srcPath, targetId, targetId)
        stat = os.stat(srcPath)
        assert stat.st_uid == stat.st_gid == targetId
コード例 #9
0
ファイル: supervdsm_server.py プロジェクト: EdDev/vdsm
def main(args):
    log = logging.getLogger("SuperVdsm.Server")
    parser = option_parser()
    args = parser.parse_args(args=args)
    sockfile = args.sockfile
    pidfile = args.pidfile
    if not config.getboolean('vars', 'core_dump_enable'):
        resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
    sigutils.register()
    zombiereaper.registerSignalHandler()

    def bind(func):
        def wrapper(_SuperVdsm, *args, **kwargs):
            return func(*args, **kwargs)
        return wrapper

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

    for _, module_name, _ in pkgutil.iter_modules([supervdsm_api.__path__[0]]):
        module = importlib.import_module('%s.%s' %
                                         (supervdsm_api.__name__,
                                          module_name))
        api_funcs = [f for _, f in module.__dict__.iteritems()
                     if callable(f) and getattr(f, 'exposed_api', False)]
        for func in api_funcs:
            setattr(_SuperVdsm, func.__name__, bind(logDecorator(func)))

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

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

        log.debug("Parsing cmd args")
        address = sockfile

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

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

        try:
            signal.signal(signal.SIGTERM, terminate)
            signal.signal(signal.SIGINT, terminate)

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

            server = manager.get_server()
            servThread = concurrent.thread(server.serve_forever)
            servThread.start()

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

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

            init_privileged_network_components()

            while _running:
                sigutils.wait_for_signal()

            log.debug("Terminated normally")
        finally:
            if os.path.exists(address):
                fileutils.rm_file(address)

    except Exception:
        log.error("Could not start Super Vdsm", exc_info=True)
        sys.exit(1)
コード例 #10
0
def _set_db_ownership():
    sys.stdout.write("Setting up ownership of database file to %s:%s\n" %
                     (constants.VDSM_USER, constants.VDSM_GROUP))
    fileUtils.chown(mvdb.DB_FILE, constants.VDSM_USER, constants.VDSM_GROUP)