Bug 1368239

Summary: Azure provider fails EMS refresh
Product: Red Hat CloudForms Management Engine Reporter: Colin Arnott <carnott>
Component: ProvidersAssignee: Bill Wei <bilwei>
Status: CLOSED CURRENTRELEASE QA Contact: Jeff Teehan <jteehan>
Severity: high Docs Contact:
Priority: high    
Version: 5.6.0CC: benglish, bilwei, cpelland, dberger, gblomqui, jfrey, jhardy, obarenbo, pbuchan, simaishi
Target Milestone: GAKeywords: TestOnly, ZStream
Target Release: 5.7.0   
Hardware: x86_64   
OS: Linux   
Whiteboard: provider:azure:refresh
Fixed In Version: 5.7.0.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1370216 (view as bug list) Environment:
Last Closed: 2017-01-11 20:03:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: Azure Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1370216    

Description Colin Arnott 2016-08-18 19:02:03 UTC
Description of problem:
I can successfully create an Azure provider is successfully created, however during an EMS Refresh the refresh process encounters an error. Below is the error and beginning of the stack trace.


[----] E, [2016-08-17T15:19:26.230101 #60252:c7d990] ERROR -- : MIQ(ManageIQ::Providers::Azure::CloudManager::Refresher#refresh) EMS: [Azure], id: [1000000000011] Refresh failed
[----] E, [2016-08-17T15:19:26.267193 #60252:c7d990] ERROR -- : [NameError]: undefined local variable or method `resource' for #<ManageIQ::Providers::Azure::CloudManager::RefreshParser:0x00000005125a20>  Method:[rescue in block in refresh]
[----] E, [2016-08-17T15:19:26.267261 #60252:c7d990] ERROR -- : /var/www/miq/vmdb/app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb:131:in `transfer_selected_resource_properties'
/var/www/miq/vmdb/app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb:121:in `block in resource_already_collected?'
/var/www/miq/vmdb/app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb:116:in `each'
/var/www/miq/vmdb/app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb:116:in `each_with_index'
/var/www/miq/vmdb/app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb:116:in `resource_already_collected?'
<< CLIPPED >>


The code block being executed is:

      def transfer_selected_resource_properties(old_resource, new_resource)
        if new_resource.properties.provisioning_state != 'Succeeded'
          old_resource.properties.provisioning_state = resource.properties.provisioning_state
        end
        if new_resource.properties.try(:status_message)
          if old_resource.properties.try(:status_message)
            old_resource.properties.status_message += "\n#{new_resource.properties.status_message}"
          else
            old_resource.properties['status_message'] = new_resource.properties.status_message
          end
        end
      end


There is a resource that has a provisioning state that is not Successful and therefore CloudForms attempts to set properties of the old_resource variable from the variable named resource, but there is no variable named "resource" in the current scope.

Based on how the function is being called from the resource_already_collected? function (line 123) I believe the variable named resource should really be named new_resource.

Modified code block:

      def transfer_selected_resource_properties(old_resource, new_resource)
        if new_resource.properties.provisioning_state != 'Succeeded'
          old_resource.properties.provisioning_state = new_resource.properties.provisioning_state
        end
        if new_resource.properties.try(:status_message)
          if old_resource.properties.try(:status_message)
            old_resource.properties.status_message += "\n#{new_resource.properties.status_message}"
          else
            old_resource.properties['status_message'] = new_resource.properties.status_message
          end
        end
      end

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

How reproducible:
requires this Azure account

Comment 8 CFME Bot 2016-08-24 22:36:26 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/6b9d0716c90129a66757b4d9de4768d7a5ea50c1

commit 6b9d0716c90129a66757b4d9de4768d7a5ea50c1
Author:     Bill Wei <bilwei>
AuthorDate: Thu Aug 18 15:47:29 2016 -0400
Commit:     Bill Wei <bilwei>
CommitDate: Fri Aug 19 14:30:30 2016 -0400

    Fix a typo: resource -> new_resource
    Fix how to acculate resource status messages.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1368239

 .../azure/cloud_manager/refresh_parser.rb          | 31 +++++++++++++++-------
 1 file changed, 22 insertions(+), 9 deletions(-)

Comment 9 Jeff Teehan 2016-10-04 16:16:36 UTC
Test case is assumed for refresh errors.

Comment 10 Jeff Teehan 2016-10-11 19:30:03 UTC
Verified via code review.  It really isn't possible to create a bad resource on purpose in Azure.  So far I haven't seen any new refresh errors.