On Thu, May 11, 2017 at 08:26:24AM +1000, RĂ³man Joost wrote:
Dear Don,
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:
>
>
> 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.
The typical direction is if Flask throws a 404 Beaker falls back to
cherrypy, see:
bkr/server/wsgi.py:180
> Is there a good direction to go here or am I in for a long ride of
> unhappiness?
The main idea we've been following to gradually migrate the old cherrypy
code over to flask is to expose this functionality via APIs and use
Backbone to write the UI part for it.
The Beaker docs give you a simple walk through which might give a
better, bigger picture:
https://beaker-project.org/dev/guide/source-walkthrough.html
Example migrations we've done in the past:
https://gerrit.beaker-project.org/#/c/5215/
https://gerrit.beaker-project.org/#/c/4382/
https://gerrit.beaker-project.org/#/c/4021/
Wow. Those migrations look much larger than I thought. I guess I was
thinking smaller scale just rewrite some templates/kid files into Backbone??
Granted, at least in the CSV case, some of the class inheritence would have
to come from somewhere else besides Forms. I will keep poking at it I
suppose.
> 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/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?
Check server-test.cfg and your MySQL correctly setup that the given
users credentials can access the beaker_test database. Mind you, that
script runs all tests which you probably don't want. More about running
tests is documented here:
https://beaker-project.org/dev/guide/writing-a-patch.html#testing-your-patch
Ok, so I didn't have a beaker-test DB setup. I switched to use beaker DB
from beaker-in-a-box and after numerous additional package installs
(including a 'git submodule init/update', the run-tests.sh worked (I exited
after an hour).
Then I stumbled upon Misc/beaker_test_setup.sh and after commenting out the
first 2/3 of the script and changing systemctl to service, the script ran
and setup the beaker_test DB. Then run-tests.sh worked fine.
Not sure if it makes sense to add a check in src/bkr/inttest/__init__.py to
create the database in sqlalchemy.dburi if it doesn't exist yet or
something.
Cheers,
Don