Bug 1307068 - Accessing the ems_events association of a RHEV Host object gives "NameError: undefined local variable or method `id' for #<EmsEvent::ActiveRecord_Relation:0x00000002ae3ba0>"
Accessing the ems_events association of a RHEV Host object gives "NameError: ...
Status: CLOSED ERRATA
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Automate (Show other bugs)
5.5.0
Unspecified Unspecified
high Severity medium
: GA
: 5.6.0
Assigned To: Drew Bomhof
Shveta
: ZStream
Depends On:
Blocks: 1309110
  Show dependency treegraph
 
Reported: 2016-02-12 10:43 EST by Peter McGowan
Modified: 2016-07-12 14:46 EDT (History)
8 users (show)

See Also:
Fixed In Version: 5.6.0.0
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1309110 (view as bug list)
Environment:
Last Closed: 2016-06-29 11:41:38 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Peter McGowan 2016-02-12 10:43:37 EST
Description of problem:
Accessing the ems_events association of a MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Host object gives "NameError: undefined local variable or method `id' for #<EmsEvent::ActiveRecord_Relation:0x00000002ae3ba0>"

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

How reproducible:
Every time

Steps to Reproduce:
1. in the rails console, define a $evm object:

irb(main):001:0> $evm = MiqAeMethodService::MiqAeService.new(MiqAeEngine::MiqAeWorkspaceRuntime.new)

2. Find a MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Host object:

irb(main):002:0> host = $evm.vmdb(:host).find_by_name('rhelh03.bit63.net')
  Host Inst Including Associations (0.3ms - 1rows)
=> #<MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Host:0x2ffb8a4 @object=#<ManageIQ::Providers::Redhat::InfraManager::Host id: ... "vms"]>

3. Check the associations of the host object:

irb(main):003:0> host_associations = host.associations
=> ["datacenter", "directories", "ems_cluster", "ems_events", "ems_folder", "ext_management_system", "files", "guest_applications", "hardware", "lans", "operating_system", "storages", "switches", "vms"]

4. Access the ems_event association:

irb(main):004:0> events = host.ems_events
  EmsEvent Inst Including Associations (129.5ms - 874rows)
NameError: undefined local variable or method `id' for #<EmsEvent::ActiveRecord_Relation:0x00000002ae3ba0>
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/relation/delegation.rb:136:in `method_missing'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/relation/delegation.rb:99:in `method_missing'
	from /var/www/miq/vmdb/app/models/host.rb:60:in `block in <class:Host>'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/builder/association.rb:65:in `instance_exec'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/builder/association.rb:65:in `block in initialize'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:191:in `instance_exec'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:191:in `eval_scope'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:155:in `block (2 levels) in add_constraints'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:154:in `each'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:141:in `each'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:39:in `scope'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:5:in `scope'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/association.rb:97:in `association_scope'
... 4 levels...
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/relation/delegation.rb:106:in `create'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/collection_association.rb:41:in `reader'
	from /opt/rh/cfme-gemset/gems/activerecord-4.2.5.1/lib/active_record/associations/builder/association.rb:115:in `ems_events'
	from /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:242:in `block in object_send'
	from /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:261:in `ar_method'
	from /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:271:in `ar_method'
	from /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:240:in `object_send'
	from /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_service_model_base.rb:93:in `block (2 levels) in expose'
	from (irb):6
	from /opt/rh/cfme-gemset/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
	from /opt/rh/cfme-gemset/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
	from /opt/rh/cfme-gemset/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
	from /opt/rh/cfme-gemset/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /opt/rh/cfme-gemset/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'irb(main):007:0>

Actual results:
As above

Expected results:
No error

Additional info:
Comment 2 Greg McCullough 2016-02-12 11:49:28 EST
This issue is reproducible outside of automate and appears to be effecting several objects.

Recreated in console with: 
Failing:
  Host.first.ems_events
  VmOrTemplate.first.ems_events
 
Working:
  ExtManagementSystem.first.ems_events
  EmsCluster.first.ems_events
  AvailabilityZone.first.ems_events

Will need to identify other models where this relationship/method is expose that might be failing.
Comment 4 CFME Bot 2016-02-16 16:00:46 EST
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/8ec98e54071cd826fcda035cd29155cf12c378fe

