[openstack-dev] [Congress] Confused syntax error when inserting rule.

Rui Chen chenrui.momo at gmail.com
Mon Aug 17 01:44:20 UTC 2015


Thanks for your clarification. I think the root reason is hidden variables
that generated by policy engine.

*error(id) :- cinder:volumes(id=id), not avail_cinder_vol(id)*
*avail_cinder_vol(id) :- cinder:volumes(id=id, status="available")*

It's a good idea, keep the rules simple and readable.

It point out a best practice that the negative and positive literal of same
table shouldn't exist in one rule.

Thank you very much.

2015-08-14 21:38 GMT+08:00 Tim Hinrichs <tim at styra.com>:

> Hi Rui,
>
> The problem with the following rule is that there are a bunch of hidden
> variables in the "not cinder:volumes(...)" literal.  The error message
> shows the hidden variables.  The syntax restriction is that every variable
> in a negative literal must appear in a positive literal in the body.  Those
> hidden variables fail to satisfy that restriction, hence the error.
>
>  error(id) :- cinder:volumes(id=id), not cinder:volumes(id=id,
> status="available")
>
> The reason the other rule worked is that you made the hidden variables
> equivalent to the ones in the positive literal, e.g. x_0_1 shows up in both
> the positive and negative literals.
>
> error(x) :- cinder:volumes(x, _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 cinder:volumes(x, _x_0_1, _x_0_2,
> \"available\",_x_0_4, _x_0_5, _x_0_6, _x_0_7, _x_0_8)
>
> But in the auto-generated one, the variables in the two literals are
> different e.g. _x_0_1 and _x_1_1
>
> error(id) :- cinder:volumes(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 cinder:volumes(id, _x_1_1, _x_1_2,
> "available", _x_1_4, _x_1_5, _x_1_6, _x_1_7, _x_1_8).  Unsafe lits: not
> cinder:volumes(id, _x_1_1, _x_1_2, "available", _x_1_4, _x_1_5, _x_1_6,
> _x_1_7, _x_1_8)
>
> Probably the solution you want is to write 2 rules:
>
> error(id) :- cinder:volumes(id=id), not avail_cinder_vol(id)
> avail_cinder_vol(id) :- cinder:volumes(id=id, status="available")
>
> Tim
>
> On Thu, Aug 13, 2015 at 8:07 PM Rui Chen <chenrui.momo at gmail.com> wrote:
>
>> Sorry, send the same mail again, please comments at here, the other mail
>> lack title.
>>
>> 2015-08-14 11:03 GMT+08:00 Rui Chen <chenrui.momo at gmail.com>:
>>
>>> Hi folks:
>>>
>>>     I face a problem when I insert a rule into Congress. I want to find
>>> out all of the volumes that are not available status, so I draft a rule
>>> like this:
>>>
>>>     error(id) :- cinder:volumes(id=id), not cinder:volumes(id=id,
>>> status="available")
>>>
>>>     But when I create the rule, a error is raised:
>>>
>>> (openstack) congress policy rule create chenrui_p "error(id) :-
>>> cinder:volumes(id=id),not cinder:volumes(id=id, status=\"available\")"
>>> ERROR: openstack Syntax error for rule::Errors: Could not reorder rule
>>> error(id) :- cinder:volumes(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 cinder:volumes(id, _x_1_1, _x_1_2,
>>> "available", _x_1_4, _x_1_5, _x_1_6, _x_1_7, _x_1_8).  Unsafe lits: not
>>> cinder:volumes(id, _x_1_1, _x_1_2, "available", _x_1_4, _x_1_5, _x_1_6,
>>> _x_1_7, _x_1_8) (vars set(['_x_1_2', '_x_1_1', '_x_1_6', '_x_1_7',
>>> '_x_1_4', '_x_1_5', '_x_1_8'])) (HTTP 400) (Request-ID:
>>> req-1f4432d6-f869-472b-aa7d-4cf78dd96fa1)
>>>
>>>     I check the Congress policy docs [1], looks like that the rule don't
>>> break any syntax restrictions.
>>>
>>>     If I modify the rule like this, it works:
>>>
>>> (openstack) congress policy rule create chenrui_p "error(x) :-
>>> cinder:volumes(x, _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 cinder:volumes(x, _x_0_1, _x_0_2, \"available\",_x_0_4, _x_0_5,
>>> _x_0_6, _x_0_7, _x_0_8)"
>>>
>>> +---------+------------------------------------------------------------------------------------------------+
>>> | Field   | Value
>>>                                    |
>>>
>>> +---------+------------------------------------------------------------------------------------------------+
>>> | comment | None
>>>                                   |
>>> | id      | ad121e09-ba0a-45d6-bd18-487d975d5bf5
>>>                                   |
>>> | name    | None
>>>                                   |
>>> | rule    | error(x) :-
>>>                                    |
>>> |         |     cinder:volumes(x, _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 cinder:volumes(x, _x_0_1, _x_0_2, "available",
>>> _x_0_4, _x_0_5, _x_0_6, _x_0_7, _x_0_8) |
>>>
>>> +---------+------------------------------------------------------------------------------------------------+
>>>
>>>     I'm not sure this is a bug or I miss something from docs, so I need
>>> some feedback from mail list.
>>> Feel free to discuss about it.
>>>
>>>
>>> [1]:
>>> http://congress.readthedocs.org/en/latest/policy.html#datalog-syntax-restrictions
>>>
>>>
>>> Best Regards.
>>>
>>
>> __________________________________________________________________________
>> OpenStack Development Mailing List (not for usage questions)
>> Unsubscribe:
>> OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>>
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150817/2156c0c8/attachment.html>


More information about the OpenStack-dev mailing list