Example #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)
Example #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)
Example #3
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)
Example #4
0
    def build(self):
        self.db = None
        self.storage = None

        conn = None
        try:
            self.zodbConnect()
            conn = self.db.open()
            root = conn.root()
            app = root.get('Application')
            if app and getattr(app, self.sitename, None) is not None:
                print "zport portal object exists; exiting."
                return
        except self.connectionFactory.exceptions.OperationalError as e:
            print "zenbuild: Database does not exist."
            sys.exit(1)
        finally:
            if conn:
                conn.close()
            if self.db:
                self.db.close()
                self.db = None
            if self.storage:
                self.storage.close()
                self.storage = None

        # TODO: remove the port condition, in here for now because there is no SQL dump of postgresql
        if self.options.fromXml:
            self.connect()
            from Products.ZenModel.ZentinelPortal import manage_addZentinelPortal
            manage_addZentinelPortal(self.app, self.sitename)
            site = self.app._getOb(self.sitename)

            # build index_html
            if self.app.hasObject('index_html'):
                self.app._delObject('index_html')
            from Products.PythonScripts.PythonScript import manage_addPythonScript
            manage_addPythonScript(self.app, 'index_html')
            newIndexHtml = self.app._getOb('index_html')
            text = 'container.REQUEST.RESPONSE.redirect(container.zport.virtualRoot() + "/zport/dmd/")\n'
            newIndexHtml.ZPythonScript_edit('', text)

            # build standard_error_message
            if self.app.hasObject('standard_error_message'):
                self.app._delObject('standard_error_message')
            file = open(
                zenPath('Products/ZenModel/dtml/standard_error_message.dtml'))
            try:
                text = file.read()
            finally:
                file.close()
            import OFS.DTMLMethod
            OFS.DTMLMethod.addDTMLMethod(self.app,
                                         id='standard_error_message',
                                         file=text)

            # Convert the acl_users folder at the root to a PAS folder and update
            # the login form to use the Zenoss login form
            Security.replaceACLWithPAS(self.app, deleteBackup=True)
            auth0_setup(self.app)
            account_locker_setup(self.app)

            # Add groupManager to zport.acl
            acl = site.acl_users
            if not hasattr(acl, 'groupManager'):
                plugins.ZODBGroupManager.addZODBGroupManager(
                    acl, 'groupManager')
            acl.groupManager.manage_activateInterfaces([
                'IGroupsPlugin',
            ])

            trans = transaction.get()
            trans.note("Initial ZentinelPortal load by zenbuild.py")
            trans.commit()
            print "ZentinelPortal loaded at %s" % self.sitename

            # build dmd
            from Products.ZenModel.DmdBuilder import DmdBuilder
            dmdBuilder = DmdBuilder(site, self.options.evthost,
                                    self.options.evtuser, self.options.evtpass,
                                    self.options.evtdb, self.options.evtport,
                                    self.options.smtphost,
                                    self.options.smtpport,
                                    self.options.pagecommand)
            dmdBuilder.build()
            transaction.commit()

            # Load XML Data
            from Products.ZenModel.XmlDataLoader import XmlDataLoader
            dl = XmlDataLoader(noopts=True, app=self.app)
            dl.loadDatabase()

        else:

            cmd = "gunzip -c  %s | %s --usedb=zodb" % (
                zenPath("Products/ZenModel/data/zodb.sql.gz"),
                zenPath("Products/ZenUtils/ZenDB.py"),
            )
            returncode = os.system(cmd)
            if returncode:
                print >> sys.stderr, "There was a problem creating the database from the sql dump."
                sys.exit(1)

            # Relstorage may have already loaded items into the cache in the
            # initial connection to the database. We have to expire everything
            # in the cache in order to prevent errors with overlapping
            # transactions from the model which was just imported above.
            if self.options.zodb_cacheservers:
                self.flush_memcached(self.options.zodb_cacheservers.split())

            self.connect()

            # Set all the attributes
            site = getattr(self.app, self.sitename, None)
            site.dmd.smtpHost = self.options.smtphost
            site.dmd.smtpPort = self.options.smtpport
            site.dmd.pageCommand = self.options.pagecommand
            site.dmd.uuid = None
            for evmgr in (site.dmd.ZenEventManager, site.dmd.ZenEventHistory):
                evmgr.username = self.options.evtuser
                evmgr.password = self.options.evtpass
                evmgr.database = self.options.evtdb
                evmgr.host = self.options.evthost
                evmgr.port = self.options.evtport
            transaction.commit()

        # Load reports
        from Products.ZenReports.ReportLoader import ReportLoader
        rl = ReportLoader(noopts=True, app=self.app)
        rl.loadDatabase()