commit 8ec98e54071cd826fcda035cd29155cf12c378fe
Author:     Drew Bomhof <dbomhof@redhat.com>
AuthorDate: Mon Feb 15 17:22:24 2016 -0500
Commit:     Drew Bomhof <dbomhof@redhat.com>
CommitDate: Mon Feb 15 17:22:24 2016 -0500

    Pass in the owner object for the ems_events relation
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1307068

 app/models/host.rb                                            |  2 +-
 .../service_methods/miq_ae_service_host_spec.rb               | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 5 CFME Bot 2016-02-23 11:05:07 EST
New commit detected on cfme/5.5.z:
https://code.engineering.redhat.com/gerrit/gitweb?p=cfme.git;a=commitdiff;h=55c674617836ab91e26c95382779e8e79e0c2524

commit 55c674617836ab91e26c95382779e8e79e0c2524
Author:     Drew Bomhof <dbomhof@redhat.com>
AuthorDate: Mon Feb 15 17:22:24 2016 -0500
Commit:     Drew Bomhof <dbomhof@redhat.com>
CommitDate: Mon Feb 22 11:25:11 2016 -0500

    Pass in the owner object for the ems_events relation
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1307068

 app/models/host.rb                                            |  2 +-
 .../service_methods/miq_ae_service_host_spec.rb               | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 6 Shveta 2016-04-19 14:41:21 EDT
Fixed.
Verified in 5.6.0.1-beta2.20160413141124_e25ac0e 


