Beispiel #1
0
    def afterSetUp(self):
        super(BaseTestCase, self).afterSetUp()

        if self.disableLogging:
            logging.disable(logging.CRITICAL)

        gen = PortalGenerator()
        if hasattr(self.app, 'zport'):
            self.app._delObject('zport', suppress_events=True)

        gen.create(self.app, 'zport', True)
        # builder params:
        # portal, cvthost, evtuser, evtpass, evtdb,
        #    smtphost, smtpport, pagecommand
        builder = DmdBuilder(self.app.zport, 'localhost', 'zenoss', 'zenoss',
                             'events', 3306, 'localhost', '25', '')
        builder.build()
        self.dmd = builder.dmd
        self.dmd.ZenUsers.manage_addUser('tester', roles=('Manager', ))
        user = self.app.zport.acl_users.getUserById('tester')
        from AccessControl.SecurityManagement import newSecurityManager
        newSecurityManager(None, user)

        register_cse_virtual_root()

        # Let's hide transaction.commit() so that tests don't fubar
        # each other
        self._transaction_commit = Transaction.commit
        Transaction.commit = lambda *x: None

        setDescriptors(self.dmd)
Beispiel #2
0
    def afterSetUp(self):
        super(BaseTestCase, self).afterSetUp()

        if self.disableLogging:
            logging.disable(logging.CRITICAL)

        gen = PortalGenerator()
        if hasattr( self.app, 'zport' ):
            self.app._delObject( 'zport', suppress_events=True)

        gen.create(self.app, 'zport', True)
        # builder params:
        # portal, cvthost, evtuser, evtpass, evtdb,
        #    smtphost, smtpport, pagecommand
        builder = DmdBuilder(self.app.zport, 'localhost', 'zenoss', 'zenoss',
                            'events', 3306, 'localhost', '25', '')
        builder.build()
        self.dmd = builder.dmd
        self.dmd.ZenUsers.manage_addUser('tester', roles=('Manager',))
        user = self.app.zport.acl_users.getUserById('tester')
        from AccessControl.SecurityManagement import newSecurityManager
        newSecurityManager(None, user)

        register_cse_virtual_root()

        # Let's hide transaction.commit() so that tests don't fubar
        # each other
        self._transaction_commit = Transaction.commit
        Transaction.commit=lambda *x: None

        setDescriptors(self.dmd)
Beispiel #3
0
 def connect(self):
     if not self.app:
         connectionFactory = getUtility(IZodbFactoryLookup).get()
         self.db, self.storage = connectionFactory.getConnection(**self.options.__dict__)
     self.getDataRoot()
     self.login()
     if getattr(self.dmd, 'propertyTransformers', None) is None:
         self.dmd.propertyTransformers = {}
         commit()
     setDescriptors(self.dmd)
Beispiel #4
0
 def connect(self):
     if not self.app:
         connectionFactory = getUtility(IZodbFactoryLookup).get()
         self.db, self.storage = connectionFactory.getConnection(
             **self.options.__dict__)
     self.getDataRoot()
     self.login()
     if getattr(self.dmd, 'propertyTransformers', None) is None:
         self.dmd.propertyTransformers = {}
         commit()
     setDescriptors(self.dmd)
 def __init__(self, noopts=0, app=None, keeproot=False):
     ZenDaemon.__init__(self, noopts, keeproot)
     self.dataroot = None
     self.app = app
     self.db = None
     if not app:
         self.zodbConnect()
     self.poollock = Lock()
     self.getDataRoot()
     self.login()
     setDescriptors(self.dmd)
Beispiel #6
0
 def __init__(self, noopts=0, app=None, keeproot=False):
     ZenDaemon.__init__(self, noopts, keeproot)
     self.dataroot = None
     self.app = app
     self.db = None
     if not app:
         self.zodbConnect()
     self.poollock = Lock()
     self.getDataRoot()
     self.login()
     setDescriptors(self.dmd)
