Bug 1396330

Summary: Wrong zone set for appliances in global region
Product: Red Hat CloudForms Management Engine Reporter: tachoi
Component: ApplianceAssignee: Gregg Tanzillo <gtanzill>
Status: CLOSED CURRENTRELEASE QA Contact: Alex Newman <anewman>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.6.0CC: abellott, clasohm, fdewaley, gtanzill, jhardy, jocarter, obarenbo, simaishi
Target Milestone: GAKeywords: TestOnly, ZStream
Target Release: 5.8.0   
Hardware: All   
OS: All   
Whiteboard: zone:distributed
Fixed In Version: 5.8.0.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1413167 (view as bug list) Environment:
Last Closed: 2017-06-12 16:54:10 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: 1413167    

Comment 2 Gregg Tanzillo 2016-12-07 17:14:31 UTC
This approach seems correct. However, there is a cleaner way of ensuring that the zone instance is for the correct region. You can use the "in_my_region" built-in scope for this. The scope forces a clause to the query that limits the zone id to the range of the current region. ("zones"."id" BETWEEN $1 AND $2). Here's a diff showing the change:

diff --git a/app/models/miq_server/configuration_management.rb b/app/models/miq_server/configuration_management.rb
index 171db37..5ce994f 100644
--- a/app/models/miq_server/configuration_management.rb
+++ b/app/models/miq_server/configuration_management.rb
@@ -39,7 +39,7 @@ module MiqServer::ConfigurationManagement
     end
 
     unless data.zone.nil?
-      self.zone = Zone.find_by(:name => data.zone)
+      self.zone = Zone.in_my_region.find_by(:name => data.zone)
       save
     end
     update_capabilities
(

I'll make this change to the source code.

Comment 3 Gregg Tanzillo 2016-12-09 21:39:13 UTC
Created PR - https://github.com/ManageIQ/manageiq/pull/13100

Comment 4 CFME Bot 2016-12-21 19:51:10 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/0e19e850718479f0f6414eb365cf5d592e9385fb

commit 0e19e850718479f0f6414eb365cf5d592e9385fb
Author:     Gregg Tanzillo <gtanzill>
AuthorDate: Fri Dec 9 16:36:32 2016 -0500
Commit:     Gregg Tanzillo <gtanzill>
CommitDate: Fri Dec 9 17:37:15 2016 -0500

    Scope the zone to the server's region
    
    Ensure the zone is in the server's region when looking up and saving zone during config activation.
    In multi region environments, it's typical to have a zone in the global region that is named the same as one in a lower region.
    This change fixes a bug where a zone from a different region is saved as the server zone during config activation.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1396330

 app/models/miq_server/configuration_management.rb     |  2 +-
 .../miq_server/configuration_management_spec.rb       | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)