Bug 2001476

Summary: 'str' object has no attribute 'decode' When register RHEL-8.5.0-20210902.5 against Satellite6.8/Satellite6.9/Satellite6.10 by bootstrap.py
Product: Red Hat Satellite Reporter: qianzhan
Component: BootstrapAssignee: Evgeni Golov <egolov>
Status: CLOSED ERRATA QA Contact: Stephen Wadeley <swadeley>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.10.0CC: egolov, hhorak, mmccune, mvanderw, saydas, sraut, zhunting
Target Milestone: 6.10.0Keywords: Triaged
Target Release: Unused   
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: 2021-11-16 14:13: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:

Description qianzhan 2021-09-06 08:11:00 UTC
Description of problem:
'str' object has no attribute 'decode' When register RHEL-8.5.0-20210902.5 against Satellite6.8/Satellite6.9/Satellite6.10 by bootstrap.py

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


How reproducible:
always

Steps to Reproduce:
1. Prepare before use bootstrap.py:

rhsm-integrate: INFO: Command run on: ent-01-vm-03.lab.eng.nay.redhat.com, purpose: create activation key
rhsm-integrate: INFO: >>>Remote Run: hammer -u admin -p admin activation-key create --name=RH00069_key --organization-label=Default_Organization --content-view='Default Organization View' --lifecycle-environment=Library
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
Activation key created.

rhsm-integrate: INFO: It's successful to create activationkey RH00069_key


rhsm-integrate: INFO: Command run on: ent-01-vm-03.lab.eng.nay.redhat.com, purpose: add sku to activation key
rhsm-integrate: INFO: >>>Remote Run: hammer -u admin -p admin activation-key add-subscription --name=RH00069_key --organization-label=Default_Organization --quantity=1 --subscription-id=5
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
Subscription added to activation key.

rhsm-integrate: INFO: It's successful to add sku to activation key
rhsm-integrate: INFO: Command run on: ent-01-vm-03.lab.eng.nay.redhat.com, purpose: set activationkey autoattach
rhsm-integrate: INFO: >>>Remote Run: hammer -u admin -p admin activation-key update --auto-attach=true --name=RH00069_key --organization-label=Default_Organization
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
Activation key updated.

rhsm-integrate: INFO: Command run on: ent-01-vm-03.lab.eng.nay.redhat.com, purpose: check activationkey autoattach
rhsm-integrate: INFO: >>>Remote Run: hammer -u admin -p admin activation-key info --name=RH00069_key --organization-label=Default_Organization
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
Name:                  RH00069_key
ID:                    10
Description:           
Host Limit:            Unlimited
Auto Attach:           true
Release Version:       
Lifecycle Environment: Library
Content View:          Default Organization View
Host Collections:      

System Purpose:        
    Service Level:  
    Purpose Usage:  
    Purpose Role:   
    Purpose Addons:


rhsm-integrate: INFO: It's successful to check activationkey autoattach status: true
rhsm-integrate: INFO: Command run on: ent-01-vm-03.lab.eng.nay.redhat.com, purpose: hammer hostgroup list
rhsm-integrate: INFO: >>>Remote Run: hammer -u admin -p admin hostgroup list
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
---|------|-------|------------------|--------------------|------
ID | NAME | TITLE | OPERATING SYSTEM | PUPPET ENVIRONMENT | MODEL
---|------|-------|------------------|--------------------|------
1  | hg   | hg    | RHEL 7           |                    |      
---|------|-------|------------------|--------------------|------

rhsm-integrate: INFO: Hostgroup exists, no need to create it.
rhsm-integrate: INFO: Command run on: hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com, purpose: Install bootstrap.py
rhsm-integrate: INFO: >>>Remote Run: curl -o /root/bootstrap.py http://ent-01-vm-03.lab.eng.nay.redhat.com/pub/bootstrap.py; chmod +x bootstrap.py
rhsm-integrate: INFO: <<<Return Code: 0
rhsm-integrate: INFO: <<<Output:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 71338  100 71338    0     0  60661      0  0:00:01  0:00:01 --:--:-- 60661

