Bug 966747 - empty and malformed custom facts makes subscription-manager unusable because "No JSON object could be decoded"
empty and malformed custom facts makes subscription-manager unusable because ...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: subscription-manager (Show other bugs)
5.10
Unspecified Unspecified
unspecified Severity medium
: rc
: ---
Assigned To: Adrian Likins
IDM QE LIST
:
Depends On:
Blocks: rhsm-rhel510
  Show dependency treegraph
 
Reported: 2013-05-23 16:39 EDT by John Sefler
Modified: 2013-09-30 19:10 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
No description necessary
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-09-30 19:10:08 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description John Sefler 2013-05-23 16:39:35 EDT
Description of problem:
A side affect of bug 966745 was the creation of an empty migration.facts file...
[root@rhsm-compat-rhel59 ~]# ls -l /etc/rhsm/facts/
total 4
-rw-r--r-- 1 root root 0 May 23 07:23 migration.facts

When there is an empty facts file, subscription-manager cannot register...

[root@rhsm-compat-rhel59 ~]# subscription-manager register
Username: testuser1
Password: 
No JSON object could be decoded


[root@rhsm-compat-rhel59 ~]# tail -20 /var/log/rhsm/rhsm.log
2013-05-23 16:30:13,142 [INFO]  @managercli.py:308 - Client Versions: {'python-rhsm': '1.8.11-1.git.1.7236cc2.el5', 'subscription-manager': '1.8.8-1.git.8.7625592.el5'} 
2013-05-23 16:30:18,651 [INFO]  @connection.py:575 - Using basic authentication as: testuser1
2013-05-23 16:30:18,652 [INFO]  @connection.py:596 - Connection Built: host: candlepin-compat-rhel59.usersys.redhat.com, port: 8443, handler: /candlepin
2013-05-23 16:30:18,721 [ERROR]  @managercli.py:150 - Error during registration: No JSON object could be decoded
2013-05-23 16:30:18,721 [ERROR]  @managercli.py:151 - No JSON object could be decoded
Traceback (most recent call last):
  File "/usr/share/rhsm/subscription_manager/managercli.py", line 1037, in _do_command
    facts_dic = self.facts.get_facts()
  File "/usr/share/rhsm/subscription_manager/facts.py", line 106, in get_facts
    facts.update(self._load_custom_facts())
  File "/usr/share/rhsm/subscription_manager/facts.py", line 128, in _load_custom_facts
    file_facts.update(json.loads(json_buffer))
  File "/usr/lib64/python2.4/site-packages/simplejson/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.4/site-packages/simplejson/decoder.py", line 335, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.4/site-packages/simplejson/decoder.py", line 353, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
2013-05-23 16:30:59,671 [ERROR]  @rhsmcertd-worker:40 - Either the consumer is not registered or the certificates are corrupted. Certificate update using daemon failed.
[root@rhsm-compat-rhel59 ~]# 


