Hypervisors tasks showing warning as result - undefined method `[]' for nil:NilClass

Solution Verified - Updated

Environment

  • Red Hat Satellite 6.3
  • Red Hat Satellite 6.4
  • Red Hat Satellite 6.5

Issue

  • After configuring virt-who via Satellite webui (virt-who configuration helper) for access to multiple virtualization environments, we are able to see errors on production.log and on tasks (some tasks with warning as Result). As a consequence, the Guest information will not be updated on the Satellite side causing issues related to subscription process/entitlement.

  • Task fails with error

      undefined method '[]' for nil:NilClass
    

Resolution

Software fix (preferred)

The problem has been solved in Satellite 6.6 with the errata RHSA-2019:3172.

If you're in Satellite 6.5 and are unable to upgrade to a later release, please open a support case in order to receive a temporary hotfix for the problem.

Workaround

While the preferred resolution path is via candlepin update, below can see a workaround.

Access the virt-who directory.

# cd /etc/virt-who.d/

Check your files on this directory, we will choose one to collect the information we need.

# ls -1 virt-who-config-*.conf
virt-who-config-1.conf
virt-who-config-2.conf
virt-who-config-3.conf
virt-who-config-4.conf
virt-who-config-5.conf

Using virt-who-config-1.conf for example, let's check the content of this file below:

# cat virt-who-config-1.conf
### This configuration file is managed via the virt-who configure plugin
### manual edits will be deleted.
[virt-who-config-1]
type=libvirt
hypervisor_id=hostname
owner=ACME
env=Library
server=192.168.1.1
username=root
encrypted_password=e2dbf788ee455da14c743e6db8d76c44f5622c5ea9b8a15988cf035b52e79b94
rhsm_hostname=sat631.local.domain
rhsm_username=virt_who_reporter_1
rhsm_encrypted_password=6947850c07d3f3adb5375880d15d3869a83d31f010a933e0aadbc2c4706d198d
rhsm_prefix=/rhsm

Basically, we need to update all conf files to use the same rhsm_username and rhsm_encrypted_password. To do this, let's continue

# grep -E '(rhsm_username|rhsm_encrypted_password)' virt-who-config-1.conf
rhsm_username=virt_who_reporter_1
rhsm_encrypted_password=6947850c07d3f3adb5375880d15d3869a83d31f010a933e0aadbc2c4706d198d

At this moment we know the values of rhsm_username and rhsm_encrypted_password, now create a new script that will update all files. In our example we will create the file /root/virt-who-update.sh according to below:

# >/root/virt-who-update.sh
# chmod +x /root/virt-who-update.sh

Below the content of the file:

#!/bin/bash
cd /etc/virt-who.d
sed -i -e 's/^rhsm_username.*/rhsm_username=virt_who_reporter_1/g' *.conf
sed -i -e 's/^rhsm_encrypted_password.*/rhsm_encrypted_password=6947850c07d3f3adb5375880d15d3869a83d31f010a933e0aadbc2c4706d198d/g' *.conf

Note. The information about rhsm_username and rhsm_encrypted_password was collected from the command above. PLEASE don't copy/paste the lines above to use in your environment because it will surely fail.
After saving and exiting, we are good to go and update all files. To do that, just run the command below:

# /root/virt-who-update.sh

All .conf files under the /etc/virt-who.ddirectory will be updated every time you run this script and as a consequence on the next virt-who cycle, we will be able to see just one Hypervisors task without issue.

Note. You can add this script to the crontab and then this script will be run as a recurring task. This is suggested because the rhsm_username and rhsm_encrypted_password will be updated on the files every time you update and redeploy the virt-whoconfiguration via Satellite 6 GUI.

For more KB articles/solutions related to Virt-who and Virtual Datacenter (VDC) Subscriptions Issues, please refer to the Consolidated Troubleshooting Article for Virt-who and Virtual Datacenter (VDC) Subscriptions Issues

Root Cause

In some situations, the json produced by virt-who contains a control character not correctly handled by candlepin.

Diagnostic Steps

Checking the tasks we are able to see one task per configuration, generally, only one will succeed and all the rest will fail.


# hammer task list --search 'label ~ *Hypervisors' | head -n 10 
-|-

ID                                   | NAME | OWNER                | STARTED AT          | ENDED AT            | STATE   | RESULT  | TASK ACTION | TASK ERRORS                           
-|-|-|-|-|-|-|-|-
c5a0a59c-e232-43d6-a5da-d5d7589a3f29 |      | virt_who_reporter_1  | 2018/12/12 20:40:50 | 2018/12/12 20:41:04 | stopped | success | Hypervisors |                                       
e4042e97-8dfc-4828-9b57-8b913386f960 |      | virt_who_reporter_2  | 2018/12/12 19:22:10 | 2018/12/12 19:22:11 | stopped | warning | Hypervisors | undefined method `[]' for nil:NilClass
243a70a0-7e04-4725-a79f-836e9160b598 |      | virt_who_reporter_3  | 2018/12/12 19:22:04 | 2018/12/12 19:22:05 | stopped | warning | Hypervisors | undefined method `[]' for nil:NilClass
243a70a0-7e04-4725-a79f-836e91623515 |      | virt_who_reporter_4  | 2018/12/12 19:22:04 | 2018/12/12 19:22:05 | stopped | warning | Hypervisors | undefined method `[]' for nil:NilClass
243a70a0-7e04-4725-a79f-836e9160b588 |      | virt_who_reporter_5  | 2018/12/12 19:22:04 | 2018/12/12 19:22:05 | stopped | warning | Hypervisors | undefined method `[]' for nil:NilClass

On the /var/log/foreman/production.log file shows an output as below, one for each configuration:

2019-01-21T10:54:05 [E|bac|] undefined method `[]' for nil:NilClass (NoMethodError)
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.7.0.42/app/lib/actions/katello/host/hypervisors.rb:23:in `block in parse_hypervisors'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.7.0.42/app/lib/actions/katello/host/hypervisors.rb:22:in `each'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.7.0.42/app/lib/actions/katello/host/hypervisors.rb:22:in `parse_hypervisors'
...
SBR
Product(s)
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.