Got fatal exception with policy ID not exist

Bug #1435128 reported by Zhenzan Zhou
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
congress
Fix Committed
Undecided
Unassigned

Bug Description

I am able to create a rule against policy ironic:

zhenzan@zhenzan-openstack:~/workspace/congress/congress$ ocp list
+--------------------------------------+----------------+----------+--------------+-----------------------+
| id | name | owner_id | kind | description |
+--------------------------------------+----------------+----------+--------------+-----------------------+
| 15abd376-2094-4908-9cb4-6694254adc8b | classification | user | nonrecursive | default policy |
| 4921bc6b-93c9-4571-8da5-aa7f4887d65c | action | user | nonrecursive | default action policy |
| None | neutronv2 | system | nonrecursive | Datasource store |
| None | nova | system | nonrecursive | Datasource store |
| None | ironic | system | nonrecursive | Datasource store |
| None | keystone | system | nonrecursive | Datasource store |
| None | cinder | system | nonrecursive | Datasource store |
| None | glancev2 | system | nonrecursive | Datasource store |
+--------------------------------------+----------------+----------+--------------+-----------------------+

zhenzan@zhenzan-openstack:~$ ocp rule create --name test_ds ironic 'error(id):-ironic:nodes(id),not equal(id, "")'
+---------+---------------------------------------------------------------------------------------+
| Field | Value |
+---------+---------------------------------------------------------------------------------------+
| comment | None |
| id | 639b0da6-1264-4d6d-9fb3-9aa61f8b5501 |
| name | test_ds |
| rule | error(id) :- |
| | ironic:nodes(id, _x_0_1, _x_0_2, _x_0_3, _x_0_4, _x_0_5, _x_0_6, _x_0_7, _x_0_8), |
| | not equal(id, "") |
+---------+---------------------------------------------------------------------------------------+

But congress-server failed to start because it got fatal exception that policy ID ironic does not exist.

> /home/zhenzan/workspace/congress/congress/api/rule_model.py(176)change_rule()
-> if policy_name not in self.engine.theory:
(Pdb) p policy_name
u'ironic'
(Pdb) p self.engine.theory
{u'action': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7faa4da462d0>, u'classification': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7faa4c640710>}
(Pdb) n
> /home/zhenzan/workspace/congress/congress/api/rule_model.py(177)change_rule()
-> raise KeyError("Policy with ID '%s' does not exist", policy_name)
(Pdb)
KeyError: KeyError...'ironic')
> /home/zhenzan/workspace/congress/congress/api/rule_model.py(177)change_rule()
-> raise KeyError("Policy with ID '%s' does not exist", policy_name)
(Pdb) c
2015-03-23 11:23:46.689 ERROR congress.service [-] Fatal Exception:
2015-03-23 11:23:46.689 TRACE congress.service Traceback (most recent call last):
2015-03-23 11:23:46.689 TRACE congress.service File "/home/zhenzan/workspace/congress/congress/service.py", line 32, in wrapper
2015-03-23 11:23:46.689 TRACE congress.service return f(*args, **kw)
2015-03-23 11:23:46.689 TRACE congress.service File "/home/zhenzan/workspace/congress/congress/service.py", line 53, in congress_app_factory
2015-03-23 11:23:46.689 TRACE congress.service cage = harness.create(root_path, policy_path, data_path)
2015-03-23 11:23:46.689 TRACE congress.service File "/home/zhenzan/workspace/congress/congress/harness.py", line 184, in create
2015-03-23 11:23:46.689 TRACE congress.service {'policy_id': rule.policy_name})
2015-03-23 11:23:46.689 TRACE congress.service File "/home/zhenzan/workspace/congress/congress/api/rule_model.py", line 177, in change_rule
2015-03-23 11:23:46.689 TRACE congress.service raise KeyError("Policy with ID '%s' does not exist", policy_name)
2015-03-23 11:23:46.689 TRACE congress.service KeyError: ("Policy with ID '%s' does not exist", u'ironic')
2015-03-23 11:23:46.689 TRACE congress.service

So the quesiton is if we should block rule creation against system owned policy? Or it is just a bug that system owned policy is not loaded at the time?

Revision history for this message
Zhenzan Zhou (zhenzan-zhou) wrote :

Just found that it's more like a bug that system owned policies are not loaded on boot when inserting rules from DB.
Service api-policy is loaded before datasource services. So self.engine.theory doesn't have datasource policies yet.

2015-03-23 14:56:52.752 DEBUG congress.api.application [req-03cac977-63f1-45fb-914f-b2136c93510a admin 1b0d3b9acf474006984364f54a07e7dd] Handling request 'POST /v1/policies/ironic/rules' with CollectionHandler(/v1/policies/(?P<policy_id>[^/]+)/rules$) from (pid=2444) __call__ /home/zhenzan/workspace/congress/congress/api/application.py:45
> /home/zhenzan/workspace/congress/congress/api/rule_model.py(176)change_rule()
-> if policy_name not in self.engine.theory:
(Pdb) p self.engine.theory
{u'bzhou': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f75242e6890>, u'classification': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f752365c710>, u'neutronv2': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7522d96d50>, u'nova': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7522ecdd10>, u'ironic': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7522ed6050>, u'keystone': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7522eb8f50>, u'action': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f75242e67d0>, u'cinder': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7523639ed0>, u'glancev2': <congress.datalog.nonrecursive.NonrecursiveRuleTheory object at 0x7f7522da1090>}
(Pdb) p self.engine.theory.keys()
[u'bzhou', u'classification', u'neutronv2', u'nova', u'ironic', u'keystone', u'action', u'cinder', u'glancev2']
(Pdb)

Revision history for this message
Zhenzan Zhou (zhenzan-zhou) wrote :
Changed in congress:
status: New → Fix Released
status: Fix Released → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.