======================================================
irb(main):031:0> host = $evm.vmdb(:host).find_by_name('qeblade29')
=> #<MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Host:0x2086004 @object=#<ManageIQ::Providers::Redhat::InfraManager::Host id: 4, name: "qeblade29", hostname: "10.16.4.50", ipaddress: "10.16.4.50", vmm_vendor: "redhat", vmm_version: nil, vmm_product: "rhev-h", vmm_buildnumber: nil, created_on: "2016-04-18 18:51:25", updated_on: "2016-04-19 15:38:00", guid: "8d729f82-0596-11e6-b7a3-fa163e03cdd3", ems_id: 2, user_assigned_os: nil, power_state: "on", smart: 1, settings: {}, last_perf_capture_on: nil, uid_ems: "23c4b162-eb2f-432d-938c-f990def6e9ac", connection_state: "connected", ssh_permit_root_login: "yes", ems_ref_obj: "--- \"/api/hosts/23c4b162-eb2f-432d-938c-f990def6e9...", admin_disabled: nil, service_tag: nil, asset_tag: nil, ipmi_address: "", mac_address: "", type: "ManageIQ::Providers::Redhat::InfraManager::Host", failover: nil, ems_ref: "/api/hosts/23c4b162-eb2f-432d-938c-f990def6e9ac", hyperthreading: nil, ems_cluster_id: 3, next_available_vnc_port: nil, hypervisor_hostname: nil, availability_zone_id: nil, maintenance: nil, maintenance_reason: nil>, @virtual_columns=["all_enabled_ports", "authentication_status", "cores_per_socket", "cpu_cores_per_socket", "cpu_total_cores", "cpu_usagemhz_rate_average_avg_over_time_period", "cpu_usagemhz_rate_average_high_over_time_period", "cpu_usagemhz_rate_average_low_over_time_period", "custom_1", "custom_2", "custom_3", "custom_4", "custom_5", "custom_6", "custom_7", "custom_8", "custom_9", "derived_memory_used_avg_over_time_period", "derived_memory_used_high_over_time_period", "derived_memory_used_low_over_time_period", "enabled_inbound_ports", "enabled_outbound_ports", "enabled_run_level_0_services", "enabled_run_level_1_services", "enabled_run_level_2_services", "enabled_run_level_3_services", "enabled_run_level_4_services", "enabled_run_level_5_services", "enabled_run_level_6_services", "enabled_tcp_inbound_ports", "enabled_tcp_outbound_ports", "enabled_udp_inbound_ports", "enabled_udp_outbound_ports", "first_drift_state_timestamp", "ipmi_enabled", "last_compliance_status", "last_compliance_timestamp", "last_drift_state_timestamp", "last_scan_on", "logical_cpus", "max_cpu_usage_rate_average_avg_over_time_period", "max_cpu_usage_rate_average_avg_over_time_period_without_overhead", "max_cpu_usage_rate_average_high_over_time_period", "max_cpu_usage_rate_average_high_over_time_period_without_overhead", "max_cpu_usage_rate_average_low_over_time_period", "max_cpu_usage_rate_average_low_over_time_period_without_overhead", "max_mem_usage_absolute_average_avg_over_time_period", "max_mem_usage_absolute_average_avg_over_time_period_without_overhead", "max_mem_usage_absolute_average_high_over_time_period", "max_mem_usage_absolute_average_high_over_time_period_without_overhead", "max_mem_usage_absolute_average_low_over_time_period", "max_mem_usage_absolute_average_low_over_time_period_without_overhead", "num_cpu", "os_image_name", "platform", "ram_size", "region_description", "region_number", "service_names", "total_vcpus", "v_annotation", "v_owning_cluster", "v_owning_datacenter", "v_owning_folder", "v_total_miq_templates", "v_total_storages", "v_total_vms", "vmm_vendor_display"], @associations=["datacenter", "directories", "ems_cluster", "ems_events", "ems_folder", "ext_management_system", "files", "guest_applications", "hardware", "lans", "operating_system", "storages", "switches", "vms"]>
irb(main):032:0> host_associations = host.associations
=> ["datacenter", "directories", "ems_cluster", "ems_events", "ems_folder", "ext_management_system", "files", "guest_applications", "hardware", "lans", "operating_system", "storages", "switches", "vms"]
irb(main):033:0> events = host.ems_events
=> [#<MiqAeServiceEmsEvent:0x8e3dac @object=#<EmsEvent id: 1442, event_type: "USER_STARTED_VM", message: "VM long-test_act-rhevm35-nutpefmgmr was started by...", timestamp: "2016-04-18 19:15:44", host_name: "qeblade29", host_id: 4, vm_name: nil, vm_location: nil, vm_or_template_id: nil, dest_host_name: nil, dest_host_id: nil, dest_vm_name: nil, dest_vm_location: nil, dest_vm_or_template_id: nil, source: "RHEVM", chain_id: nil, ems_id: 2, is_task: nil, full_data: {:id=>"2115652", :href=>"/api/events/2115652", :cluster=>{:id=>"adefc9e8-ef1a-4aa4-9852-f9aaebf11fbe", :href=>"/api/clusters/adefc9e8-ef1a-4aa4-9852-f9aaebf11fbe"}, :data_center=>{:id=>"b0f84640-951e-4537-8be2-ad810b01667f", :href=>"/api/datacenters/b0f84640-951e-4537-8be2-ad810b01667f"}, :host=>{:id=>"23c4b162-eb2f-432d-938c-f990def6e9ac", :href=>"/api/hosts/23c4b162-eb2f-432d-938c-f990def6e9ac"}, :template=>{:id=>"e763c7c8-81d0-42a5-b232-f674be951442", :href=>"/api/templates/e763c7c8-81d0-42a5-b232-f674be951442"}, :user=>{:id=>"fdfc627c-d875-11e0-90f0-83df133b58cc", :href=>"/api/users/fdfc627c-d875-11e0-90f0-83df133b58cc"}, :vm=>{:id=>"7a202a4f-69fe-4492-b1e1-4930bd4a9308", :href=>"/api/vms/7a202a4f-69fe-4492-b1e1-4930bd4a9308"}, :description=>"VM long-test_act-rhevm35-nutpefmgmr was started by admin (Host: qeblade29).", :severity=>"normal", :code=>153, :time=>2016-04-18 15:15:44 -0400, :name=>"USER_STARTED_VM"}, created_on: "2016-04-18 19:16:06", username: "admin@internal", ems_cluster_id: 3, ems_cluster_name: "iscsi_cluster", ems_cluster_uid: nil, dest_ems_cluster_id: nil, dest_
Comment 8 errata-xmlrpc 2016-06-29 11:41:38 EDT
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, 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-2016:1348

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