Example #5
0
    def build(self):
        self.db = None
        self.storage = None

        conn = None
        try:
            self.zodbConnect()
            conn = self.db.open()
            root = conn.root()
            app = root.get('Application')
            if app and getattr(app, self.sitename, None) is not None:
                print "zport portal object exists; exiting."
                return
        except self.connectionFactory.exceptions.OperationalError as e:
            print "zenbuild: Database does not exist."
            sys.exit(1)
        finally:
            if conn:
                conn.close()
            if self.db:
                self.db.close()
                self.db = None
            if self.storage:
                self.storage.close()
                self.storage = None

        # TODO: remove the port condition, in here for now because there is no SQL dump of postgresql
        if self.options.fromXml:
            self.connect()
            from Products.ZenModel.ZentinelPortal import manage_addZentinelPortal
            manage_addZentinelPortal(self.app, self.sitename)
            site = self.app._getOb(self.sitename)

            # build index_html
            if self.app.hasObject('index_html'):
                self.app._delObject('index_html')
            from Products.PythonScripts.PythonScript import manage_addPythonScript
            manage_addPythonScript(self.app, 'index_html')
            newIndexHtml = self.app._getOb('index_html')
            text = 'container.REQUEST.RESPONSE.redirect(container.zport.virtualRoot() + "/zport/dmd/")\n'
            newIndexHtml.ZPythonScript_edit('', text)

            # build standard_error_message
            if self.app.hasObject('standard_error_message'):
                self.app._delObject('standard_error_message')
            file = open(zenPath('Products/ZenModel/dtml/standard_error_message.dtml'))
            try:
                text = file.read()
            finally:
                file.close()
            import OFS.DTMLMethod
            OFS.DTMLMethod.addDTMLMethod(self.app, id='standard_error_message',
                                            file=text)

            # Convert the acl_users folder at the root to a PAS folder and update
            # the login form to use the Zenoss login form
            Security.replaceACLWithPAS(self.app, deleteBackup=True)
            auth0_setup(self.app)
            account_locker_setup(self.app)

            # Add groupManager to zport.acl
            acl = site.acl_users
            if not hasattr(acl, 'groupManager'):
                plugins.ZODBGroupManager.addZODBGroupManager(acl, 'groupManager')
            acl.groupManager.manage_activateInterfaces(['IGroupsPlugin',])

            trans = transaction.get()
            trans.note("Initial ZentinelPortal load by zenbuild.py")
            trans.commit()
            print "ZentinelPortal loaded at %s" % self.sitename

            # build dmd
            from Products.ZenModel.DmdBuilder import DmdBuilder
            dmdBuilder = DmdBuilder(site,
                                    self.options.evthost,
                                    self.options.evtuser,
                                    self.options.evtpass,
                                    self.options.evtdb,
                                    self.options.evtport,
                                    self.options.smtphost,
                                    self.options.smtpport,
                                    self.options.pagecommand)
            dmdBuilder.build()
            transaction.commit()

            # Load XML Data
            from Products.ZenModel.XmlDataLoader import XmlDataLoader
            dl = XmlDataLoader(noopts=True, app=self.app)
            dl.loadDatabase()

        else:

            cmd = "gunzip -c  %s | %s --usedb=zodb" % (
                 zenPath("Products/ZenModel/data/zodb.sql.gz"),
                 zenPath("Products/ZenUtils/ZenDB.py"),
            )
            returncode = os.system(cmd)
            if returncode:
                print >> sys.stderr, "There was a problem creating the database from the sql dump."
                sys.exit(1)

            # Relstorage may have already loaded items into the cache in the
            # initial connection to the database. We have to expire everything
            # in the cache in order to prevent errors with overlapping
            # transactions from the model which was just imported above.
            if self.options.zodb_cacheservers:
                self.flush_memcached(self.options.zodb_cacheservers.split())

            self.connect()

            # Set all the attributes
            site = getattr(self.app, self.sitename, None)
            site.dmd.smtpHost = self.options.smtphost
            site.dmd.smtpPort = self.options.smtpport
            site.dmd.pageCommand = self.options.pagecommand
            site.dmd.uuid = None
            for evmgr in (site.dmd.ZenEventManager, site.dmd.ZenEventHistory):
                evmgr.username = self.options.evtuser
                evmgr.password = self.options.evtpass
                evmgr.database = self.options.evtdb
                evmgr.host = self.options.evthost
                evmgr.port = self.options.evtport
            transaction.commit()

        # Load reports
        from Products.ZenReports.ReportLoader import ReportLoader
        rl = ReportLoader(noopts=True, app=self.app)
        rl.loadDatabase()