Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1821747

Summary: Any subscription-manager command is terminated, when /etc/rhsm/syspurpose directory does not exist
Product: Red Hat Enterprise Linux 8 Reporter: Jiri Hnidek <jhnidek>
Component: subscription-managerAssignee: Jiri Hnidek <jhnidek>
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.1CC: jsefler, redakkan, skallesh, wpoteat
Target Milestone: rcKeywords: Triaged
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 01:39:09 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 Jiri Hnidek 2020-04-07 14:02:39 UTC
Description of problem:
When directory /etc/rhsm/syspurpose is missing, then any subscription-manager command is terminated.

Version-Release number of selected component (if applicable):
[root@localhost ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 2.9.21-1
subscription management rules: 5.37
subscription-manager: 1.26.12-1.el8

How reproducible:
100%

Steps to Reproduce:
1. Delete directory /etc/rhsm/syspurpose
[root@localhost ~]# rm -rf /etc/rhsm/syspurpose/

2. Try to run any subscription-manager command
[root@localhost ~]# subscription-manager version

Actual results:
[Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'

Expected results:
Directory /etc/rhsm/syspurpose/ is created and /etc/rhsm/syspurpose/syspurpose.json with content: '{}' is also created.

Additional info:
Content of rhsm.log

2020-04-07 15:51:12,033 [ERROR] subscription_manager.py:4807:MainThread @managercli.py:216 - exception caught in subscription-manager
2020-04-07 15:51:12,033 [ERROR] subscription_manager.py:4807:MainThread @managercli.py:217 - [Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'
Traceback (most recent call last):
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/scripts/subscription_manager.py", line 96, in <module>
    sys.exit(abs(main() or 0))
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/scripts/subscription_manager.py", line 87, in main
    return managercli.ManagerCLI().main()
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/managercli.py", line 3068, in __init__
    CLI.__init__(self, command_classes=commands)
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/cli.py", line 101, in __init__
    cmd = clazz()
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/managercli.py", line 1636, in __init__
    attr='addons', commands=['unset', 'add', 'remove'])
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/managercli.py", line 573, in __init__
    self.store = self._get_synced_store()
  File "/home/jiri/github/candlepin/subscription_manager/src/subscription_manager/managercli.py", line 609, in _get_synced_store
    return SyncedStore(uep=uep, consumer_uuid=self.identity.uuid)
  File "/home/jiri/github/candlepin/subscription_manager/syspurpose/src/syspurpose/files.py", line 252, in __init__
    self.local_contents = self.get_local_contents()
  File "/home/jiri/github/candlepin/subscription_manager/syspurpose/src/syspurpose/files.py", line 335, in get_local_contents
    self.update_local({})
  File "/home/jiri/github/candlepin/subscription_manager/syspurpose/src/syspurpose/files.py", line 372, in update_local
    return self.update_file(self.path, data)
  File "/home/jiri/github/candlepin/subscription_manager/syspurpose/src/syspurpose/files.py", line 505, in update_file
    f = io.open(path, mode, encoding='utf-8')
IOError: [Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'


It also worth to mention that syspurpose command has similar problem and creating /etc/rhsm/syspurpose fixes this issue:

[root@localhost ~]# syspurpose show
[Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'

[root@localhost ~]# mkdir /etc/rhsm/syspurpose/

[root@localhost ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 2.9.21-1
subscription management rules: 5.37
subscription-manager: 1.26.12-1.el8
[root@localhost subscription_manager]# syspurpose show
{}

Comment 1 Jiri Hnidek 2020-04-09 09:16:15 UTC
When directory /var/lib/rhsm/cache does not exist, then subscription-manager is terminated with similar error. It should be fixed in the provided PR.

Comment 4 Shwetha Kallesh 2020-05-18 11:26:04 UTC
reproducer:

[root@kvm-02-guest16 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 2.9.27-1
subscription management rules: 5.37
subscription-manager: 1.26.12-1.el8
[root@kvm-02-guest16 ~]# rm -rf /etc/rhsm/syspurpose/
[root@kvm-02-guest16 ~]# subscription-manager version
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/syspurpose/files.py", line 325, in get_local_contents
    self.local_contents = json.load(io.open(self.path, 'r', encoding='utf-8'))
FileNotFoundError: [Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/sbin/subscription-manager", line 11, in <module>
    load_entry_point('subscription-manager==1.26.12', 'console_scripts', 'subscription-manager')()
  File "/usr/lib64/python3.6/site-packages/subscription_manager/scripts/subscription_manager.py", line 86, in main
    return managercli.ManagerCLI().main()
  File "/usr/lib64/python3.6/site-packages/subscription_manager/managercli.py", line 2992, in __init__
    CLI.__init__(self, command_classes=commands)
  File "/usr/lib64/python3.6/site-packages/subscription_manager/cli.py", line 101, in __init__
    cmd = clazz()
  File "/usr/lib64/python3.6/site-packages/subscription_manager/managercli.py", line 1571, in __init__
    attr='addons', commands=['unset', 'add', 'remove'])
  File "/usr/lib64/python3.6/site-packages/subscription_manager/managercli.py", line 565, in __init__
    self.store = self._get_synced_store()
  File "/usr/lib64/python3.6/site-packages/subscription_manager/managercli.py", line 601, in _get_synced_store
    return SyncedStore(uep=uep, consumer_uuid=self.identity.uuid)
  File "/usr/lib/python3.6/site-packages/syspurpose/files.py", line 252, in __init__
    self.local_contents = self.get_local_contents()
  File "/usr/lib/python3.6/site-packages/syspurpose/files.py", line 335, in get_local_contents
    self.update_local({})
  File "/usr/lib/python3.6/site-packages/syspurpose/files.py", line 372, in update_local
    return self.update_file(self.path, data)
  File "/usr/lib/python3.6/site-packages/syspurpose/files.py", line 505, in update_file
    f = io.open(path, mode, encoding='utf-8')
FileNotFoundError: [Errno 2] No such file or directory: '/etc/rhsm/syspurpose/syspurpose.json'
[root@kvm-02-guest16 ~]#

Comment 5 Shwetha Kallesh 2020-05-18 11:29:18 UTC
Verification:


[root@kvm-06-guest05 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 2.9.27-1
subscription management rules: 5.37
subscription-manager: 1.27.3
[root@kvm-06-guest05 ~]# rm -rf /etc/rhsm/syspurpose/
[root@kvm-06-guest05 ~]# ls /etc/rhsm/syspurpose/syspurpose.json
ls: cannot access '/etc/rhsm/syspurpose/syspurpose.json': No such file or directory
[root@kvm-06-guest05 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 2.9.27-1
subscription management rules: 5.37
subscription-manager: 1.27.3
^^ no traceback , version is displayed properly
[root@kvm-06-guest05 ~]# cat /etc/rhsm/syspurpose/syspurpose.json
{}

[root@kvm-06-guest05 ~]# rm -rf /etc/rhsm/syspurpose/
[root@kvm-06-guest05 ~]# ls /etc/rhsm/syspurpose/syspurpose.json
ls: cannot access '/etc/rhsm/syspurpose/syspurpose.json': No such file or directory
[root@kvm-06-guest05 ~]# subscription-manager clean
All local data removed
^^ no traceback again

[root@kvm-06-guest05 ~]# cat /etc/rhsm/syspurpose/syspurpose.json 
{}[root@kvm-06-guest05 ~]#

Comment 8 errata-xmlrpc 2020-11-04 01:39:09 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 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-2020:4460