Bug 2029828

Summary: TFTP Storage check fails on undefined method `[]' for nil:NilClass
Product: Red Hat Satellite Reporter: Evgeni Golov <egolov>
Component: Satellite MaintainAssignee: Evgeni Golov <egolov>
Status: CLOSED ERRATA QA Contact: Gaurav Talreja <gtalreja>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.11.0CC: apatel, aupadhye, kgaikwad, pcreech, vsedmik
Target Milestone: 6.11.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: rubygem-foreman_maintain-1.0.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-07-05 14:30:51 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 Evgeni Golov 2021-12-07 12:03:37 UTC
Description of problem:

On a Satellite 7.0 with no Puppetserver deployed, foreman-maintain fails to restart the later in a weird fashion:

# foreman-maintain service restart --only puppetserver
undefined method `[]' for nil:NilClass


Version-Release number of selected component (if applicable):
rubygem-foreman_maintain-0.9.3-1.el7sat.noarch

How reproducible:
100% 

Steps to Reproduce:
1. foreman-maintain service restart --only puppetserver

Actual results:
undefined method `[]' for nil:NilClass

Expected results:
Something that tells the user "can't do this, there is no puppetserver"

Additional info:

Comment 1 Evgeni Golov 2021-12-07 13:32:13 UTC
oooh, this is different

the error happens for *any* call of `foreman-maintain` with `--only` ?!

# foreman-maintain service restart --only foreman
undefined method `[]' for nil:NilClass

# foreman-maintain service start --only foreman
undefined method `[]' for nil:NilClass

seems to affect start/stop/restart, status is fine:

# foreman-maintain service status --only foreman
Running Status Services
================================================================================
Get status of applicable services: 

Displaying the following service(s):
foreman
| displaying foreman                                                            
● foreman.service - Foreman
   Loaded: loaded (/usr/lib/systemd/system/foreman.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/foreman.service.d
           └─installer.conf


# foreman-maintain service status --only puppetserver
Running Status Services
================================================================================
Get status of applicable services: 

Displaying the following service(s):                                  [FAIL]
No service found matching your parameter 'puppetserver'

Comment 2 Evgeni Golov 2021-12-07 14:14:55 UTC
okay, the error is somewhere completely else, it just gets bubbled up here.

the problem is in ./definitions/checks/foreman_proxy/check_tftp_storage.rb:

    def self.lookup_token_duration
      data = feature(:foreman_database). \
             query("select s.value, s.default from settings s \
                    where category = 'Setting::Provisioning' and name = 'token_duration'")
      YAML.load(data[0]['value'] || data[0]['default'])
    end

but `data` is `[]`, so `data[0]` is nil and `nil['value']` gets you the nice error

Comment 3 Evgeni Golov 2021-12-07 14:17:23 UTC
Created redmine issue https://projects.theforeman.org/issues/34100 from this bug

Comment 4 Gaurav Talreja 2022-02-22 10:20:32 UTC
Verified.

Tested on Satellite 7.0 Snap 10.0 for both EL7 and EL8 installations
Version: rubygem-foreman_maintain-1.0.3-1.el8sat.noarch

Steps:
1. foreman-maintain service stop --only foreman
2. foreman-maintain service start --only foreman
3. foreman-maintain service status --only foreman
4. foreman-maintain service restart --only foreman

Observation:
foreman-maintain service stop/start/status/restart works fine with --only option with no errors

Comment 8 errata-xmlrpc 2022-07-05 14:30:51 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.11 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-2022:5498