Version-Release number of selected component (if applicable):
[root@rhsm-compat-rhel59 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 0.8.7-1
subscription-manager: 1.8.8-1.git.8.7625592.el5
python-rhsm: 1.8.11-1.git.1.7236cc2.el5
Comment 1 John Sefler 2013-05-23 16:46:46 EDT
... and when custom facts are truely malformed by accident, we fail with the same message:

[root@rhsm-compat-rhel59 ~]# cat /etc/rhsm/facts/malformed.facts 
{ "mycustomfacts":"true", "are_malformed":burp}

[root@rhsm-compat-rhel59 ~]# subscription-manager register
Username: testuser1
Password: 
No JSON object could be decoded


It would be better to inform the user why/where "No JSON object could be decoded".  Something like this....

[root@rhsm-compat-rhel59 ~]# subscription-manager register
Username: testuser1
Password: 
Error: Custom facts file "/etc/rhsm/facts/malformed.facts" is not in the proper JSON format.  It must be corrected or deleted.
Comment 2 RHEL Product and Program Management 2013-05-23 16:50:16 EDT
This request was evaluated by Red Hat Product Management for inclusion
in a Red Hat Enterprise Linux release.  Product Management has
requested further review of this request by Red Hat Engineering, for
potential inclusion in a Red Hat Enterprise Linux release for currently
deployed products.  This request is not yet committed for inclusion in
a release.
Comment 3 Adrian Likins 2013-06-04 14:17:43 EDT
https://github.com/candlepin/subscription-manager/pull/628

commit d3be82c492718b9d3e5559e564dc81290e1fcd21
Author: Adrian Likins <alikins@redhat.com>
Date:   Tue Jun 4 13:02:42 2013 -0400

    966747: handle a custom facts file being empty
    
    json.loads("") throws a ValueError, so handle that
    case
    
    Add log.info about which custom facts we are loading.
    
    Split up custom cache loading into a few methods, so
    we can test them easier, and add corresponding tests.
    
    Add lots more tests to test_facts.py, and fix up some
    of the issue found.
    
    Handle facts cache file not existing, being empty, or
    otherwise failing to load so Facts.has_changed does
    the right thing.
Comment 4 Adrian Likins 2013-06-04 15:55:31 EDT
merged in master with:

commit d3be82c492718b9d3e5559e564dc81290e1fcd21
Author: Adrian Likins <alikins@redhat.com>
Date:   Tue Jun 4 13:02:42 2013 -0400

should be in 1.8.11
Comment 6 John Sefler 2013-06-07 13:42:04 EDT
Testing Version...
[root@jsefler-5 ~]# rpm -q subscription-manager
subscription-manager-1.8.10-1.git.15.4bb4042.el5

The fixed behavior appears to log a warning to rhsm.log for the malformed custom facts and proceeds with the subscription-manager task at hand.

2013-06-07 13:31:08,916 [WARNING]  @facts.py:125 - Unable to load custom facts file: /etc/rhsm/facts/malformed.facts
Comment 7 John Sefler 2013-07-01 15:00:49 EDT
Verifying Version...
[root@jsefler-5 ~]# rpm -q subscription-manager
subscription-manager-1.8.11-1.el5



Testing empty facts file case...
[root@jsefler-5 ~]# touch /etc/rhsm/facts/empty.facts
[root@jsefler-5 ~]# ls -l /etc/rhsm/facts/
total 4
-rw-r--r-- 1 root root 0 Jul  1 14:44 empty.facts
[root@jsefler-5 ~]# subscription-manager register
Username: testuser1
Password: 
Organization: admin
The system has been registered with ID: c2137292-02ef-40ed-8fc9-a8ce390733d3 
[root@jsefler-5 ~]# 

VERIFIED



Testing malformaed facts file case...
[root@jsefler-5 ~]# subscription-manager unregister
System has been unregistered.
[root@jsefler-5 ~]# echo '{"mycustomfacts":"true", "are_malformed":burp}' > /etc/rhsm/facts/malformed.facts
[root@jsefler-5 ~]# ls -l /etc/rhsm/facts/
total 12
-rw-r--r-- 1 root root  0 Jul  1 14:44 empty.facts
-rw-r--r-- 1 root root 47 Jul  1 14:47 malformed.facts
[root@jsefler-5 ~]# subscription-manager register
Username: testuser1
Password: 
Organization: admin
The system has been registered with ID: ff865f17-bddd-4a34-988a-c940911c1a93 
[root@jsefler-5 ~]# 

VERIFIED



Additional Info...

[root@jsefler-5 ~]# subscription-manager facts --update
Successfully updated the system facts.
[root@jsefler-5 ~]# tail -100 /var/log/rhsm/rhsm.log | grep WARNING
2013-07-01 14:57:56,903 [WARNING]  @facts.py:111 - Unable to load custom facts file: /etc/rhsm/facts/malformed.facts
2013-07-01 14:57:56,903 [WARNING]  @facts.py:111 - Unable to load custom facts file: /etc/rhsm/facts/empty.facts
[root@jsefler-5 ~]#
Comment 9 errata-xmlrpc 2013-09-30 19:10:08 EDT
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.

http://rhn.redhat.com/errata/RHBA-2013-1332.html

Note You need to log in before you can comment on or make changes to this bug.