Bug 1104656

Summary: support for complex rules and better handling of invalid rules
Product: Red Hat Enterprise Linux 7 Reporter: Tomas Jelinek <tojeline>
Component: pcsAssignee: Tomas Jelinek <tojeline>
Status: CLOSED ERRATA QA Contact: Martin Juricek <mjuricek>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: cfeist, cluster-maint, mjuricek, rsteiger, slevine, tojeline
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcs-0.9.126-1.el7 Doc Type: Bug Fix
Doc Text:
Cause: User enters invalid or complex rule in 'pcs constraint location' command. Consequence: Depending on the rule pcs crashes, produces invalid rule or invalid CIB. Fix: Implement new rule parser supporting complex rules and providing explanatory error messages when the rule is invalid. Result: For valid rules pcs saves the rule into CIB correctly. For invalid rules pcs provides an explanatory error message and exits gracefully.
Story Points: ---
Clone Of:
: 1129869 (view as bug list) Environment:
Last Closed: 2015-03-05 09:19:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1129869    
Attachments:
Description Flags
proposed fix none

Description Tomas Jelinek 2014-06-04 12:51:28 UTC
Description of problem:
pcs supports simple rules like
#uname eq node1
or
#uname ne node1 and #uname ne node2 and #uname ne node3
but not rules with both 'or' and 'and' operators.

If invalid rule is specified by the user, the pcs fails to handle it and exits with traceback or creates an invalid CIB and tries to push it into pacemaker which leads to invalid CIB printed to terminal.

Version-Release number of selected component (if applicable):
pcs-0.9.115-32.el7

How reproducible:
Always

Steps to Reproduce:
1. create cluster with resource 'dummy'
2. run these commands:
  A) pcs constraint location dummy rule '#uname' ne
  B) pcs constraint location dummy rule '#uname' ne node1 and
  C) pcs constraint location dummy rule '#uname' ne node1 and '#uname' ne
  D) pcs constraint location dummy rule '#uname' ne node1 and '#uname' ne node2 or '#uname' ne node3

Actual results:
A) pcs exits with traceback
B,C) invalid CIB is dumped into terminal
D) pcs exits without error, but created rule is not correct
<rule id="location-dummy-rule" score="INFINITY">
  <expression attribute="#uname" id="location-dummy-rule-expr-1" operation="ne" value="node3"/>
</rule>

Expected results:
In case of valid rule process it right and create correct rule in CIB.
In case of invalid rule do not crash, do not dump invalid CIB, provide explanatory error message.

Comment 2 Tomas Jelinek 2014-07-18 12:00:54 UTC
Created attachment 919059 [details]
proposed fix

Comment 5 Tomas Jelinek 2014-09-11 09:29:38 UTC
Before Fix:
[root@rh70-node1 ~]# rpm -q pcs
pcs-0.9.115-32.el7.x86_64
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne
Traceback (most recent call last):
  File "/usr/sbin/pcs", line 135, in <module>
    main(sys.argv[1:])
  File "/usr/sbin/pcs", line 122, in main
    constraint.constraint_cmd(argv)
  File "/usr/lib/python2.7/site-packages/pcs/constraint.py", line 32, in constraint_cmd
    location_rule([sub_cmd2] + argv)
  File "/usr/lib/python2.7/site-packages/pcs/constraint.py", line 838, in location_rule
    utils.rule_add(lc, argv)
  File "/usr/lib/python2.7/site-packages/pcs/utils.py", line 935, in rule_add
    if args[-1] == "or" or args[-1] == "and":
IndexError: list index out of range
[root@rh70-node1 ~]# echo $?
1
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and
Error: Unable to update cib
Call cib_replace failed (-203): Update does not conform to the configured schema
<cib admin_epoch="0" cib-last-written="Wed Sep 10 16:41:52 2014" crm_feature_set="3.0.7" epoch="6504" have-quorum="1" num_updates="1" update-client="cibadmin" update-origin="rh70-node1" validate-with="pacemaker-1.2" dc-uuid="1">
{output trimmed}
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and '#uname' ne
Error: Unable to update cib
Call cib_replace failed (-203): Update does not conform to the configured schema
<cib admin_epoch="0" cib-last-written="Wed Sep 10 16:42:55 2014" crm_feature_set="3.0.7" epoch="6504" have-quorum="1" num_updates="1" update-client="cibadmin" update-origin="rh70-node1" validate-with="pacemaker-1.2" dc-uuid="1">
{output trimmed}
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and '#uname' ne rh70-node2 or '#uname' ne rh70-node3
[root@rh70-node1 ~]# pcs constraint
Location Constraints:
  Resource: dummy
    Constraint: location-dummy
      Rule: score=INFINITY  
        Expression: #uname ne rh70-node3  
Ordering Constraints:
Colocation Constraints:

After Fix:
[root@rh70-node1 ~]# rpm -q pcs
pcs-0.9.126-1.el7.x86_64
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne
Error: '#uname ne' is not a valid rule expression: unexpected end of rule
[root@rh70-node1 ~]# echo $?
1
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and
Error: '#uname ne rh70-node1 and' is not a valid rule expression: unexpected end of rule
[root@rh70-node1 ~]# echo $?
1
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and '#uname' ne
Error: '#uname ne rh70-node1 and #uname ne' is not a valid rule expression: unexpected end of rule
[root@rh70-node1 ~]# echo $?
1
[root@rh70-node1 ~]# pcs constraint location dummy rule '#uname' ne rh70-node1 and '#uname' ne rh70-node2 or '#uname' ne rh70-node3
[root@rh70-node1 ~]# echo $?
0
[root@rh70-node1 ~]# pcs constraint
Location Constraints:
  Resource: dummy
    Constraint: location-dummy
      Rule: score=INFINITY boolean-op=or
        Rule: score=0 boolean-op=and
          Expression: #uname ne rh70-node1
          Expression: #uname ne rh70-node2
        Expression: #uname ne rh70-node3
Ordering Constraints:
Colocation Constraints:

Comment 9 errata-xmlrpc 2015-03-05 09:19:50 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-0415.html