Bug 1734361

Summary: Provide a hint about the "set" option for cmds containing multiple "then" keywords in their constraint definitions
Product: Red Hat Enterprise Linux 8 Reporter: Tomas Jelinek <tojeline>
Component: pcsAssignee: Tomas Jelinek <tojeline>
Status: CLOSED ERRATA QA Contact: cluster-qe <cluster-qe>
Severity: low Docs Contact:
Priority: medium    
Version: 8.0CC: cfeist, cluster-maint, cluster-qe, cmarthal, idevat, mlisik, mmazoure, nhostako, omular, tojeline
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcs-0.10.3-2.el8 Doc Type: Bug Fix
Doc Text:
Cause: The user specifies multiple resources in the 'pcs constraint colocation add' or 'pcs constraint order' commands. Consequence: A constraint for the first two resources is created, the other resources are silently ignored, no error is reported. Fix: Improve command line parsing and validation in the commands. Result: The user is informed that exactly two resources may be specified in the commands. They are advised to use set constraints instead to set constraints for multiple resources.
Story Points: ---
Clone Of: 1500012 Environment:
Last Closed: 2020-04-28 15:27:56 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:
Attachments:
Description Flags
proposed fix + tests none

Description Tomas Jelinek 2019-07-30 11:00:56 UTC
+++ This bug was initially created as a clone of Bug #1500012 +++

Description of problem:
After further manual reading, I learned when defining order constraints for multiple resources at once, you need to use the "set" command. However, until I learned that, pcs was fine letting me think I had done everything correctly with multiple "then"'s in my cmd.

 
[root@host-081 ~]# pcs resource show
 Clone Set: dlm_for_lvmlockd-clone [dlm_for_lvmlockd]
     Started: [ host-081 host-094 host-095 ]
 Clone Set: lvmlockd-clone [lvmlockd]
     Started: [ host-081 host-094 host-095 ]
 Clone Set: QA-lvmlockd-activation-clone [QA-lvmlockd-activation]
     Started: [ host-081 host-094 host-095 ]

[root@host-081 ~]# pcs constraint order start dlm_for_lvmlockd-clone then start lvmlockd-clone then start QA-lvmlockd-activation-clone Serialize
Adding dlm_for_lvmlockd-clone lvmlockd-clone (kind: Mandatory) (Options: first-action=start then-action=start)

[root@host-081 ~]# pcs constraint show --full
Location Constraints:
Ordering Constraints:
  start dlm_for_lvmlockd-clone then start lvmlockd-clone (kind:Mandatory) (id:order-dlm_for_lvmlockd-clone-lvmlockd-clone-mandatory)
Colocation Constraints:
Ticket Constraints:

[root@host-081 ~]# pcs constraint  remove order-dlm_for_lvmlockd-clone-lvmlockd-clone-mandatory
[root@host-081 ~]# pcs constraint show --full
Location Constraints:
Ordering Constraints:
Colocation Constraints:
Ticket Constraints:

# This cmd resulted in the exact same thing as above since the final "then" is just getting dropped
[root@host-081 ~]# pcs constraint order start dlm_for_lvmlockd-clone then start lvmlockd-clone Serialize
Adding dlm_for_lvmlockd-clone lvmlockd-clone (kind: Mandatory) (Options: first-action=start then-action=start)
[root@host-081 ~]# pcs constraint show --full
Location Constraints:
Ordering Constraints:
  start dlm_for_lvmlockd-clone then start lvmlockd-clone (kind:Mandatory) (id:order-dlm_for_lvmlockd-clone-lvmlockd-clone-mandatory)
Colocation Constraints:
Ticket Constraints:

[root@host-081 ~]# pcs constraint  remove order-dlm_for_lvmlockd-clone-lvmlockd-clone-mandatory

# This should fail:
[root@host-081 ~]# pcs constraint order start dlm_for_lvmlockd-clone then start nonexistentresource-clone Serialize
Error: Resource 'nonexistentresource-clone' does not exist

# As should this I would think:
[root@host-081 ~]# pcs constraint order start dlm_for_lvmlockd-clone then start lvmlockd-clone then start nonexistentresource-clone Serialize
Adding dlm_for_lvmlockd-clone lvmlockd-clone (kind: Mandatory) (Options: first-action=start then-action=start)
[root@host-081 ~]# echo $?
0


# After further reading, I found that the "set" option is what I was looking for.
order set <resource1> [resourceN]

[root@host-081 ~]# pcs constraint order set dlm_for_lvmlockd-clone lvmlockd-clone nonexistentresource-clone
Error: resource 'nonexistentresource-clone' does not exist

[root@host-081 ~]# pcs constraint order set dlm_for_lvmlockd-clone lvmlockd-clone QA-lvmlockd-activation-clone sequential=true
[root@host-081 ~]# pcs constraint show --full
Location Constraints:
Ordering Constraints:
  Resource Sets:
    set dlm_for_lvmlockd-clone lvmlockd-clone QA-lvmlockd-activation-clone sequential=true (id:pcs_rsc_set_dlm_for_lvmlockd-clone_lvmlockd-clone_QA-lvmlockd-activation-clone) (id:pcs_rsc_order_set_dlm_for_lvmlockd-clone_lvmlockd-clone_QA-lvmlockd-activation-clone)
Colocation Constraints:
Ticket Constraints:


Version-Release number of selected component (if applicable):
pcs-0.9.158-6.el7.x86_64

