Bug #17562
closedhammer csv content-hosts --export" fails with "Error: undefined method `[]' for nil:NilClass"
Description
Description of problem:
If one or more hosts don't have a valid subscription then running "hammer csv content-hosts --export" to save the current assignment of subscriptions fails with error "Error: undefined method `clear' for nil:NilClass"
Version-Release number of selected component (if applicable):
tfm-rubygem-hammer_cli_import-0.11.2
Steps to Reproduce:
1. Ensure that at least one content host does not have a valid subscription
2. Run "hammer csv content-hosts --export --file content-hosts-export.csv --itemized-subscriptions"
This issue can not be reproduced by removing a subscription from an already entitled host.
This issue can be reproduced by creating a new host ("Hosts" --> "New host") so the host entry is created but the host hasn't registered yet (e.g. it's still being provisioned).
Actual results:
Error: undefined method `clear' for nil:NilClass
File content-hosts-export.csv only contains the first header line.
Expected results:
Hosts without subscriptions are skipped and output file is successfully created with correct subscription assignments for hosts with valid subscriptions.
Additional info:
Traceback from hammer:
[ INFO 2016-11-14 08:12:45 HammerCLICsv::CsvCommand] Called with options: {} [ INFO 2016-11-14 08:12:45 HammerCLICsv::CsvCommand::ContentHostsCommand] Called with options: {"option_threads"=>1, "option_export"=>true} Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions [ERROR 2016-11-14 08:12:46 Exception] Error: undefined method `[]' for nil:NilClass Error: undefined method `[]' for nil:NilClass [ERROR 2016-11-14 08:12:46 Exception] NoMethodError (undefined method `[]' for nil:NilClass): /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:374:in `block (2 levels) in iterate_hosts' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:369:in `each' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:369:in `block in iterate_hosts' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:363:in `each' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:363:in `iterate_hosts' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:74:in `export_all' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/content_hosts.rb:36:in `export' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/base.rb:85:in `block in execute' /opt/rh/rh-ruby22/root/usr/share/ruby/csv.rb:1048:in `instance' /opt/rh/rh-ruby22/root/usr/share/ruby/csv.rb:2320:in `CSV' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.1.0/lib/hammer_cli_csv/base.rb:84:in `execute' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.5.1.11/lib/hammer_cli/abstract.rb:22:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.5.1.11/lib/hammer_cli/abstract.rb:22:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/subcommand/execution.rb:11:in `execute' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:68:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.5.1.11/lib/hammer_cli/abstract.rb:22:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:133:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.5.1.11/bin/hammer:125:in `<top (required)>' /usr/bin/hammer:23:in `load' /usr/bin/hammer:23:in `<main>'