Bug 2121350

Summary: The force option of registering through dbus python binding is ignored
Product: Red Hat Enterprise Linux 9 Reporter: Rehana <redakkan>
Component: subscription-managerAssignee: Jason Jerome <jajerome>
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: medium Docs Contact:
Priority: medium    
Version: 9.0CC: arpandey, candlepin-bugs, cdonnell, mbocek, redakkan, rhsm-qe, tkuratom, zpetrace
Target Milestone: rcKeywords: Triaged
Target Release: 9.2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.29.32-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2118486 Environment:
Last Closed: 2023-05-09 08:18:42 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:
Bug Depends On: 2118486    
Bug Blocks:    

Description Rehana 2022-08-25 08:32:31 UTC
+++ This bug was initially created as a clone of Bug #2118486 +++

Description of problem:
The dbus object com.redhat.RHSM1 documented at https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6 mentions that we can set the force option when registering the system that should be the equivalent of the --force cli option.

This option is not respected when passing the force option through the RHSM dbus python binding.

Version-Release number of selected component (if applicable):


Steps to Reproduce:
1. Have a RHEL 8 system registered to RHSM
2. Run this piece of python code
```
import dbus

REGISTER_OPTS_DICT = dbus.Dictionary({"force": True}, signature="ss")

system_bus = dbus.SystemBus()
register_server = system_bus.get_object("com.redhat.RHSM1", "/com/redhat/RHSM1/RegisterServer")
address = register_server.Start("C", dbus_interface="com.redhat.RHSM1.RegisterServer")
private_bus = dbus.connection.Connection(address)
register_object = private_bus.get_object("com.redhat.RHSM1", "/com/redhat/RHSM1/Register")
connection_opts = {"host": "subscription.rhsm.redhat.com"}
connection_opts = dbus.Dictionary(connection_opts, signature="ss")
register_object.Register(
    "",
    "username",
    "password",
    REGISTER_OPTS_DICT,
    connection_opts,
    "C",
    dbus_interface="com.redhat.RHSM1.Register",
)
```

Actual results:
You're greeted with the following exception:

com.redhat.RHSM1.Error: {"exception": "DBusException", "message": "This system is already registered", "severity": "error"}

Expected results:
The system is re-registered without an exception.

--- Additional comment from Pino Toscano on 2022-08-16 13:00:23 UTC ---

Yes, it appears it is not actually implemented, only checked as part of the parameters in case a system is registered.

Comment 1 Archana Pandey 2022-11-21 12:59:14 UTC
Pre-verification:

Preverifying against jenkins build of sub-man having fix for issue-

>> reproducing the issue-