--- Additional comment from Tomas Jelinek on 2017-10-10 09:37:35 CEST ---

Order constraints cmdline parsing needs to be fixed to only accept a pair of resources. If more than two resources are specified, pcs should exit with an error. The error should, apart from telling the syntax is not valid, hint that a set constraint may be used instead.

The same should be done for colocation constraints.

Comment 1 Tomas Jelinek 2019-08-01 09:37:26 UTC
Created attachment 1596893 [details]
proposed fix + tests

In order to fix the reported issue properly a few more fixes had to be implemented:
* 'pcs constraint colocation add': report an error when multiple "with"s are specified, provide a hint that 'pcs constraint colocation set' should be used instead
* 'pcs constraint colocation add': report an error when specified resource roles are not valid
* 'pcs constraint colocation add': missing 'name' or '=value' in name=value options is reported as an error
* 'pcs constraint order': report an error when multiple "then"s are used, provide a hint that 'pcs constraint order set' should be used instead
* 'pcs constraint order': missing 'name' or '=value' in name=value options is reported as an error

Comment 3 Miroslav Lisik 2019-10-23 15:46:23 UTC
After fix:

[root@r81-node-01 ~]# rpm -q pcs
pcs-0.10.3-1.el8.x86_64

[root@r81-node-01 pcs]# pcs resource
 d-01   (ocf::pacemaker:Dummy): Started r81-node-01
 d-02   (ocf::pacemaker:Dummy): Started r81-node-02
 d-03   (ocf::pacemaker:Dummy): Started r81-node-01

### order

[root@r81-node-01 pcs]# pcs constraint order d-01 then d-02 then d-03

Usage: pcs constraint [constraints]...
    order [show] [--full]
        List all current ordering constraints (if --full is specified show
        the internal constraint id's as well).

    order [action] <resource id> then [action] <resource id> [options]
        Add an ordering constraint specifying actions (start, stop, promote,
        demote) and if no action is specified the default action will be
        start.
        Available options are kind=Optional/Mandatory/Serialize,
        symmetrical=true/false, require-all=true/false and id=<constraint-id>.

    order set <resource1> [resourceN]... [options] [set
              <resourceX> ... [options]]
              [setoptions [constraint_options]]
        Create an ordered set of resources.
        Available options are sequential=true/false, require-all=true/false and
        action=start/promote/demote/stop. Available constraint_options are
        id=<constraint-id>, kind=Optional/Mandatory/Serialize and
        symmetrical=true/false.

    order delete <resource1> [resourceN]...
        Remove resource from any ordering constraint

    order remove <resource1> [resourceN]...
        Remove resource from any ordering constraint

Error: Multiple 'then's cannot be specified.
Hint: Use the 'pcs constraint order set' command if you want to create a constraint for more than two resources.
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint order d-01 then d-02 true
Error: missing value of 'true' option
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint order d-01 then d-02 =true
Error: missing key in '=true' option
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint order d-01 then d-02 symetrical
Error: missing value of 'symetrical' option
[root@r81-node-01 pcs]# echo $?
1

### colocation

[root@r81-node-01 pcs]# pcs constraint colocation add d-01 with d-02 with d-03

Usage: pcs constraint [constraints]...
    colocation add [master|slave] <source resource id> with [master|slave]
                   <target resource id> [score] [options] [id=constraint-id]
        Request <source resource> to run on the same node where pacemaker has
        determined <target resource> should run.  Positive values of score
        mean the resources should be run on the same node, negative values
        mean the resources should not be run on the same node.  Specifying
        'INFINITY' (or '-INFINITY') for the score forces <source resource> to
        run (or not run) with <target resource> (score defaults to "INFINITY").
        A role can be master or slave (if no role is specified, it defaults to
        'started').

Error: Multiple 'with's cannot be specified.
Hint: Use the 'pcs constraint colocation set' command if you want to create a constraint for more than two resources.
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint colocation add d-01 with d-02 value
Error: invalid role value 'd-02', allowed values are: 'Master', 'Slave', 'Started', 'Stopped'
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint colocation add d-01 with d-02 =value
Error: missing key in '=value' option
[root@r81-node-01 pcs]# echo $?
1
[root@r81-node-01 pcs]# pcs constraint colocation add d-01 with d-02 name=value something
Error: missing value of 'something' option
[root@r81-node-01 pcs]# echo $?
1

[root@r81-node-01 pcs]# pcs constraint
Location Constraints:
Ordering Constraints:
Colocation Constraints:
Ticket Constraints:

Comment 6 Miroslav Lisik 2019-11-19 11:03:49 UTC
Test:

[root@r81-node-01 ~]# rpm -q pcs
pcs-0.10.3-2.el8.x86_64

[root@r81-node-01 ~]# pcs resource
  * dummy-01	(ocf::pacemaker:Dummy):	 Started r81-node-01
  * dummy-02	(ocf::pacemaker:Dummy):	 Started r81-node-02

[root@r81-node-01 ~]# pcs constraint order dummy-01 then dummy-02 symetrical=
Error: value of 'symetrical' option is empty
[root@r81-node-01 ~]# echo $?
1

[root@r81-node-01 ~]# pcs constraint colocation add dummy-01 with dummy-02 name=
Error: value of 'name' option is empty
[root@r81-node-01 ~]# echo $?
1

Comment 10 errata-xmlrpc 2020-04-28 15:27:56 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://access.redhat.com/errata/RHEA-2020:1568