Bug 1827711

Summary: /etc/cron.daily/rhsmd fails to recognize rhsmd.processtimeout configuration
Product: Red Hat Enterprise Linux 7 Reporter: Rehana <redakkan>
Component: subscription-managerAssignee: candlepin-bugs
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: high Docs Contact:
Priority: high    
Version: 7.9CC: candlepin-bugs, jsefler, rhsm-qe, wpoteat
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: 7.9   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.24.35-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1827708
: 1828186 (view as bug list) Environment:
Last Closed: 2020-09-29 19:23:08 UTC Type: ---
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: 1827708    
Bug Blocks: 1828186    

Description Rehana 2020-04-24 15:29:36 UTC
+++ This bug was initially created as a clone of Bug #1827708 +++

Description of problem:
In the scenario that a customer upgrades subscription-manager from an older version, it is possible that the /etc/rhsm/rhsm.conf configuration file will be be carried forward from their old installation and be absent of the new [rhsmd] processTimeout configuration introduced by bug 1643189.   When this happens, a user may choose to change the default value [300 seconds] of this config by calling...

subscription-manager config --rhsmd.processtimeout=200

which will introduce a new configuration in /etc/rhsm/rhsm.conf all in lowercase characters.  The problem is that the script /etc/cron.daily/rhsmd has an error that will not recognize the lowercase character configuration.  The fix is to  add an "--ignore-case" option to the first line of code in /etc/cron.daily/rhsmd
Change this line of code...

> config=$(grep -E "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")

to this...

> config=$(grep -iE "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")


Version-Release number of selected component (if applicable):
[root@kvm-01-guest06 ~]# rpm -q --whatprovides /etc/cron.daily/rhsmd 
subscription-manager-1.26.16-1.el8.x86_64


How reproducible:


Steps to Reproduce:
Make sure that /etc/rhsm/rhsm.conf is absent of the processTimeout configuration....
[root@kvm-01-guest06 ~]# grep --ignore-case "processTimeout" /etc/rhsm/rhsm.conf
[root@kvm-01-guest06 ~]# 

Then here is the test that shows /etc/rhsm/rhsm.conf fails to read a properly configured rhsmd.processtimeout...
[root@kvm-01-guest06 ~]# subscription-manager config | grep --ignore-case "processTimeout"
   processtimeout = [300]
[root@kvm-01-guest06 ~]# 
[root@kvm-01-guest06 ~]# subscription-manager config --rhsmd.processtimeout=120
[root@kvm-01-guest06 ~]# 
[root@kvm-01-guest06 ~]# subscription-manager config | grep --ignore-case "processTimeout"
   processtimeout = 120
[root@kvm-01-guest06 ~]# 
[root@kvm-01-guest06 ~]# time /etc/cron.daily/rhsmd

real	5m0.065s
user	0m0.455s
sys	0m0.126s



Actual results:
 the /etc/cron.daily/rhsmd took 5minutes (equivaluent to the 300sec default) to timeout

Expected results:
 the /etc/cron.daily/rhsmd should have taken 2minutes (equivaluent to the configured 120sec) to timeout


Additional info:

Here is the current implementation of /etc/cron.daily/rhsmd

[root@kvm-01-guest06 ~]# cat /etc/cron.daily/rhsmd
#!/bin/sh
# nightly run of rhsmd to log entitlement expiration/validity errors to syslog
# this is a cron job because it doesn't need to 'phone home'. should that
# change, look into calling the dbus interface from rhsmcertd instead.
config=$(grep -E "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")
if [ -n "$config" ]; then
  rhsmd_timeout=$config
else
  rhsmd_timeout=300
fi

/usr/libexec/rhsmd -s &
sleep $rhsmd_timeout;

ps_check=$(pgrep -f '/usr/libexec/rhsmd')
if [ -n "$ps_check" ]; then
  pkill -f '/usr/libexec/rhsmd' >/dev/null 2>&1
  logger -t rhsmd -p user.warn "rhsmd process exceeded runtime and was killed." >/dev/null 2>&1
fi
[root@kvm-01-guest06 ~]#

Comment 6 John Sefler 2020-05-15 03:02:37 UTC
Verifying Version...

[root@ibm-x3650m4-01-vm-06 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 Beta (Maipo)
[root@ibm-x3650m4-01-vm-06 ~]# rpm -q subscription-manager
subscription-manager-1.24.37-1.el7.x86_64
[root@ibm-x3650m4-01-vm-06 ~]# rpm -q --changelog subscription-manager | grep 1827711
- 1827711: Make rhsmd cron read 'processTimeout' case-insensitive
[root@ibm-x3650m4-01-vm-06 ~]# 

To demonstrate that this bug is fixed (as originally reported in Bug 1827708 on a RHEL-8.2 machine), we will show that as a result of an upgrade to RHEL-7.9 (steps not shown) the /etc/rhsm/rhsm.conf file may be absent of a "processTimeout" configuration.  Despite its absence, we can use subscription-manager config tool to change the value of the default "processtimeout" value (from 300 seconds) to a different value and it will be honored.

[root@ibm-x3650m4-01-vm-06 ~]# grep --ignore-case "processTimeout" /etc/rhsm/rhsm.conf
[root@ibm-x3650m4-01-vm-06 ~]# 
[root@ibm-x3650m4-01-vm-06 ~]# subscription-manager config | grep --ignore-case "processTimeout"
   processtimeout = [300]
[root@ibm-x3650m4-01-vm-06 ~]# 
[root@ibm-x3650m4-01-vm-06 ~]# subscription-manager config --rhsmd.processtimeout=120
[root@ibm-x3650m4-01-vm-06 ~]# 
[root@ibm-x3650m4-01-vm-06 ~]# subscription-manager config | grep --ignore-case "processTimeout"
   processtimeout = 120
[root@ibm-x3650m4-01-vm-06 ~]# 
[root@ibm-x3650m4-01-vm-06 ~]# grep --ignore-case "processTimeout" /etc/rhsm/rhsm.conf
processtimeout = 120
[root@ibm-x3650m4-01-vm-06 ~]# 
[root@ibm-x3650m4-01-vm-06 ~]# time /etc/cron.daily/rhsmd

real	2m0.053s    <==== VERIFIED: The process exited after a 120 second timeout as newly configured
user	0m0.286s
sys	0m0.140s
[root@ibm-x3650m4-01-vm-06 ~]# 

VERIFIED: We invoked "subscription-manager config --rhsmd.processtimeout=120" on an upgraded RHEL7 system to change the default "processtimeout" which was honored by the /etc/cron.daily/rhsmd job.


Note: The fix for this bug was a simple code change in /etc/cron.daily/rhsmd to introduce an "--ignore-case" option to the first line of code in /etc/cron.daily/rhsmd.  Let's look at that line of code on this rhel7.9 system....

[root@ibm-x3650m4-01-vm-06 ~]# head -n5 /etc/cron.daily/rhsmd
#!/bin/sh
# nightly run of rhsmd to log entitlement expiration/validity errors to syslog
# this is a cron job because it doesn't need to 'phone home'. should that
# change, look into calling the dbus interface from rhsmcertd instead.
config=$(grep -iE "^processTimeout" /etc/rhsm/rhsm.conf | grep -Po "[0-9]+")
               ^
               ^
               That is the one character fix for "--ignore-case".

Comment 8 errata-xmlrpc 2020-09-29 19:23:08 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 (subscription-manager bug fix 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-2020:3866