Bug 1282851

Summary: VMware provider refresh fails with 'divided by 0'
Product: Red Hat CloudForms Management Engine Reporter: ncatling
Component: ProvidersAssignee: Adam Grare <agrare>
Status: CLOSED ERRATA QA Contact: Nandini Chandra <nachandr>
Severity: high Docs Contact:
Priority: high    
Version: 5.4.0CC: cpelland, gblomqui, jfrey, jhardy, obarenbo, simaishi
Target Milestone: GAKeywords: ZStream
Target Release: 5.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 5.5.0.13 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1287731 (view as bug list) Environment:
Last Closed: 2015-12-08 13:47:59 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:
Bug Depends On:    
Bug Blocks: 1287731    
Attachments:
Description Flags
evm log snippet none

Description ncatling 2015-11-17 15:57:15 UTC
Created attachment 1095545 [details]
evm log snippet

Description of problem:

VMware provider refresh fails with:
ERROR -- : [ZeroDivisionError]: divided by 0  Method:[rescue in block in refresh]


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

CFME 5.4.3
vCenter 5.1


How reproducible:


Steps to Reproduce:
1. Add provider
2. Refresh
3. Error produced

Actual results:

Refresh fails with above error.


Expected results:

Refresh completes successfully


Additional info:

[----] E, [2015-11-17T13:00:24.280242 #11104:76fea8] ERROR -- : [ZeroDivisionError]: divided by 0  Method:[rescue in block in refresh]
[----] E, [2015-11-17T13:00:24.280697 #11104:76fea8] ERROR -- : /var/www/miq/vmdb/app/models/ems_refresh/parsers/vc.rb:830:in `/'
/var/www/miq/vmdb/app/models/ems_refresh/parsers/vc.rb:830:in `calculate_cores_and_sockets'

Comment 2 ncatling 2015-11-20 08:30:15 UTC
As the error suggests, the value of 'cores' is zero in this instance. This workaround was successful:

[root@localhost ~]# diff -u /var/www/miq/vmdb/app/models/ems_refresh/parsers/vc.rb*
--- /var/www/miq/vmdb/app/models/ems_refresh/parsers/vc.rb	2015-11-17 07:26:30.264593764 -0500
+++ /var/www/miq/vmdb/app/models/ems_refresh/parsers/vc.rb.back	2015-10-13 12:02:02.000000000 -0400
@@ -827,7 +827,6 @@
 
   def self.calculate_cores_and_sockets(total, cores)
     cores = (cores || 1).to_i
-    cores = 1 if cores == 0
     [cores, (total.to_i / cores)]
   end
   private_class_method :calculate_cores_and_sockets

Comment 4 CFME Bot 2015-12-02 19:44:16 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/74b219d8578f98d9c5fba4c4faef1676d7b1676c

commit 74b219d8578f98d9c5fba4c4faef1676d7b1676c
Author:     Adam Grare <agrare>
AuthorDate: Wed Nov 25 11:11:02 2015 -0500
Commit:     Adam Grare <agrare>
CommitDate: Wed Nov 25 11:51:18 2015 -0500

    Handle VMware VMs reportedly having 0 CPU Sockets
    
    VMware has been seen to return inventory stating that a VM has
    0 CPU sockets causing a ZeroDivisionError exception in the
    vmware refresh_parser.
    
    There is an existing check for numCoresPerSocket being nil,
    so expand on that to check for 0 as well.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1282851

 .../vmware/infra_manager/refresh_parser.rb         |  5 ++++-
 .../vmware/infra_manager/refresher_spec.rb         | 25 ++++++++++++++++++++++
 .../miq_vim_inventory/virtualMachinesByMor.yml     | 16 ++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

Comment 5 CFME Bot 2015-12-02 20:30:27 UTC
New commit detected on cfme/5.5.z:
https://code.engineering.redhat.com/gerrit/gitweb?p=cfme.git;a=commitdiff;h=efe07d18ba5e92025cfb2b40e1af5079a34081a6

commit efe07d18ba5e92025cfb2b40e1af5079a34081a6
Author:     Adam Grare <agrare>
AuthorDate: Wed Nov 25 11:11:02 2015 -0500
Commit:     Adam Grare <agrare>
CommitDate: Mon Nov 30 11:50:59 2015 -0500

    Handle VMware VMs reportedly having 0 CPU Sockets
    
    VMware has been seen to return inventory stating that a VM has
    0 CPU sockets causing a ZeroDivisionError exception in the
    vmware refresh_parser.
    
    There is an existing check for numCoresPerSocket being nil,
    so expand on that to check for 0 as well.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1282851

 .../vmware/infra_manager/refresh_parser.rb         |  5 ++++-
 .../vmware/infra_manager/refresher_spec.rb         | 25 ++++++++++++++++++++++
 .../miq_vim_inventory/virtualMachinesByMor.yml     | 16 ++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

Comment 6 Nandini Chandra 2015-12-03 22:42:06 UTC
Root cause was having a VC >= 5.0 and VMs on hosts <= 4.1.  The numCoresPerSocket property was added in 5.0 [1] so the VC just set that value to 0 for any hosts older than 5.0.

[1] https://www.vmware.com/support/developer/converter-sdk/conv55_apireference/vim.vm.VirtualHardware.html

Comment 7 Nandini Chandra 2015-12-04 00:11:47 UTC
Verified that the code is present in 5.5.0.13.Marking this as VERIFIED.

Comment 9 errata-xmlrpc 2015-12-08 13:47:59 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, 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-2015:2551