[root@koza-1 ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 4.2.10-1
subscription management rules: 5.43
subscription-manager: 1.29.31-1.el9
[root@koza-1 ~]# 
[root@koza-1 ~]# 
[root@koza-1 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.

System Purpose Status: Disabled            

[root@koza-1 ~]# 
[root@koza-1 ~]# 
[root@koza-1 ~]# python test.py   <<<<<<,, running the script with dbus python binding
Traceback (most recent call last):
  File "/root/test.py", line 13, in <module>
    register_object.Register(
  File "/usr/lib64/python3.9/site-packages/dbus/proxies.py", line 72, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib64/python3.9/site-packages/dbus/proxies.py", line 141, in __call__
    return self._connection.call_blocking(self._named_service,
  File "/usr/lib64/python3.9/site-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: com.redhat.RHSM1.Error: {"exception": "DBusException", "severity": "error", "message": "This system is already registered"}  << issue reproduced, force registration failed
[root@koza-1 ~]# 
[root@koza-1 ~]# 
[root@koza-1 ~]# 

>> lets upgrade the sub-man client to jenkins build and run the script again-

[root@koza-1 ~]# yum upgrade subscription-manager
Updating Subscription Management repositories.
Red Hat Enterprise Linux 9 for x86_64 - AppStream Beta (RPMs)                                                                                                 1.9 kB/s | 512  B     00:00    
Red Hat Enterprise Linux 9 for x86_64 - BaseOS Beta (RPMs)                                                                                                    2.0 kB/s | 512  B     00:00    
Dependencies resolved.
==============================================================================================================================================================================================
 Package                                                  Architecture                 Version                                                       Repository                          Size
==============================================================================================================================================================================================
Upgrading:
 libdnf-plugin-subscription-manager                       x86_64                       1.29.31+37.gd575edc81-1.git.0.80915ad                         rhsm_RHEL9.2                        82 k
 python3-cloud-what                                       x86_64                       1.29.31+37.gd575edc81-1.git.0.80915ad                         rhsm_RHEL9.2                        93 k
 python3-subscription-manager-rhsm                        x86_64                       1.29.31+37.gd575edc81-1.git.0.80915ad                         rhsm_RHEL9.2                       177 k
 subscription-manager                                     x86_64                       1.29.31+37.gd575edc81-1.git.0.80915ad                         rhsm_RHEL9.2                       779 k

Transaction Summary
==============================================================================================================================================================================================
Upgrade  4 Packages

Total download size: 1.1 M
:
:
:
Upgraded:
  libdnf-plugin-subscription-manager-1.29.31+37.gd575edc81-1.git.0.80915ad.x86_64                      python3-cloud-what-1.29.31+37.gd575edc81-1.git.0.80915ad.x86_64                       
  python3-subscription-manager-rhsm-1.29.31+37.gd575edc81-1.git.0.80915ad.x86_64                       subscription-manager-1.29.31+37.gd575edc81-1.git.0.80915ad.x86_64                     

Complete!
[root@koza-1 ~]# 
[root@koza-1 ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 4.2.10-1
subscription management rules: 5.43
subscription-manager: 1.29.31+37.gd575edc81-1.git.0.80915ad
[root@koza-1 ~]# 
[root@koza-1 ~]#

[root@koza-1 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.

System Purpose Status: Disabled

[root@koza-1 ~]# 
[root@koza-1 ~]# 
[root@koza-1 ~]# subscription-manager identity 
system identity: 75cc1b44-b29a-4f3a-9256-3edcb3730ac1  << system identity before registration with force option
name: koza-1.4a2m.lab.eng.bos.redhat.com
org name: 13343512
org ID: 13343512
[root@koza-1 ~]# python test.py                         <<<< running the script to use dbus python binding for rhsm 
[root@koza-1 ~]# subscription-manager identity 
system identity: 43d827a5-ec0f-4409-82c2-499e11e222f6   << << system identity after registration with force option
name: koza-1.4a2m.lab.eng.bos.redhat.com
org name: 13343512
org ID: 13343512
[root@koza-1 ~]#

Verified :  The system is re-registered without an exception when using --force option . 

---------------------------------------------------------------------------------------------------------------------------------
Additional Information: test.py has following content

[root@koza-1 ~]# cat test.py 

import dbus

REGISTER_OPTS_DICT = dbus.Dictionary({"force": True}, signature="ss")

system_bus = dbus.SystemBus()
register_server = system_bus.get_object("com.redhat.RHSM1", "/com/redhat/RHSM1/RegisterServer")
address = register_server.Start("C", dbus_interface="com.redhat.RHSM1.RegisterServer")
private_bus = dbus.connection.Connection(address)
register_object = private_bus.get_object("com.redhat.RHSM1", "/com/redhat/RHSM1/Register")
connection_opts = {"host": "subscription.rhsm.stage.redhat.com"}
connection_opts = dbus.Dictionary(connection_opts, signature="ss")
register_object.Register(
    "",
    "*****",
    "******",
    REGISTER_OPTS_DICT,
    connection_opts,
    "C",
    dbus_interface="com.redhat.RHSM1.Register",
)

Comment 5 Zdenek Petracek 2023-01-27 13:39:18 UTC
SM version:
[root@kvm-01-guest01 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 4.2.12-1
subscription management rules: 5.43
subscription-manager: 1.29.32-1.el9

[root@kvm-01-guest01 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.

System Purpose Status: Disabled

[root@kvm-01-guest01 ~]# subscription-manager identity
system identity: a20281b0-66ae-4bed-80eb-033f1ea31030
name: kvm-01-guest01.lab.eng.brq2.redhat.com
org name: 13281785
org ID: 13281785

Running a script for re-registering to the system:
[root@kvm-01-guest01 ~]# python3 script.py
[root@kvm-01-guest01 ~]#

After running the script:
[root@kvm-01-guest01 ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.

System Purpose Status: Disabled

[root@kvm-01-guest01 ~]# subscription-manager identity
system identity: 9c22df3a-afcd-4ed8-9185-157efdd95ed4
name: kvm-01-guest01.lab.eng.brq2.redhat.com
org name: 13281785
org ID: 13281785

^^ System was successfully re-registered --> Final verification PASSED

Comment 7 errata-xmlrpc 2023-05-09 08:18:42 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-2023:2493