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/
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
Kind Regards,
--
Róman Joost
Senior Software Engineer, Products & Technologies Operations (Brisbane)
Red Hat