fp7-ofelia / ocf

OFELIA Control Framework (OCF) is a set of software tools for testbed management.
http://fp7-ofelia.github.com/ocf/
Other
18 stars 14 forks source link

Settings not accessible from manage.py #163

Closed CarolinaFernandez closed 11 years ago

CarolinaFernandez commented 11 years ago

Models from plugins are not being synchronized when a user installs OCF from scratch (via OFVER). This has something to do with the INSTALLED_APPS setting loaded at Django startup.

Error trace reported by Alessio del Chiaro (30/05/13 12:27):

[Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] mod_wsgi (pid=6123): Exception occurred processing WSGI script '/opt/ofelia/expedient/src/wsgi/expedient/clearinghouse/django.wsgi'. [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] Traceback (most recent call last): [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 241, in call [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] response = self.get_response(request) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 141, in get_response [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] return self.handle_uncaught_exception(request, resolver, sys.exc_info()) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 100, in get_response [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] response = callback(request, _callback_args, *_callback_kwargs) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/opt/ofelia/expedient/src/python/plugins/vt_plugin/controller/vtAggregateController/vtAggregateController.py", line 58, in aggregate_crud [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] client = client_form.save() [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/forms/models.py", line 377, in save [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] fail_message, commit, construct=False) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/forms/models.py", line 86, in save_instance [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] instance.save() [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 434, in save [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] self.save_base(using=using, force_insert=force_insert, force_update=force_update) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 527, in save_base [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] result = manager._insert(values, return_id=update_pk, using=using) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 195, in _insert [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] return insert_query(self.model, values, **kwargs) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 1479, in insert_query [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] return query.get_compiler(using=using).execute_sql(return_id) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 783, in execute_sql [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] cursor = super(SQLInsertCompiler, self).execute_sql(None) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 727, in execute_sql [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] cursor.execute(sql, params) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 15, in execute [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] return self.cursor.execute(sql, params) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line 86, in execute [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] return self.cursor.execute(query, args) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] self.errorhandler(self, exc, value) [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] raise errorclass, errorvalue [Thu May 30 03:05:01 2013] [error] [client 10.216.48.4] DatabaseError: (1146, "Table 'expedient.vt_plugin_xmlrpcserverproxy' doesn't exist")

CarolinaFernandez commented 11 years ago

When a user installs OCF from scratch (via OFVER) and the manage.py syncdb is executed, the apps at INSTALLED_APPS are not available anymore (because settings loading was moved to urls.py file, see #158 ) and thus the tables won't be created.

To solve this, a quick fix was added into plugin.py where the INSTALLED_APPS setting for each plugin is added to the settings if not already present (which will be the case when the entry point is manage.py instead of a normal HttpRequest).

File: expedient/src/python/expedient/clearinghouse/defaultsettings/plugin.py

# Set path for plugins (set at 'expedient/common/utils/plugins/pluginloader.py')
PLUGINS_PATH = os.path.join(settings.SRC_DIR,"python","plugins")
#sys.path.append(PLUGIN_LOADER.plugins_path)
sys.path.append(os.path.join(PLUGINS_PATH))

# Ugly hack to add "INSTALLED_APPS" to the settings
# even when OCF is loaded via manage.py (remember that
# setting will only load now when urls.py is loaded)

import ast
import ConfigParser

confparser = ConfigParser.RawConfigParser()
setting = "installed_apps"

for plugin_name in os.listdir(PLUGINS_PATH):
    if os.path.isdir(os.path.join(PLUGINS_PATH, plugin_name)):
        confparser.readfp(open(os.path.join(PLUGINS_PATH, plugin_name, "settings.conf")))
        if confparser.has_section("general"):
            conf_setting = list()
            if hasattr(settings, setting.upper()):
                conf_setting = getattr(settings, setting.upper()) or conf_setting
            try:
                plugin_setting = ast.literal_eval(confparser.get("general", "installed_apps"))
                # Users may set one app only and not wrap this into a list. Wrap it here
                if not isinstance(plugin_setting, list):
                    plugin_setting = [ '%s' % str(plugin_setting) ]
                # If no setting for plugins has been set in INSTALLED_APPS, add these now
                if [ p for p in plugin_setting if p not in conf_setting ]:
                    setattr(settings, setting.upper(), conf_setting + plugin_setting)
            except:
                pass