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 1984133

Summary: subscription-manager repos --enable=REPO --disable=REPO --enable=REPO is failing to win on the last parameter
Product: Red Hat Enterprise Linux 9 Reporter: John Sefler <jsefler>
Component: subscription-managerAssignee: Pino Toscano <ptoscano>
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: low Docs Contact:
Priority: unspecified    
Version: 9.0CC: arpandey, ptoscano, redakkan
Target Milestone: rcKeywords: Regression, Triaged
Target Release: 9.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.29.21-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-17 15:58:13 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 2021-07-20 18:47:40 UTC
Description of problem:

When specifying multiple "--enable" and "--disable" options with the subscription-manager repos module against the same REPOID, historically the last option specified from left to right would win.  This behavior was originally established in bug 1115499.  Note that this subtle policy was never documented in the man pages.  Now in RHEL 9, it appears that the "--disable" option wins which is a regression.

I suspect this change was caused by the rhel-9 commit "Replace optparse with argparse" https://github.com/candlepin/subscription-manager/commit/eef1bb13f8924af9539f98330465c110f2df92b5

Version-Release number of selected component (if applicable):
[root@kvm-06-guest23 ~]# rpm -q subscription-manager
subscription-manager-1.29.18-1.el9.x86_64
[root@kvm-06-guest23 ~]# rpm -q subscription-manager --changelog | grep -i "Replace optparse"
- Replace optparse with argparse (wpoteat)


How reproducible:


Steps to Reproduce:

_____________________ON RHEL9__________________
[root@kvm-06-guest23 ~]# rpm -q subscription-manager
subscription-manager-1.29.18-1.el9.x86_64

[root@kvm-06-guest23 ~]# subscription-manager repos --enable=rhel-9-for-x86_64-rt-beta-rpms --disable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is disabled for this system.         <========= PASS

[root@kvm-06-guest23 ~]# subscription-manager repos --disable=rhel-9-for-x86_64-rt-beta-rpms --enable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is disabled for this system.         <========= FAIL: EXPECTED "enabled"


_____________________ON RHEL8__________________
[root@kvm-06-guest21 ~]# rpm -q subscription-manager
subscription-manager-1.28.19-1.el8.x86_64

[root@kvm-06-guest21 ~]# subscription-manager repos --enable=rhel-8-for-x86_64-rt-beta-rpms --disable=rhel-8-for-x86_64-rt-beta-rpms
Repository 'rhel-8-for-x86_64-rt-beta-rpms' is disabled for this system.         <========= PASS

[root@kvm-06-guest21 ~]# subscription-manager repos --disable=rhel-8-for-x86_64-rt-beta-rpms --enable=rhel-8-for-x86_64-rt-beta-rpms
Repository 'rhel-8-for-x86_64-rt-beta-rpms' is enabled for this system.         <========= PASS


_____________________ON RHEL7__________________
[root@ibm-x3650m4-01-vm-14 ~]# rpm -q subscription-manager
subscription-manager-1.24.48-1.el7_9.x86_64

[root@ibm-x3650m4-01-vm-14 ~]# subscription-manager repos --enable=rhel-7-server-rpms --disable=rhel-7-server-rpms
Repository 'rhel-7-server-rpms' is disabled for this system.         <========= PASS

[root@ibm-x3650m4-01-vm-14 ~]# subscription-manager repos --disable=rhel-7-server-rpms --enable=rhel-7-server-rpms
Repository 'rhel-7-server-rpms' is enabled for this system.         <========= PASS



Actual results:
  On RHEL-9, the --disable option always wins when specifying both --enable and --disable with the same REPOID

Expected results:
  On older RHEL, the last option always wins when specifying both --enable and --disable with the same REPOID

Additional info:

