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 2096852

Summary: When running subscription-manager from a script, it might hang if some arguments are not provided
Product: Red Hat Enterprise Linux 8 Reporter: David Hill <dhill>
Component: subscription-managerAssignee: Jason Jerome <jajerome>
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: low Docs Contact:
Priority: unspecified    
Version: 8.2CC: jsefler, jstavel, redakkan
Target Milestone: rcKeywords: Triaged
Target Release: 8.8Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: subscription-manager-1.28.33-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2097679 (view as bug list) Environment:
Last Closed: 2023-05-16 09:07:12 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:    
Bug Blocks: 2097679    

Description David Hill 2022-06-14 12:37:56 UTC
Description of problem:
When running subscription-manager from a script, it might hang if some arguments are not provided as it will prompt the user for the missing argument.   When ran from scripts for automation, a failure would be much better.

Perhaps the following chunk of code could be added somewhere:


import sys
if sys.stdin and sys.stdin.isatty():
    # prompt the user for missing arguments
else:
    # fail with an error message

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

How reproducible:
Always

Steps to Reproduce:
1. Use diskimage-builder and don't provide --environment when one is required.
2.
3.

Actual results:
Blocks at subscription-manager

Expected results:
Error message such as "--environment is missing"

Additional info:

Comment 2 Jan Stavel 2022-11-04 19:52:32 UTC
The fix works as supposed:

root@localhost ~]# ssh -T localhost "subscription-manager register"
root@localhost's password: 
Registering to: subscription.rhsm.stage.redhat.com:443/subscription
Error: --username is a required parameter in non-interactive mode.




[root@localhost ~]# rpm -qa | grep subscription-manager
subscription-manager-rhsm-certificates-1.28.33-1.el8.x86_64
subscription-manager-initial-setup-addon-1.28.33-1.el8.x86_64
dnf-plugin-subscription-manager-1.28.33-1.el8.x86_64
subscription-manager-1.28.33-1.git.0.34a04aa.el8.x86_64
subscription-manager-cockpit-1.28.33-1.git.0.34a04aa.el8.noarch
python3-subscription-manager-rhsm-1.28.33-1.git.0.34a04aa.el8.x86_64

Comment 3 Jan Stavel 2022-11-08 21:18:21 UTC
PLAY [subscription-manager raises error when user input is required in case tty is not allocated] ***

TASK [Info about version of the entitlement stack] *****************************
ok: [192.168.122.53] => 
  msg: |2-
    server type: This system is currently not registered.
    subscription management server: 4.2.10-1
    subscription management rules: 5.43
    subscription-manager: 1.28.33-1.git.0.34a04aa.el8

TASK [Register in a script without TTY - without org specified] ****************
  cmd: ssh -T localhost "subscription-manager register --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument - org

TASK [List availabled environments in a script without TTY - without org specified] ***
  cmd: ssh -T localhost "subscription-manager environments --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument - org

TASK [List availabled environments in a script without TTY - without org specified] ***
  cmd: ssh -T localhost "subscription-manager environments --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --org

TASK [List availabled environments in a script without TTY - without username specified] ***
  cmd: ssh -T localhost "subscription-manager environments"
  rc: 64
  stdout: |-
    root@localhost's password:
    This operation requires user credentials
    Error: --username is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --username

TASK [Register a system with account that has more orgs available - without environment specified] ***
  cmd: ssh -T localhost "subscription-manager register  --username testuser1 --password password --org snowwhite"
  rc: 64
  stdout: |-
    root@localhost's password:
    Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
    Hint: Organization "snowwhite" contains following environments: ArchanaEnv1, ArchanaEnv2
    Error: --environments is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --environments

TASK [Register a system with account that has more orgs available - without environment specified, without environment defined] ***
changed: [192.168.122.53]

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: Info about registering of a system appeared.

TASK [unregister a system] *****************************************************
changed: [192.168.122.53]

TASK [Register a system with account that has one org available - without environment defined] ***
changed: [192.168.122.53]

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: Info about registering of a system appeared.



PLAY [subscription-manager raises error when user input is required in case tty is not allocated] ***

TASK [Info about version of the entitlement stack] *****************************
ok: [192.168.122.53] => 
  msg: |2-
    server type: This system is currently not registered.
    subscription management server: 4.2.10-1
    subscription management rules: 5.43
    subscription-manager: 1.28.33-1.git.0.34a04aa.el8

TASK [Register in a script without TTY - without org specified] ****************
  cmd: ssh -T localhost "subscription-manager register --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument - org

TASK [List availabled environments in a script without TTY - without org specified] ***
  cmd: ssh -T localhost "subscription-manager environments --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument - org

TASK [List availabled environments in a script without TTY - without org specified] ***
  cmd: ssh -T localhost "subscription-manager environments --username testuser1 --password password"
  rc: 64
  stdout: |-
    root@localhost's password:
    Hint: User "testuser1" is member of following organizations: snowwhite, admin
    Error: --org is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --org

TASK [List availabled environments in a script without TTY - without username specified] ***
  cmd: ssh -T localhost "subscription-manager environments"
  rc: 64
  stdout: |-
    root@localhost's password:
    This operation requires user credentials
    Error: --username is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --username

TASK [Register a system with account that has more orgs available - without environment specified] ***
  cmd: ssh -T localhost "subscription-manager register  --username testuser1 --password password --org snowwhite"
  rc: 64
  stdout: |-
    root@localhost's password:
    Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
    Hint: Organization "snowwhite" contains following environments: ArchanaEnv1, ArchanaEnv2
    Error: --environments is a required parameter in non-interactive mode.

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: The app informs about required argument --environments

TASK [Register a system with account that has more orgs available - without environment specified, without environment defined] ***
changed: [192.168.122.53]

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: Info about registering of a system appeared.

TASK [unregister a system] *****************************************************
changed: [192.168.122.53]

TASK [Register a system with account that has one org available - without environment defined] ***
changed: [192.168.122.53]

TASK [ansible.builtin.assert] **************************************************
ok: [192.168.122.53] => changed=false 
  msg: Info about registering of a system appeared.

Comment 9 errata-xmlrpc 2023-05-16 09:07:12 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:2984