Bug 1435771

Summary: RHSM1DBusException: com.redhat.RHSM1.Error: UnboundLocalError: local variable 'data' referenced before assignment
Product: Red Hat Enterprise Linux 7 Reporter: John Sefler <jsefler>
Component: subscription-managerAssignee: Chris Snyder <csnyder>
Status: CLOSED ERRATA QA Contact: John Sefler <jsefler>
Severity: low Docs Contact:
Priority: high    
Version: 7.4CC: csnyder, khowell, redakkan, skallesh
Target Milestone: rcKeywords: Regression, Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.19.9-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 19:21:47 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 John Sefler 2017-03-24 17:39:41 UTC
Description of problem:
When there is a malformed custom fact or simply an empty custom facts file, a traceback occurs during registration.

This is a regression from RHEL7.3 where a WARNING like the following was written to rhsm.log

[WARNING]  @facts.py:125 - Unable to load custom facts file: /etc/rhsm/facts/empty.facts



Version-Release number of selected component (if applicable):
[root@jsefler-rhel7 ~]# rpm -q subscription-manager python-rhsm
subscription-manager-1.19.4-1.el7.x86_64
python-rhsm-1.19.2-1.el7.x86_64


How reproducible:


Steps to Reproduce:
[root@jsefler-rhel7 ~]# touch /etc/rhsm/facts/empty.facts
[root@jsefler-rhel7 ~]# subscription-manager register
Registering to: jsefler-candlepin.usersys.redhat.com:8443/candlepin
Username: testuser1
Password: 
com.redhat.RHSM1.Error: Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/dbus/service.py", line 707, in _message_cb
    retval = candidate_method(self, *args, **keywords)
  File "<string>", line 2, in GetFacts
  File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/util.py", line 32, in dbus_handle_exceptions
    ret = func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/facts/base.py", line 79, in GetFacts
    results.update(fact_collector.GetFacts())
  File "<string>", line 2, in GetFacts
  File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/util.py", line 32, in dbus_handle_exceptions
    ret = func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/facts/base.py", line 43, in GetFacts
    collection = self.facts_collector.collect()
  File "/usr/lib/python2.7/site-packages/rhsmlib/facts/collector.py", line 84, in collect
    facts_dict.update(self.get_all())
  File "/usr/lib/python2.7/site-packages/rhsmlib/facts/host_collector.py", line 85, in get_all
    custom_facts_dict = custom_facts.get_all()
  File "/usr/lib/python2.7/site-packages/rhsmlib/facts/custom.py", line 111, in get_all
    for custom_facts in facts_dir:
  File "/usr/lib/python2.7/site-packages/rhsmlib/facts/custom.py", line 85, in __iter__
    yield CustomFacts.from_json(fact_file.read())
  File "/usr/lib/python2.7/site-packages/rhsmlib/facts/custom.py", line 37, in from_json
    custom_facts.data = data
RHSM1DBusException: com.redhat.RHSM1.Error: UnboundLocalError: local variable 'data' referenced before assignment


Actual results:
 above

Expected results:
 expected a successful register with the following rhsm.log entry
 [WARNING]  @facts.py:125 - Unable to load custom facts file: /etc/rhsm/facts/empty.facts



Additional info:

The same traceback is thrown when a custom facts file has malformed json, like this...
[root@jsefler-rhel7 ~]# cat /etc/rhsm/facts/malformed.facts
{"malformed_fact":"value" is "misquoted"}

Comment 3 Chris Snyder 2017-04-06 19:51:52 UTC
I have a fix for the exception.

I am currently investigating whether logging in the dbus service works at all. As far as I can tell there is no reason (with my fix) the desired log message should not be written to /etc/rhsm/rhsm.log but yet it is not. Furthermore, I've not seen any log messages coming from the dbus service.

I will continue investigation.

Comment 4 Chris Snyder 2017-04-06 20:45:34 UTC
I have employed the same logic as is done in rhsmd, applied to the dbus services.
The PR with the both fixes necessary for this bug has been attached as an external tracker to this bug.

Comment 7 John Sefler 2017-04-25 18:02:54 UTC
Verifying Version....
[root@jsefler-rhel7 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 0.9.51.21-1
subscription management rules: 5.15.1
subscription-manager: 1.19.9-1.el7
python-rhsm: 1.19.5-1.el7

[root@jsefler-rhel7 ~]# touch /etc/rhsm/facts/empty.facts
[root@jsefler-rhel7 ~]# subscription-manager register
Registering to: subscription.rhsm.stage.redhat.com:443/subscription
Username: stage_auto_testuser1
Password: 
The system has been registered with ID: 441553d0-674f-4033-8145-6ac313626341 

[root@jsefler-rhel7 ~]# tail -f /var/log/rhsm/rhsm.log
2017-04-25 13:58:41,757 [INFO] subscription-manager:22077:MainThread @custom.py:85 - Loading custom facts from: /etc/rhsm/facts/empty.facts
2017-04-25 13:58:41,758 [WARNING] subscription-manager:22077:MainThread @custom.py:40 - Unable to load custom facts file.
2017-04-25 13:58:41,801 [INFO] subscription-manager:22077:MainThread @custom.py:85 - Loading custom facts from: /etc/rhsm/facts/empty.facts
2017-04-25 13:58:41,801 [WARNING] subscription-manager:22077:MainThread @custom.py:40 - Unable to load custom facts file.

Comment 8 errata-xmlrpc 2017-08-01 19:21:47 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/RHBA-2017:2083