Bug 2178707

Summary: Creating location constraint passes with wrong date format
Product: Red Hat Enterprise Linux 8 Reporter: Simon Foucek <sfoucek>
Component: pcsAssignee: Tomas Jelinek <tojeline>
Status: CLOSED ERRATA QA Contact: cluster-qe <cluster-qe>
Severity: low Docs Contact:
Priority: medium    
Version: 8.8CC: cluster-maint, idevat, mlisik, mmazoure, mpospisi, nhostako, omular, slevine, tojeline
Target Milestone: rcKeywords: Triaged
Target Release: 8.9Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcs-0.10.16-1.el8 Doc Type: Bug Fix
Doc Text:
Cause: User enters a location constraint rule with a date in an unexpected format. Consequence: The constraint is stored in cluster configuration and either doesn't work at all or applies at unexpected time. Fix: Validate format of date entered in the rule. Result: The user is informed in case the entered date is not valid.
Story Points: ---
Clone Of:
: 2178714 (view as bug list) Environment:
Last Closed: 2023-11-14 15:22:35 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:

Description Simon Foucek 2023-03-15 15:43:22 UTC
Description of problem:

Pcs does not warn the user that he is entering the wrong data format for the location rule, he can then see the constraint in the cluster and gets no information that it might not work.

Version-Release number of selected component (if applicable):
[root@virt-508 ~]# pcs --version
0.10.14




Steps to Reproduce:
1. pcs constraint location dummy rule score=INFINITY date lt '01-01-2022'


Actual results:
Command passes and I can see location in the cluster

Expected results:

pcs warns the user that they are entering the wrong data format and returns an error code

Comment 2 Tomas Jelinek 2023-03-16 08:34:01 UTC
Upstream patch: https://github.com/ClusterLabs/pcs/commit/72ca3f550c63218f1f132e4c6b9a6d1cb0670d6f

Test:
# pcs constraint location dummy rule date lt '01-01-2022'
Error: 'date lt 01-01-2022' is not a valid rule expression: '01-01-2022' is not an ISO 8601 date

Comment 6 Michal Pospisil 2023-05-29 10:10:09 UTC
DevTestResults:

[root@r08-09-a ~]# rpm -q pcs
pcs-0.10.16-1.el8.x86_64

[root@r08-09-a ~]# pcs constraint location r1 rule date lt '01-01-2022'
Error: 'date lt 01-01-2022' is not a valid rule expression: '01-01-2022' is not an ISO 8601 date

Comment 11 svalasti 2023-06-22 09:09:43 UTC
## BEFORE

[root@virt-545 ~]# rpm -q pcs
pcs-0.10.15-4.el8.x86_64

[root@virt-545 ~]# pcs resource create d1 ocf:heartbeat:Dummy

[root@virt-545 ~]# echo $?
0

[root@virt-545 ~]# pcs resource
  * d1	(ocf::heartbeat:Dummy):	 Started virt-545


A). Entering invalid date format for location rule (not an ISO 8601 date)

[root@virt-545 ~]# pcs constraint location d1 rule date lt 22-06-2023

[root@virt-545 ~]# echo $?
0

[root@virt-545 ~]# pcs constraint location config
Location Constraints:
  Resource: d1
    Constraint: location-d1
      Rule: score=INFINITY
        Expression: date lt 22-06-2023

> In the previous version it was possible to specify a constraint rule with a date whose format was not correct (not an ISO8601 date format). This case did not return an error message and the return code was 0.


## AFTER

[root@virt-129 ~]# rpm -q pcs
pcs-0.10.16-1.el8.x86_64

[root@virt-129 ~]# pcs resource create d1 ocf:heartbeat:Dummy

[root@virt-129 ~]# echo $?
0

[root@virt-129 ~]# pcs resource
  * d1	(ocf::heartbeat:Dummy):	 Started virt-129

A.) Entering invalid date format(dd-mm-yyyy, not an ISO 8601 date)

[root@virt-129 ~]# pcs constraint location d1 rule date lt 22-06-2023
Error: 'date lt 22-06-2023' is not a valid rule expression: '22-06-2023' is not an ISO 8601 date

[root@virt-129 ~]# echo $?
1

[root@virt-129 ~]# pcs constraint location config
Location Constraints:

> OK.