rhsm-integrate: INFO: It's successful to install bootstrap.py

2. Register RHEL-8.5.0-20210902.5 against Satellite6.8 by bootstrap.py:

rhsm-integrate: INFO: Command run on: hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com, purpose: Install bootstrap.py
rhsm-integrate: INFO: >>>Remote Run: python3 /root/bootstrap.py --login=admin --password=admin --server=ent-01-vm-03.lab.eng.nay.redhat.com --location='Default Location' --organization='Default Organization' --hostgroup=hg --activationkey=RH00069_key --add-domain --force
rhsm-integrate: INFO: <<<Return Code: 1
rhsm-integrate: INFO: <<<Output:
Foreman Bootstrap Script
This script is designed to register new systems or to migrate an existing system to a Foreman server with Katello
Traceback (most recent call last):
  File "/root/bootstrap.py", line 1334, in <module>
    check_rpm_installed()
  File "/root/bootstrap.py", line 1018, in check_rpm_installed
    package_name = package['name'].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'


Actual results:


Expected results:


Additional info:

Comment 2 Evgeni Golov 2021-09-06 09:18:33 UTC
Hey,

thanks for the report!

Would you have the bandwidth to test the patch in https://github.com/Katello/katello-client-bootstrap/pull/348?

THanks!

Comment 3 qianzhan 2021-09-06 09:46:04 UTC
(In reply to Evgeni Golov from comment #2)
> Hey,
> 
> thanks for the report!
> 
> Would you have the bandwidth to test the patch in
> https://github.com/Katello/katello-client-bootstrap/pull/348?
> 
> THanks!

1. Try bootstrap.py before any changes:

[root@hpe-dl380pgen8-02-vm-1 ~]# grep "p_name = package" -A10 bootstrap.py 
        p_name = package['name'].decode('ascii')
        p_version = package['version'].decode('ascii')
        if rpm.labelCompare(('0', p_version, '1'), required_version) < 0:
            err = "%s %s is too old" % (p_name, p_version)
        else:
            err = None

    return (err is None, err)


def setup_yum_repo(url, gpg_key):
[root@hpe-dl380pgen8-02-vm-1 ~]# 
[root@hpe-dl380pgen8-02-vm-1 ~]# grep "package_name = package" -A10 bootstrap.py 
        package_name = package['name'].decode('ascii')
        if package_name in rpm_sat:
            print_error("%s RPM found. bootstrap.py should not be used on a Katello/Spacewalk/Satellite host." % (package_name))
            sys.exit(1)


def prepare_rhel5_migration():
    """
    Execute specific preparations steps for RHEL 5. Older releases of RHEL 5
    did not have a version of rhn-classic-migrate-to-rhsm which supported
    activation keys. This function allows those systems to get a proper
[root@hpe-dl380pgen8-02-vm-1 ~]# python3 /root/bootstrap.py --login=admin --password=admin --server=ent-01-vm-03.lab.eng.nay.redhat.com --location='Default Location' --organization='Default Organization' --hostgroup=hg --activationkey=RH00069_key --add-domain --force
Foreman Bootstrap Script
This script is designed to register new systems or to migrate an existing system to a Foreman server with Katello
Traceback (most recent call last):
  File "/root/bootstrap.py", line 1334, in <module>
    check_rpm_installed()
  File "/root/bootstrap.py", line 1018, in check_rpm_installed
    package_name = package['name'].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'
[root@hpe-dl380pgen8-02-vm-1 ~]#

2. Change the bootstrap.py according to Comment 2:

[root@hpe-dl380pgen8-02-vm-1 ~]# grep "p_name = package" -A10 bootstrap.py 
        #p_name = package['name'].decode('ascii')
        #p_version = package['version'].decode('ascii')
        try:
            p_name = package['name'].decode('ascii')
            p_version = package['version'].decode('ascii')
        except AttributeError:
            p_name = package['name']
            p_version = package['version']
        if rpm.labelCompare(('0', p_version, '1'), required_version) < 0:
            err = "%s %s is too old" % (p_name, p_version)
        else:
            err = None

    return (err is None, err)


def setup_yum_repo(url, gpg_key):


[root@hpe-dl380pgen8-02-vm-1 ~]# grep "package_name = package" -A10 bootstrap.py 
        #package_name = package['name'].decode('ascii')
        try:
            package_name = package['name'].decode('ascii')
        except AttributeError:
            package_name = package['name']
        if package_name in rpm_sat:
            print_error("%s RPM found. bootstrap.py should not be used on a Katello/Spacewalk/Satellite host." % (package_name))
            sys.exit(1)


def prepare_rhel5_migration():
    """
    Execute specific preparations steps for RHEL 5. Older releases of RHEL 5
    did not have a version of rhn-classic-migrate-to-rhsm which supported
    activation keys. This function allows those systems to get a proper

3. Run bootstrap.py after changes in step 2:

[root@hpe-dl380pgen8-02-vm-1 ~]# python3 /root/bootstrap.py --login=admin --password=admin --server=ent-01-vm-03.lab.eng.nay.redhat.com --location='Default Location' --organization='Default Organization' --hostgroup=hg --activationkey=RH00069_key --add-domain --force
Foreman Bootstrap Script
This script is designed to register new systems or to migrate an existing system to a Foreman server with Katello
[NOTIFICATION], [2021-09-06 05:49:53], [This system is not registered to RHN. Attempting to register via subscription-manager]
[NOTIFICATION], [2021-09-06 05:49:53], [Checking subscription manager prerequisites]
[RUNNING], [2021-09-06 05:49:54], [/usr/bin/yum -y remove subscription-manager-gnome]
Updating Subscription Management repositories.
No match for argument: subscription-manager-gnome
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!
[SUCCESS], [2021-09-06 05:49:58], [/usr/bin/yum -y remove subscription-manager-gnome], completed successfully.
[NOTIFICATION], [2021-09-06 05:49:58], [subscription-manager is installed already. Attempting update]
[RUNNING], [2021-09-06 05:49:58], [/usr/bin/yum -y update subscription-manager 'subscription-manager-migration-*']
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS  0.0  B/s |   0  B     00:04    
Errors during downloading metadata for repository 'rhel-8-for-x86_64-baseos-beta-rpms':
  - Curl error (35): SSL connect error for https://ent-01-vm-03.lab.eng.nay.redhat.com/pulp/repos/Default_Organization/Library/content/beta/rhel8/8/x86_64/baseos/os/repodata/repomd.xml [error:1408F10B:SSL routines:ssl3_get_record:wrong version number]
Error: Failed to download metadata for repo 'rhel-8-for-x86_64-baseos-beta-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[WARNING], [2021-09-06 05:50:07], NON-FATAL: [/usr/bin/yum -y update subscription-manager 'subscription-manager-migration-*'] failed to execute properly.
[RUNNING], [2021-09-06 05:50:07], [/usr/bin/yum -y update yum openssl python]
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS  0.0  B/s |   0  B     00:01    
Errors during downloading metadata for repository 'rhel-8-for-x86_64-baseos-beta-rpms':
  - Curl error (35): SSL connect error for https://ent-01-vm-03.lab.eng.nay.redhat.com/pulp/repos/Default_Organization/Library/content/beta/rhel8/8/x86_64/baseos/os/repodata/repomd.xml [error:1408F10B:SSL routines:ssl3_get_record:wrong version number]
Error: Failed to download metadata for repo 'rhel-8-for-x86_64-baseos-beta-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[WARNING], [2021-09-06 05:50:13], NON-FATAL: [/usr/bin/yum -y update yum openssl python] failed to execute properly.
[NOTIFICATION], [2021-09-06 05:50:13], [Removing old Katello agent and certs]
[RUNNING], [2021-09-06 05:50:13], [/usr/bin/yum -y remove 'katello-ca-consumer-*' katello-agent gofer katello-host-tools katello-host-tools-fact-plugin]
Updating Subscription Management repositories.
No match for argument: katello-agent
No match for argument: gofer
No match for argument: katello-host-tools
No match for argument: katello-host-tools-fact-plugin
Dependencies resolved.
========================================================================================
 Package                                                   Arch    Version
                                                                         Repo       Size
========================================================================================
Removing:
 katello-ca-consumer-ent-01-vm-03.lab.eng.nay.redhat.com   noarch  1.0-1 @@System   21 k

Transaction Summary
========================================================================================
Remove  1 Package

Freed space: 21 k
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Erasing          : katello-ca-consumer-ent-01-vm-03.lab.eng.nay.redhat.   1/1 
  Running scriptlet: katello-ca-consumer-ent-01-vm-03.lab.eng.nay.redhat.   1/1 
  Verifying        : katello-ca-consumer-ent-01-vm-03.lab.eng.nay.redhat.   1/1 
Installed products updated.

Removed:
  katello-ca-consumer-ent-01-vm-03.lab.eng.nay.redhat.com-1.0-1.noarch          

Complete!
[SUCCESS], [2021-09-06 05:50:28], [/usr/bin/yum -y remove 'katello-ca-consumer-*' katello-agent gofer katello-host-tools katello-host-tools-fact-plugin], completed successfully.
[SUCCESS], [2021-09-06 05:50:28], [Removing /etc/rhsm/ca/katello-server-ca.pem], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:28], [System appears to be registered via another entitlement server. Attempting unregister]
[NOTIFICATION], [2021-09-06 05:50:28], [Cleaning old yum metadata]
[RUNNING], [2021-09-06 05:50:28], [/usr/bin/yum -y clean metadata dbcache]
Updating Subscription Management repositories.
Cache was expired
119 files removed
[SUCCESS], [2021-09-06 05:50:29], [/usr/bin/yum -y clean metadata dbcache], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:29], [Unregistering]
[RUNNING], [2021-09-06 05:50:29], [/usr/sbin/subscription-manager unregister]
Unregistering from: subscription.rhsm.redhat.com:443/subscription
Network error. Please check the connection details, or see /var/log/rhsm/rhsm.log for more information.
[WARNING], [2021-09-06 05:50:30], NON-FATAL: [/usr/sbin/subscription-manager unregister] failed to execute properly.
[RUNNING], [2021-09-06 05:50:30], [/usr/sbin/subscription-manager clean]
All local data removed
[SUCCESS], [2021-09-06 05:50:31], [/usr/sbin/subscription-manager clean], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:31], [Writing custom cURL configuration to allow download via HTTPS without certificate verification]
[NOTIFICATION], [2021-09-06 05:50:31], [Retrieving Client CA Certificate RPMs]
[RUNNING], [2021-09-06 05:50:31], [rpm -Uvh https://ent-01-vm-03.lab.eng.nay.redhat.com/pub/katello-ca-consumer-latest.noarch.rpm]
Retrieving https://ent-01-vm-03.lab.eng.nay.redhat.com/pub/katello-ca-consumer-latest.noarch.rpm
Verifying...                          ########################################
Preparing...                          ########################################
Updating / installing...
katello-ca-consumer-ent-01-vm-03.lab.e########################################
[SUCCESS], [2021-09-06 05:50:34], [rpm -Uvh https://ent-01-vm-03.lab.eng.nay.redhat.com/pub/katello-ca-consumer-latest.noarch.rpm], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:34], [Deleting cURL configuration]
[SUCCESS], [2021-09-06 05:50:34], [Removing /tmp/tmp17pivcah], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:34], [Writing FQDN katello-fact]
[RUNNING], [2021-09-06 05:50:45], [Disassociating host id 21 for host hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com]
[RUNNING], [2021-09-06 05:50:47], [Deleting host id 21 for host hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com]
[RUNNING], [2021-09-06 05:50:50], [Calling Foreman API to create a host entry associated with the group & org]
[SUCCESS], [2021-09-06 05:50:52], [Successfully created host hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com], completed successfully.
[NOTIFICATION], [2021-09-06 05:50:53], [Calling subscription-manager]
[RUNNING], [2021-09-06 05:50:53], [/usr/sbin/subscription-manager config --server.server_timeout=900]

[SUCCESS], [2021-09-06 05:50:54], [/usr/sbin/subscription-manager config --server.server_timeout=900], completed successfully.
[RUNNING], [2021-09-06 05:50:54], [/usr/sbin/subscription-manager register --org 'Default_Organization' --name 'hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com' --activationkey 'RH00069_key'  --serverurl=https://ent-01-vm-03.lab.eng.nay.redhat.com:443/rhsm --baseurl=https://ent-01-vm-03.lab.eng.nay.redhat.com/pulp/repos --force]
The system has been registered with ID: 3bbfe5c3-a760-4669-9362-f6b22d249f42
The registered system name is: hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux for x86_64 Beta
Status:       Subscribed

[SUCCESS], [2021-09-06 05:51:31], [/usr/sbin/subscription-manager register --org 'Default_Organization' --name 'hpe-dl380pgen8-02-vm-1.hpe2.lab.eng.bos.redhat.com' --activationkey 'RH00069_key'  --serverurl=https://ent-01-vm-03.lab.eng.nay.redhat.com:443/rhsm --baseurl=https://ent-01-vm-03.lab.eng.nay.redhat.com/pulp/repos --force], completed successfully.
[RUNNING], [2021-09-06 05:51:31], [/usr/bin/systemctl enable rhsmcertd]

[SUCCESS], [2021-09-06 05:51:31], [/usr/bin/systemctl enable rhsmcertd], completed successfully.
[RUNNING], [2021-09-06 05:51:31], [/usr/bin/systemctl restart rhsmcertd]

[SUCCESS], [2021-09-06 05:51:31], [/usr/bin/systemctl restart rhsmcertd], completed successfully.
[NOTIFICATION], [2021-09-06 05:51:31], [Installing the Katello Host Tools]
[RUNNING], [2021-09-06 05:51:31], [/usr/bin/yum -y install katello-host-tools]
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS  0.0  B/s |   0  B     00:04    
Errors during downloading metadata for repository 'rhel-8-for-x86_64-baseos-beta-rpms':
  - Curl error (35): SSL connect error for https://ent-01-vm-03.lab.eng.nay.redhat.com/pulp/repos/Default_Organization/Library/content/beta/rhel8/8/x86_64/baseos/os/repodata/repomd.xml [error:1408F10B:SSL routines:ssl3_get_record:wrong version number]
Error: Failed to download metadata for repo 'rhel-8-for-x86_64-baseos-beta-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[ERROR], [2021-09-06 05:51:40], EXITING: [/usr/bin/yum -y install katello-host-tools] failed to execute properly.

Comment 4 Evgeni Golov 2021-09-06 10:11:46 UTC
looks like it's working? not sure where the SSL error comes from, but that's certainly a different topic to look into

Comment 6 Evgeni Golov 2021-09-20 08:45:07 UTC
PR was merged

Comment 13 errata-xmlrpc 2021-11-16 14:13: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 (Moderate: Satellite 6.10 Release), 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/RHSA-2021:4702

Comment 14 Mike McCune 2022-01-06 18:34:30 UTC
Created attachment 1849306 [details]
katello-client-bootstrap-1.7.7-1.el7sat.noarch.rpm

Comment 15 Mike McCune 2022-01-06 18:38:48 UTC
*** Satellite 6.9 Hotfix Available ***

1) Download katello-client-bootstrap-1.7.7-1.el7sat.noarch.rpm from this bugzilla to your Satellite

2) Install:

# rpm -Uvh katello-client-bootstrap-1.7.7-1.el7sat.noarch.rpm

3) resume operations

Comment 16 Brad Buckingham 2022-01-31 14:27:59 UTC
*** Bug 2046085 has been marked as a duplicate of this bug. ***