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.
Created PR - https://github.com/ManageIQ/manageiq/pull/13100
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(-)