Comment 1 Pino Toscano 2021-07-23 09:49:36 UTC
(In reply to John Sefler from comment #0)
> I suspect this change was caused by the rhel-9 commit "Replace optparse with
> argparse"
> https://github.com/candlepin/subscription-manager/commit/
> eef1bb13f8924af9539f98330465c110f2df92b5

Yes, this is indeed the case, and it is due to different functionalities in optparse vs argparse.

When adding an option, optparse support passing a callback, i.e. a function that is called for the option & its value. There was a common function for both --enable and --disable, adding all the repositories to a single list with an enable/disable flag, so the order of the repositories is preserved.

After the conversion to argparse, there is no callback anymore, as it is not supported (in the same form as provided by optparse) by argparse. Instead, each of --enable and --disable piles its repositories in an own list, and these two lists are combined in a single list with first the repositories to enable, then those to disable. This explains the finding:

> Now in RHEL 9, it appears that the "--disable" option wins which is a regression.

A proper solution is to implement a custom argparse.Action for --enable and --disable, which should implement the same behaviour (appending to the same list) of the old callback.

Comment 2 Pino Toscano 2021-07-23 09:52:06 UTC
Additional open question:

> Note that this subtle policy was never documented in the man pages.

Considering that I've seen plenty of examples doing "--disable=* --enable=somerepo" (and I even used it myself), it seems that there is this expectation of order done by --enable & --disable.

Hence, should we explicitly document it? (My personal vote goes to "yes".)

Comment 3 Pino Toscano 2021-07-30 11:21:59 UTC
Triaging notes:
- this is indeed a regression that we want to fix
- we want to explicitly document the ordering of --enable & --disable, as it is something people already rely on

Comment 5 Archana Pandey 2021-11-17 13:55:33 UTC
pre-verifying on subscription-manager-1.29.21-1.el9.x86_64

reproducing issue :
[root@auto-hv-01-guest04 ~]# rpm -q subscription-manager
subscription-manager-1.29.18-2.el9.x86_64
[root@auto-hv-01-guest04 ~]#

[root@auto-hv-01-guest04 ~]# subscription-manager repos --disable=rhel-9-for-x86_64-rt-beta-rpm --enable= rhel-9-for-x86_64-rt-beta-rpm
Repository 'rhel-9-for-x86_64-rt-beta-rpm' is disabled for this system.  <<< sequence of arguments not being honored, repository should be enabled
[root@auto-hv-01-guest04 ~]#  


Verifying on subscription-manager-1.29.21-1.el9.x86_64:

[root@auto-hv-01-guest04 ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 3.2.21-1
subscription management rules: 5.41
subscription-manager: 1.29.21-1.el9

[root@auto-hv-01-guest04 ~]# rpm -qa --changelog subscription-manager | grep 1984133
- 1984133: repos: respect order of --enable & --disable (ptoscano)
[root@auto-hv-01-guest04 ~]# 

[root@auto-hv-01-guest04 ~]# subscription-manager repos –disable=rhel-9-for-x86_64-rt-beta-rpms --enable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is enabled for this system.  <<<<< as expected repository is enabled. PASS
[root@auto-hv-01-guest04 ~]# 


[root@auto-hv-01-guest04 ~]# subscription-manager repos --disable=rhel-9-for-x86_64-rt-beta-rpms --enable=rhel-9-for-x86_64-rt-beta-rpms --disable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is disabled for this system.   <<<< as expected PASS
[root@auto-hv-01-guest04 ~]# 


Additional info:

checking documentation update for same.
[root@auto-hv-01-guest04 ~]# man subscription-manager | grep REPO_ID -A 5
       --enable=REPO_ID
              Enables the specified repository, which is made available by the content sources identified in the system subscriptions. To enable multiple  repositories,
              use this argument multiple times. Wild cards * and ? are supported. The repositories enabled by this option and disabled by --disable are processed in the
              same order they are specified.   <<<<  man updated as required

       --disable=REPO_ID
              Disables the specified repository, which is made available by the content sources identified in the system subscriptions. To  disable  multiple  reposito‐
              ries,  use  this argument multiple times. Wild cards * and ? are supported. The repositories disabled by this option and enabled by --enable are processed
              in the same order they are specified.  <<<<<<<  man updated as required

Verification PASSED

Comment 9 Rehana 2021-12-01 12:25:14 UTC
Verifying on :
=============


# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 3.2.21-1
subscription management rules: 5.41
subscription-manager: 1.29.21-1.el9

# rpm -q subscription-manager --changelog | grep 1984133
- 1984133: repos: respect order of --enable & --disable (ptoscano)

# subscription-manager attach --auto
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux for x86_64 Beta
Status:       Subscribed


# subscription-manager repos --disable=rhel-9-for-x86_64-rt-beta-rpms --enable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is enabled for this system.  --> PASSED

# subscription-manager repos --disable=rhel-9-for-x86_64-rt-beta-rpms --enable=rhel-9-for-x86_64-rt-beta-rpms --disable=rhel-9-for-x86_64-rt-beta-rpms
Repository 'rhel-9-for-x86_64-rt-beta-rpms' is disabled for this system. --> PASSED 

# man subscription-manager | grep REPO_ID -A 5
       --enable=REPO_ID
              Enables the specified repository, which is made available by the content sources identified in the system subscriptions. To enable multiple repositories,use  this  argument  multiple times. Wild cards * and ? are supported. The repositories enabled by this option and disabled by --disable are processed in the same order they are specified.

       --disable=REPO_ID
              Disables the specified repository, which is made available by the content sources identified in the system subscriptions. To disable  multiple  repositories,  use this argument multiple times. Wild cards * and ? are supported. The repositories disabled by this option and enabled by --enable are processed in the same order they are specified.

Also the man pages have been updated !! 

Moving the bug to Verified!!

Comment 11 errata-xmlrpc 2022-05-17 15:58:13 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 (new packages: subscription-manager), 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-2022:3984