Bug 1504086 - Undefined method empty? for nil:NilClass during the generation of reports
Summary: Undefined method empty? for nil:NilClass during the generation of reports
Keywords:
Status: CLOSED DUPLICATE of bug 1501475
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Reporting
Version: 5.8.0
Hardware: All
OS: All
medium
medium
Target Milestone: GA
: cfme-future
Assignee: Yuri Rudman
QA Contact: Niyaz Akhtar Ansari
URL:
Whiteboard:
Depends On:
Blocks: 1480288
TreeView+ depends on / blocked
 
Reported: 2017-10-19 13:34 UTC by Felix Dewaleyne
Modified: 2021-06-10 13:18 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-23 15:39:45 UTC
Category: ---
Cloudforms Team: ---
Target Upstream Version:
Embargoed:
nansari: needinfo+


Attachments (Terms of Use)
trace from evm.log (11.92 KB, text/plain)
2017-10-19 13:34 UTC, Felix Dewaleyne
no flags Details

Description Felix Dewaleyne 2017-10-19 13:34:51 UTC
Created attachment 1340767 [details]
trace from evm.log

Description of problem:
[----] I, [2017-10-17T07:59:16.292550 #37599:9e7140]  INFO -- : MIQ(MiqTask#update_status) Task: [1000000005537] [Active] [Ok] [Generating report]
[----] E, [2017-10-17T07:59:17.414378 #37599:9e7140] ERROR -- : [NoMethodError]: undefined method `empty?' for nil:NilClass  Method:[rescue in _async_generate_table]
[----] E, [2017-10-17T07:59:17.414677 #37599:9e7140] ERROR -- : /var/www/miq/vmdb/app/models/miq_report/generator.rb:738:in `block (2 levels) in build_add_includes'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:737:in `each'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:737:in `block in build_add_includes'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:696:in `each'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:696:in `build_add_includes'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:668:in `build_reportable_data'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:396:in `block in build_table'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:395:in `collect'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:395:in `build_table'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:316:in `_generate_table'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:188:in `block in generate_table'
/var/www/miq/vmdb/app/models/user.rb:245:in `with_user'
/var/www/miq/vmdb/app/models/miq_report/generator.rb:188:in `generate_table'
/var/www/miq/vmdb/app/models/miq_report/generator/async.rb:96:in `_async_generate_table'
/var/www/miq/vmdb/app/models/miq_report/generator/async.rb:45:in `_async_generate_table'
/var/www/miq/vmdb/app/models/miq_queue.rb:347:in `block in deliver'
/opt/rh/rh-ruby23/root/usr/share/ruby/timeout.rb:91:in `block in timeout'
/opt/rh/rh-ruby23/root/usr/share/ruby/timeout.rb:33:in `block in catch'
/opt/rh/rh-ruby23/root/usr/share/ruby/timeout.rb:33:in `catch'
/opt/rh/rh-ruby23/root/usr/share/ruby/timeout.rb:33:in `catch'
/opt/rh/rh-ruby23/root/usr/share/ruby/timeout.rb:106:in `timeout'
/var/www/miq/vmdb/app/models/miq_queue.rb:343:in `deliver'

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

How reproducible:
depends on customer environment

Steps to Reproduce:
1.generate report on the customer's appliance
2.
3.

Actual results:
see attached trace

Expected results:
report is generated or exception handled to work around the NilClass

Additional info:
still gathering historical information regarding the environment and relation with the provider.

Comment 4 Felix Dewaleyne 2017-10-20 12:04:41 UTC
only happens with Base report: "Cloud Tenants"

Comment 7 Dave Johnson 2017-10-24 15:22:12 UTC
Niyaz, can you reproduce this?

Comment 8 Niyaz Akhtar Ansari 2017-10-25 08:10:58 UTC
Dave, I am also not able to reproduce this issue.

Comment 9 Felix Dewaleyne 2017-10-31 11:12:38 UTC
is there anything I can provide from the customer to continue on this issue, I think it depends highly on the customer environment.

Comment 10 Felix Dewaleyne 2017-11-01 11:51:41 UTC
the customer shared more detailed steps with me 

1º Assign tag to VM, for example, departament tag,we have used "Discipline". 
2º Asign tag to Tenant, for example, departament tag, we have used "Discipline".
3º Create report with base report "VMs and Instances" and the next fields: Name Departament tag.
4º Create report with base report "Cloud Tenant" and the next fields: Name Departament tag.
5º Generate the two reports.

if I need to push for the database let me know

Comment 14 Dave Johnson 2017-11-06 05:04:46 UTC
Niyaz, please retest per comment 13.  If you need help restoring, please reach out to Luke.

Comment 20 Ian Tewksbury 2018-02-16 13:53:10 UTC
I am having this issue as well. A reboot of the services or the appliances does not fix the issue.

Comment 21 Ian Tewksbury 2018-02-16 13:53:47 UTC
I am on 5.8.2.3

Comment 22 Ian Tewksbury 2018-02-16 15:01:55 UTC
So I added some debug logging to /var/www/miq/vmdb/app/modles/miq_report/generator.rb

```
  def build_add_includes(data_records, entry, includes, parent_association)
    _log.info("HERE 0 { data_records => #{data_records}, entry => #{entry}, includes => #{includes}, parent_association => #{parent_association} }")
    include_has_options = includes.kind_of?(Hash)
    associations = include_has_options ? includes.keys : Array(includes)

    associations.each do |association|
      existing_records = data_records.dup
      data_records = []
      full_path = get_full_path(parent_association, association)
      if include_has_options
        assoc_options = includes[association].merge(:qualify_attribute_names => full_path,
                                                    :only                    => includes[association]["columns"])
      else
        assoc_options = {:qualify_attribute_names => full_path, :only => includes[association]["columns"]}
      end

      temp = (association == "managed")
      _log.info("HERE 0.5 { association => #{association}, association.class => #{association.class}, (association == \"managed\") => #{temp} }")

      if association == "categories" || association == "managed"
        _log.info("HERE 1")
        association_objects = []
        assochash = {}
        @descriptions_by_tag_id ||= Classification.where("parent_id != 0").each_with_object({}) do |c, h|
          h[c.tag_id] = c.description
        end

        assoc_options[:only].each do|c|
          entarr = []
          entry[:obj].tags.each do |t|
            next unless t.name.starts_with?("/managed/#{c}/")
            next unless @descriptions_by_tag_id.key?(t.id)
            entarr << @descriptions_by_tag_id[t.id]
          end
          assochash[full_path + "." + c] = entarr unless entarr.empty?
        end
        # join the the category data together
        longest = 0
        idx = 0
        assochash.each_key { |k| longest = assochash[k].length if assochash[k].length > longest }
        longest.times do
          nh = {}
          assochash.each_key { |k| nh[k] = assochash[k][idx].nil? ? assochash[k].last : assochash[k][idx] }
          association_objects.push(nh)
          idx += 1
        end
      else
        _log.info("HERE 2 'association => #{association}'")
        association_objects = entry[association.to_sym]
      end

      existing_records.each do |existing_record|
        if association_objects.empty?
          data_records << existing_record
        else
          association_objects.each do |obj|
            unless association == "categories" || association == "managed"
              association_records = build_reportable_data(obj, assoc_options, full_path)
            else
              association_records = [obj]
            end
            association_records.each do |assoc_record|
              data_records << existing_record.merge(assoc_record)
            end
          end
        end
      end
    end
    data_records
  end

```

and then the log output i get is:

```
[----] I, [2018-02-16T09:52:18.591488 #119274:1061138]  INFO -- : MIQ(MiqReport#build_add_includes) HERE 0 { data_records => [{"name"=>"rhel6_64_apache", "id"=>30000000002928}], entry => {:obj=>#<ManageIQ::Providers::Vmware::InfraManager::Vm id: 30000000002928, vendor: "vmware", format: nil, version: nil, name: "rhel6_64_apache", description: nil, location: "rhel6_64_apache_1/rhel6_64_apache.vmx", config_xml: nil, autostart: nil, host_id: nil, last_sync_on: nil, created_on: "2017-06-13 14:38:40", updated_on: "2017-06-15 14:52:13", storage_id: 30000000000170, guid: "fe203514-5045-11e7-a4a0-00505695ad67", ems_id: 30000000000001, last_scan_on: nil, last_scan_attempt_on: nil, uid_ems: "4215024c-e66d-202c-52c2-b436bb689210", retires_on: nil, retired: nil, boot_time: nil, tools_status: "toolsNotRunning", standby_action: "checkpoint", power_state: "off", state_changed_on: "2017-06-13 14:38:40", previous_state: nil, connection_state: "connected", last_perf_capture_on: nil, registered: nil, busy: nil, smart: nil, memory_reserve: 0, memory_reserve_expand: false, memory_limit: -1, memory_shares: 20480, memory_shares_level: "normal", cpu_reserve: 0, cpu_reserve_expand: false, cpu_limit: -1, cpu_shares: 2000, cpu_shares_level: "normal", cpu_affinity: nil, ems_created_on: nil, template: false, evm_owner_id: nil, ems_ref_obj: "--- !ruby/string:VimString\nstr: vm-153465\nxsiType:...", miq_group_id: 30000000000001, linked_clone: true, fault_tolerance: false, type: "ManageIQ::Providers::Vmware::InfraManager::Vm", ems_ref: "vm-153465", ems_cluster_id: nil, retirement_warn: nil, retirement_last_warn: nil, vnc_port: nil, flavor_id: nil, availability_zone_id: nil, cloud: false, retirement_state: nil, cloud_network_id: nil, cloud_subnet_id: nil, cloud_tenant_id: nil, raw_power_state: "poweredOff", publicly_available: nil, orchestration_stack_id: nil, retirement_requester: nil, tenant_id: 30000000000001, resource_group_id: nil, deprecated: nil, storage_profile_id: nil, cpu_hot_add_enabled: nil, cpu_hot_remove_enabled: nil, memory_hot_add_enabled: nil, memory_hot_add_limit: nil, memory_hot_add_increment: nil>}, includes => {:managed=>{:columns=>["cbp_managing_entity"]}}, parent_association =>  }
[----] I, [2018-02-16T09:52:18.591674 #119274:1061138]  INFO -- : MIQ(MiqReport#build_add_includes) HERE 0.5 { association => managed, association.class => Symbol, (association == "managed") => false }
[----] I, [2018-02-16T09:52:18.591729 #119274:1061138]  INFO -- : MIQ(MiqReport#build_add_includes) HERE 2 'association => managed'
[----] E, [2018-02-16T09:52:18.593213 #119274:1061138] ERROR -- : [NoMethodError]: undefined method `empty?' for nil:NilClass  Method:[rescue in _async_generate_table]
[----] E, [2018-02-16T09:52:18.593375 #119274:1061138] ERROR -- : /var/www/miq/vmdb/app/models/miq_report/generator.rb:744:in `block (2 levels) in build_add_includes'
```


The issue is that association is a symbol `:managed` but the code is assuming that `association` is a string at least in these places:
* https://github.com/ManageIQ/manageiq/blob/master/app/models/miq_report/generator.rb#L707
* https://github.com/ManageIQ/manageiq/blob/master/app/models/miq_report/generator.rb#L742

Comment 23 Ian Tewksbury 2018-02-16 15:04:40 UTC
It goes even further in that https://github.com/ManageIQ/manageiq/blob/master/app/models/miq_report/generator.rb#L702 assumes that the included association has a `"comlumns"` key but in at least my case I have a `:columns` key.

Comment 24 Ian Tewksbury 2018-02-16 15:21:07 UTC
Alright, so I figured out the issue, at least for our case.

Steps:

1. create a report in CloudForms Region 10 using a tag as one of the columns
2. export that report
3. import the report into CloudForms Region 20
4. attempt to run that report

Actual:

The error as described in this bug.
If you edit the report then you will see the loaded column is all wierd. In my case the tag name was "Managing Entity". In region 10 that column in the report shows up as "My Company Tags: Managing Entity" but in region 20 when the report is imported it shows up as "Managing entity".

Then if I hack the generator.rb to deal with symbols instead of strings the report will run but with no data for that column.

If I then edit the report to remove "Managing entity" and add back in "My Company Tags: Managing Entity" the report runs without issue.

Other:

Both region 10 and region 20 have the same company name.


Issue:

Basically it would seem you can't export reports with tags and import them into another region even if the tags exist and the company name is the same.

Expected:

even if company names don't line up as long as the tag exists in both regions with the same name then the report import/export should work without issue.

Comment 25 Yuri Rudman 2018-02-21 13:10:49 UTC
Ian, it looks like issues you describing  have the same root as in https://bugzilla.redhat.com/show_bug.cgi?id=1501475 (with converting to symbols during import).
It was resolved in https://github.com/ManageIQ/manageiq/pull/16143

I re-tested on 5.9 (it should be the same on 5.8): after applying changes in https://github.com/ManageIQ/manageiq/pull/16143 - there is no issue when importing reports with tag column in different region

Comment 26 Ian Tewksbury 2018-02-21 13:19:27 UTC
@Yuri,

Is version of CFME shipped yet that has https://github.com/ManageIQ/manageiq/pull/16143?? I coudn't tell from PR which version of 5.8 has the fix.

Blue skies,
Ian

Comment 27 Yuri Rudman 2018-02-21 13:25:58 UTC
corresponding BZ for 5.8: https://bugzilla.redhat.com/show_bug.cgi?id=1501475,
fix should be in 5.8.3

Comment 28 Yuri Rudman 2018-02-23 15:39:45 UTC
Closing this BZ as duplicate of #1501475

*** This bug has been marked as a duplicate of bug 1501475 ***


Note You need to log in before you can comment on or make changes to this bug.