Closed lbergesio closed 11 years ago
In vt_manager/src/python/vt_manager/controller/dispatchers/ui/PolicyDispatcher.py, in rule_table_view, ruleTable is none and that is directed to a template, not a controller function (django's views). For some reason this does not reach the autogeneration of a table with the default name.
13 def rule_table_view(request, TableName = None): 14 15 if (not request.user.is_superuser): 16 17 return simple.direct_to_template(request, 18 template = 'not_admin.html', 19 extra_context = {'user':request.user}, 20 ) 21 else: #Admin 22 try: 23 ruleTable = RuleTableManager.getInstance(RuleTableManager.getDefaultName()) 24 # If everything runs smoothly, return normal template 25 return simple.direct_to_template( 26 request, 27 template = 'policyEngine/table_view.html', 28 extra_context = {'user': request.user, 29 'table': ruleTable} 30 ) 31 # Handle each exception and pass the error to template 32 except ZeroPolicyObjectsReturned: 33 return HttpResponseRedirect("/policies/") 34 except MultiplePolicyObjectsReturned: 35 return HttpResponseRedirect(reverse('policy_edit', args=(RuleTableManager.get DefaultName(),))) 36
There were two different problems: 1) File pypelib/persistence/backends/django/Django.py is concatenating String and Exceptions instead of str(e). Fixed. Needs to be updated in pypelib's .deb and repo. 2) Table names do not match. Explained in issue #101
*Files to modify: pypelib/persistence/backends/django/Django.py : -line 102: raise Exception("[Django Driver] Some error occurred when trying to fetch table table with name: " + tableName + ". Exception: " + e) ==> raise Exception("[Django Driver] Some error occurred when trying to fetch table table with name: " + tableName + ". Exception: " + str(e))
line: 138 Django.logger.warning('[Django Driver] Could not delete the PolicyRuleTable object with ID: %s. Exception: %s' % (tableID,e)) ==> Django.logger.warning('[Django Driver] Could not delete the PolicyRuleTable object with ID: %s. Exception: %s' % (tableID,str(e)))
There is some issue here when updating (at least the vt_manager
module) from 0.3.1 to 0.4:
Creating tables ... Project signature has changed - an evolution is required The following content types are stale and need to be deleted: vt_manager | policyrulemodel vt_manager | policyruletablemodel Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you're unsure, answer 'no'. Type 'yes' to continue, or 'no' to cancel: yes Installing custom SQL ... Installing indexes ... No fixtures found. > Evolving Database schema... /usr/lib/pymodules/python2.6/django/db/__init__.py:19: DeprecationWarning: settings.DATABASE_* is deprecated; use settings.DATABASES instead. DeprecationWarning /usr/lib/pymodules/python2.6/django/db/__init__.py:60: DeprecationWarning: Short names for ENGINE in database configurations are deprecated. Prepend default.ENGINE with 'django.db.backends.' DeprecationWarning /usr/lib/pymodules/python2.6/registration/models.py:4: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha You have requested a database evolution. This will alter tables and data currently in the 'default' database, and may result in IRREVERSABLE DATA LOSS. Evolutions should be *thoroughly* reviewed prior to execution. Are you sure you want to execute the evolutions? Type 'yes' to continue, or 'no' to cancel: yes Evolution successful.
When the staled content types ("The following content types are stale and need to be deleted") are deleted, it happens that the tables pypelib_RuleModel
and pypelib_RuleTableModel
do physically disappear, being this the cause of the 500 error.
Couldn't find out yet if it was due to the deletion of the content types or to the evolution, though.
PS: To recreate lost tables in MySQL:
CREATE TABLE pypelib_RuleModel (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, RuleUUID VARCHAR(512) NOT NULL, RuleTableName VARCHAR(512), Rule VARCHAR(2048), RuleIsEnabled TINYINT(1) NOT NULL, RulePosition INT(11) NOT NULL);
CREATE TABLE pypelib_RuleTableModel (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, type VARCHAR(16) NOT NULL, uuid VARCHAR(512) NOT NULL, name LONGTEXT NOT NULL, defaultParser VARCHAR(64), defaultPersistence VARCHAR(64), defaultPersistenceFlag TINYINT(1) NOT NULL);
Last problem was an internal problem due to some misconfiguration (another pypelib source was being used). Pay no mind to it; but symlinks shall be created for this next version of PyPElib, rather than duplicate the code for every /usr/lib/pythonX.Y
folder.
RuleTableModel reverted (field "name" was Unique, but it may lead to some problem with evolution because of some incompatibilities between the "TextField" type and the "unique" parameter.
name = models.TextField(max_length = 120, default="") # name
FIXME: set 'name' to 'unique', but that seems only possible with 'CharField'
name = models.CharField(max_length = 120, default="", unique=True) # name
When updated to "v0.4RC" and going to poicy manager 500 error is returned and following message in the log:
[RuleTable.py:246] ERROR: Unable to load RuleTable. Exception: cannot concatenate 'str' and 'DatabaseError' objects
At then the trace log says:
[Mon Dec 24 17:54:09 2012] [error] [client 147.83.206.92] TemplateSyntaxError: Caught NoReverseMatch while rendering: Reverse for 'policy_create' with arguments '('',)' and keyword arguments '{}' not found.
which seems to be related with latest changes to deal with not allowed multupla rule tables.