On Tue, May 09, 2017 at 10:43:16PM -0400, Don Zickus wrote: > Hi Dan, > > I was trying to poke through some of the server code and I was struggling to > fall the flow of the code (lots of hidden magic with turbogears and > cherrypy). Of course, with the turbogears->flask and cherrypy->flask > wrappers, it makes things more challenging. :-) > > So I thought if I start peeling away some of the cherrypy stuff it would > help me understand some of the code better. Using a lot of ignorance, I > pulled out this patch inside beaker-in-a-box:
Ok, I think I have unraveled a lot of this. Basically the httpd loads bkr/server/wsgi.py which then imports 'app' from bkr.server.app (which is the initial Flask class through PrefixedFlask). This is how all the flask stuff is expose now (@app.*). Inside bkr/sever/wsgi.py is init() and inside there is the core cherrypy stuff: # Set up old CherryPy stuff. import bkr.server.controllers cherrypy.root = bkr.server.controllers.Root() cherrypy.server.start(init_only=True, server_class=None) The Root() is the whole key to everything. That loads all the webpages into cherrypy. Though I am not entirely sure how it coordinates that with turbogears besides the turbogears decorators. So I am guessing to convert the webpages to Flask, one has to go to each file (CSV_import_export.py for example) and convert it to use Flask decorators (@app.route("...") ) and then use Flask templates instead of the kid files??? That is quite the work... Am I on the right track? If so, is it possible to go one page at a time or is it everything at once? Cheers, Don > > > diff --git a/Server/bkr/server/CSV_import_export.py > b/Server/bkr/server/CSV_import_export.py > index 41fcb26..8c98d68 100644 > --- a/Server/bkr/server/CSV_import_export.py > +++ b/Server/bkr/server/CSV_import_export.py > @@ -10,7 +10,8 @@ > from bkr.server import identity > from bkr.server.xmlrpccontroller import RPCRoot > from tempfile import NamedTemporaryFile > -from cherrypy.lib.cptools import serve_file > +#from cherrypy.lib.cptools import serve_file > +from flask import send_file > from bkr.server.model import (System, SystemType, Activity, SystemActivity, > User, Group, LabController, LabInfo, > OSMajor, OSVersion, > @@ -139,9 +140,9 @@ def action_export(self, csv_type, *args, **kw): > log = self.to_csv(file, csv_type) > file.seek(0) > > - return serve_file(file.name, contentType="text/csv", > - disposition="attachment", > - name="%s.csv" % csv_type) > + return send_file(file.name, mimetype="text/csv", > + as_attachment=True, > + attachment_filename="%s.csv" % csv_type) > > def _import_row(self, data, log): > if data['csv_type'] in system_types and ('fqdn' in data or 'id' in > data): > > Restarting the httpd service and trying to export a CSV led to a 500 > failure, with the beaker debug logs spitting out 'cherrypy can not iterate > through the response' failures. Not surprised. > > I am sure I am untangling spaghetti here, but I guess I was hoping I would > eventually hit one of your cherrypy->flask wrappers. > > Is there a good direction to go here or am I in for a long ride of > unhappiness? > > > Also for some reason when I am in IntegrationTests and run ./run-tests.sh, I > get the following error: > > > ====================================================================== > ERROR: test suite for <module 'bkr.inttest' from > '/root/git/beaker/IntegrationTests/src/bkr/inttest/__init__.pyc'> > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python2.6/site-packages/nose/suite.py", line 209, in run > self.setUp() > File "/usr/lib/python2.6/site-packages/nose/suite.py", line 292, in setUp > self.setupContext(ancestor) > File "/usr/lib/python2.6/site-packages/nose/suite.py", line 315, in > setupContext > try_run(context, names) > File "/usr/lib/python2.6/site-packages/nose/util.py", line 471, in try_run > return func() > File "/root/git/beaker/IntegrationTests/src/bkr/inttest/__init__.py", line > 351, in setup_package > data_setup.setup_model() > File > "/usr/lib/python2.6/site-packages/beaker_server-24.2-py2.6.egg/bkr/server/tests/data_setup.py", > line 51, in setup_model > connection = engine.connect() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line > 1779, in connect > return self._connection_cls(self, **kwargs) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line > 60, in __init__ > self.__connection = connection or engine.raw_connection() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line > 1848, in raw_connection > return self.pool.unique_connection() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 280, in > unique_connection > return _ConnectionFairy._checkout(self) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 641, in > _checkout > fairy = _ConnectionRecord.checkout(pool) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 440, in > checkout > rec = pool._do_get() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 961, in > _do_get > return self._create_connection() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 285, in > _create_connection > return _ConnectionRecord(self) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 411, in > __init__ > self.connection = self.__connect() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 537, in > __connect > connection = self.__pool._creator() > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/strategies.py", > line 96, in connect > connection_invalidated=invalidated > File "/usr/lib64/python2.6/site-packages/sqlalchemy/util/compat.py", line > 199, in raise_from_cause > reraise(type(exception), exception, tb=exc_tb) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/strategies.py", > line 90, in connect > return dialect.connect(*cargs, **cparams) > File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/default.py", > line 377, in connect > return self.dbapi.connect(*cargs, **cparams) > File "/usr/lib64/python2.6/site-packages/MySQLdb/__init__.py", line 81, in > Connect > return Connection(*args, **kwargs) > File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 187, > in __init__ > super(Connection, self).__init__(*args, **kwargs2) > OperationalError: (OperationalError) (1044, "Access denied for user > 'beaker'@'localhost' to database 'beaker_test'") None None > -------------------- >> begin captured logging << -------------------- > > Thoughts? > > Cheers, > Don > _______________________________________________ > Beaker-devel mailing list -- beaker-devel@lists.fedorahosted.org > To unsubscribe send an email to beaker-devel-le...@lists.fedorahosted.org _______________________________________________ Beaker-devel mailing list -- beaker-devel@lists.fedorahosted.org To unsubscribe send an email to beaker-devel-le...@lists.fedorahosted.org