Bug 2090390

Summary: undefined method `find' for nil:NilClass when importing content that has gpg_keys associated to it
Product: Red Hat Satellite Reporter: Joniel Pasqualetto <jpasqual>
Component: Inter Satellite SyncAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Radek Mynar <rmynar>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.10.5CC: ahumbe, jbhatia, jjansky, mkalyat, osousa, pmoravec, saydas, tmilsond, vsedmik, wclark
Target Milestone: 6.11.1Keywords: EasyFix, PrioBumpGSS, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tfm-rubygem-katello-4.3.0.43-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2093407 2103110 (view as bug list) Environment:
Last Closed: 2022-07-27 17:27: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:
Attachments:
Description Flags
Hotfix RPM for Satellite 6.11.0 on RHEL7
none
Hotfix RPM for Satellite 6.11.0 on RHEL8 none

Description Joniel Pasqualetto 2022-05-25 16:16:00 UTC
Description of problem:

Fail to parse the the metadata when importing products/repositories that have a GPG key associated. Import task fails almost immediately with the following trace back:

~~~
2022-05-25T10:22:02 [E|app|0a12262c] NoMethodError: undefined method `find' for nil:NilClass
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb:108:in `gpg_key_for_product'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb:63:in `block in parse_products'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb:57:in `map'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb:57:in `parse_products'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb:27:in `initialize'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/lib/actions/katello/content_view_version/import.rb:6:in `new'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/lib/actions/katello/content_view_version/import.rb:6:in `plan'
 0a12262c | /opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.9/lib/dynflow/action.rb:515:in `block (3 levels) in execute_plan'
~~~

Version-Release number of selected component (if applicable):
Satellite 6.10.5 (katello-4.1.1.56)

How reproducible:
Always

Steps to Reproduce:
1. Create a custom product/repository and assign a GPG key to it
2. Create a CV including the repository created on step 1
3. Create a complete export of the CV created on step 2
4. Try importing the content

Actual results:

Fail to process the metadata and import doesn't work:

~~~
# hammer content-import version --path /var/lib/pulp/imports/Zabbix/1.0/2022-05-25T11-20-12-04-00/ --organization-id 4
Could not import the archive.:
  undefined method `find' for nil:NilClass
~~~


Expected results:

Import to start

Additional info:

Issue happens here (file /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.1.56/app/services/katello/pulp3/content_view_version/metadata_map.rb):

~~~
        def initialize(metadata:)
          @toc = metadata[:toc]
          @products = parse_products(metadata[:products]) if metadata[:products]
          @repositories = parse_repositories(metadata[:repositories]) if metadata[:repositories]
          @content_view = parse_content_view(metadata[:content_view]) if metadata[:content_view]
          @content_view_version = parse_content_view_version(metadata[:content_view_version]) if metadata[:content_view_version]
          @from_content_view_version = parse_content_view_version(metadata[:from_content_view_version]) if metadata[:from_content_view_version]
          @gpg_keys = parse_gpg_keys(metadata[:gpg_keys]) if metadata[:gpg_keys]
        end
~~~

When initializing the variable @products, the parser tries to access the variable @gpg_keys, that has not been initialized yet at that point. Simply changing the order of the initialization of those variables allows the import to happen.

Comment 3 Bryan Kearney 2022-06-02 00:04:39 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/34966 has been resolved.

Comment 4 Radek Mynar 2022-07-15 13:34:35 UTC
Importing library and contentview containing repository with associated GPG key works properly.

VERIFIED with Satellite 6.11.1 SNAP1 @RHEL8.6 (rubygem-katello-4.3.0.44-1.el8sat.noarch)

Comment 6 wclark 2022-07-25 19:21:24 UTC
Created attachment 1899240 [details]
Hotfix RPM for Satellite 6.11.0 on RHEL7

INSTALL INSTRUCTIONS:

1. Take a complete backup or snapshot of Satellite 6.11.0 server

2. Download the hotfix RPM for Satellite 6.11.0 on RHEL7 attached to this BZ and copy it to Satellite server

3. # yum install ./tfm-rubygem-katello-4.3.0.42-2.HOTFIXRHBZ2090390.el7sat.noarch.rpm --disableplugin=foreman-protector

4. # satellite-maintain service restart

Comment 7 wclark 2022-07-25 19:23:08 UTC
Created attachment 1899241 [details]
Hotfix RPM for Satellite 6.11.0 on RHEL8

INSTALL INSTRUCTIONS:

1. Take a complete backup or snapshot of Satellite 6.11.0 server

2. Download the hotfix RPM for Satellite 6.11.0 on RHEL8 attached to this BZ and copy it to Satellite server

3. # dnf install ./rubygem-katello-4.3.0.42-2.HOTFIXRHBZ2090390.el8sat.noarch.rpm --disableplugin=foreman-protector

4. # satellite-maintain service restart

Comment 11 errata-xmlrpc 2022-07-27 17:27: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 (Satellite 6.11.1 Async Bug Fix 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-2022:5742