def registerDescriptors(event):
    """
    Handler for IZopeApplicationOpenedEvent which registers property descriptors.
    """
    zport = getattr(event.app, 'zport', None)
    # zport may not exist if we are using zenbuild to initialize the database
    if zport:
        try:
            setDescriptors(zport.dmd)
        except Exception, e:
            args = (e.__class__.__name__, e)
            log.info("Unable to set property descriptors: %s: %s", *args)
Beispiel #8
0
def registerDescriptors(event):
    """
    Handler for IZopeApplicationOpenedEvent which registers property descriptors.
    """
    zport = getattr(event.app, 'zport', None)
    # zport may not exist if we are using zenbuild to initialize the database
    if zport:
        try:
            setDescriptors(zport.dmd)
        except Exception as e:
            args = (e.__class__.__name__, e)
            log.info("Unable to set property descriptors: %s: %s", *args)
Beispiel #9
0
    def dmd(self):
        """
        Use a well-known connection to get a reliable dmd object.
        """
        closer = getattr(CONNECTION_ENVIRONMENT, self.CONN_MARKER, None)

        if closer is None:
            conn = self.db.open()
            setattr(CONNECTION_ENVIRONMENT, self.CONN_MARKER,
                    ConnectionCloser(conn))
            newSecurityManager(None, AccessControl.User.system)
            app = conn.root()['Application']
            # Configure zProperty descriptors
            setDescriptors(app.zport.dmd)
        else:
            app = closer.connection.root()['Application']

        return _getContext(app).zport.dmd
    def dmd(self):
        """
        Use a well-known connection to get a reliable dmd object.
        """
        closer = getattr(CONNECTION_ENVIRONMENT, self.CONN_MARKER, None)

        if closer is None:
            conn = self.db.open()
            setattr(CONNECTION_ENVIRONMENT, self.CONN_MARKER,
                    ConnectionCloser(conn))
            newSecurityManager(None, AccessControl.User.system)
            app = conn.root()['Application']
            # Configure zProperty descriptors
            setDescriptors(app.zport.dmd)
        else:
            app = closer.connection.root()['Application']

        return app.zport.dmd
Beispiel #11
0
    def afterSetUp(self):

        super(BaseTestCase, self).afterSetUp()

        if self.disableLogging:
            logging.disable(logging.CRITICAL)

        gen = PortalGenerator()
        if hasattr(self.app, "zport"):
            self.app._delObject("zport", suppress_events=True)
        gen.create(self.app, "zport", True)
        # builder params:
        # portal, cvthost, evtuser, evtpass, evtdb,
        #    smtphost, smtpport, pagecommand
        builder = DmdBuilder(
            self.app.zport,
            "localhost",
            "zenoss",
            "zenoss",
            "events",
            3306,
            "localhost",
            "25",
            "$ZENHOME/bin/zensnpp localhost 444 $RECIPIENT",
        )
        builder.build()
        self.dmd = builder.dmd

        self.dmd.ZenUsers.manage_addUser("tester", roles=("Manager",))
        user = self.app.zport.acl_users.getUserById("tester")
        from AccessControl.SecurityManagement import newSecurityManager

        newSecurityManager(None, user)

        # Let's hide transaction.commit() so that tests don't fubar
        # each other
        self._transaction_commit = Transaction.commit
        Transaction.commit = lambda *x: None

        setDescriptors(self.dmd)
Beispiel #12
0
def zodb(db, userid, log):
    """Return the DMD context via contextmanager protocol.

    :param db: ZODB database connection.
    :param str userid: The ID of the user to authenticate with.
    """
    session = db.open()
    try:
        mlog.debug("Started ZODB session")
        root = session.root()
        application = _getContext(root["Application"])
        dataroot = getObjByPath(application, "/zport/dmd")
        user = _login(dataroot, userid=userid)
        setDescriptors(dataroot)
        log_mesg = ("Authenticated as user %s", user.getUserName())
        log.info(*log_mesg)
        mlog.debug(*log_mesg)
        try:
            yield dataroot
        finally:
            noSecurityManager()
    finally:
        session.close()
        mlog.debug("Finished ZODB session")