B.) Entering another invalid date format (yyyy/month/dd)

[root@virt-129 ~]# pcs constraint location d1 rule date lt 2023/Jun/22
Error: 'date lt 2023/Jun/22' is not a valid rule expression: '2023/Jun/22' is not an ISO 8601 date

[root@virt-129 ~]# echo $?
1

[root@virt-129 ~]# pcs constraint location config
Location Constraints:

> OK.

C.) Entering US date format (mm/dd/yyyy, not an ISO 8601 date)

[root@virt-129 ~]# pcs constraint location d1 rule date lt 06/22/2023
Error: 'date lt 06/22/2023' is not a valid rule expression: '06/22/2023' is not an ISO 8601 date

[root@virt-129 ~]# echo $?
1

[root@virt-129 ~]# pcs constraint location config
Location Constraints:

> OK.

D.) Entering invalid date format (yyyy-mm/dd)

[root@virt-129 ~]# pcs constraint location d1 rule date lt 2023-06/23

[root@virt-129 ~]# echo $?
0

[root@virt-129 ~]# pcs constraint location config
Location Constraints:

> I am not sure about validity of this edge case. The first part of the date is OK and so it is possible that it is evaluated as a valid ISO 8601 date, but in this case the user is not notified that this date is an invalid date format. Also there is no warning/error message and it returns with 0 return code, however no actie location constraint is displayed. 

[root@virt-129 ~]# pcs constraint location config --all
Location Constraints:
  Resource: d1
    Constraint (expired): location-d1
      Rule (expired): score=INFINITY
        Expression: date lt 2023-06/23

[root@virt-129 ~]# date
Wed Jun 21 14:04:04 CEST 2023

> This location constraint rule is shown as expired even though it should not be expired yet. We have created a new BZ that addresses this issue (https://bugzilla.redhat.com/show_bug.cgi?id=2216492)

E.) Entering invalid date format (yyyy/mm-dd)

[root@virt-129 ~]# pcs constraint location d1 rule lt 2023/06-23
Error: 'lt 2023/06-23' is not a valid rule expression: unexpected 'lt'

[root@virt-129 ~]# echo $?
1

[root@virt-129 ~]# pcs constraint location config
Location Constraints:

> OK.

F.) Entering valid ISO 8601 basic date format

[root@virt-129 ~]# pcs constraint location d1 rule date lt 2023-06-22
[root@virt-129 ~]# echo $?
0
[root@virt-129 ~]# pcs constraint location config
Location Constraints:
  Resource: d1
    Constraint: location-d1
      Rule: score=INFINITY
        Expression: date lt 2023-06-22

> OK.

G.) Entering valid ISO 8601 week date format

[root@virt-129 ~]# pcs constraint location d1 rule date lt 2023-W25-4

[root@virt-129 ~]# echo $?
0

[root@virt-129 ~]# pcs constraint location config
Location Constraints:
  Resource: d1
    Constraint: location-d1
      Rule: score=INFINITY
        Expression: date lt 2023-W25-4

> OK.

H.) Entering valid ISO 8601 date format

[root@virt-129 ~]# pcs constraint location d1 rule date lt 2023-173

[root@virt-129 ~]# echo $?
0

[root@virt-129 ~]# pcs constraint location config
Location Constraints:
  Resource: d1
    Constraint: location-d1
      Rule: score=INFINITY
        Expression: date lt 2023-173

> OK.

I.) Entering more complex valid date expression

[root@virt-129 ~]# pcs constraint location d1 rule date in_range 2023-01-01 to 2023-175

[root@virt-129 ~]# echo $?
0

[root@virt-129 ~]# pcs constraint location config
Location Constraints:
  Resource: d1
    Constraint: location-d1
      Rule: score=INFINITY
        Expression: date in_range 2023-01-01 to 2023-175

> OK.

> Overall, working with dates that are specified in ISO 8601 standard works reliably. However, in my opinion, it would be useful to add an extra check to ensure that only ISO 8601 dates are supported (https://bugzilla.redhat.com/show_bug.cgi?id=2216492). 

> Marking as VERIFIED for pcs-0.10.16-1.el8.x86_64

Comment 15 errata-xmlrpc 2023-11-14 15:22:35 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 (pcs bug fix and enhancement update), 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/RHBA-2023:6903