From eeabe1e4b7b1728757a51655258bdc1e40d92ef8 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 28 Jun 2017 17:46:35 -0400 Subject: [PATCH 1/5] Ensure the default roles are set for a server - If no roles exist (new server), try to source them from the environment or fall back to the default in Settings --- app/models/miq_server.rb | 11 +++++------ app/models/miq_server/role_management.rb | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/miq_server.rb b/app/models/miq_server.rb index 6d2fa3a75de..f7764cb922e 100644 --- a/app/models/miq_server.rb +++ b/app/models/miq_server.rb @@ -118,18 +118,17 @@ def start puts "** #{msg}" starting_server_record + ensure_default_roles ############################################################# # Server Role Assignment # - # 1. Deactivate all roles from last time - # 2. Set assigned roles from configuration - # 3. Assert database_owner role - based on vmdb being local - # 4. Role activation should happen inside monitor_servers - # 5. Synchronize active roles to monitor for role changes + # - Deactivate all roles from last time + # - Assert database_owner role - based on vmdb being local + # - Role activation should happen inside monitor_servers + # - Synchronize active roles to monitor for role changes ############################################################# deactivate_all_roles - set_assigned_roles set_database_owner_role(EvmDatabase.local?) monitor_servers monitor_server_roles if self.is_master? diff --git a/app/models/miq_server/role_management.rb b/app/models/miq_server/role_management.rb index d6a94c3069e..4f3ffee5667 100644 --- a/app/models/miq_server/role_management.rb +++ b/app/models/miq_server/role_management.rb @@ -54,6 +54,10 @@ def set_assigned_roles self.role = ::Settings.server.role end + def ensure_default_roles + self.role = (ENV["DEFAULT_ROLES"] || ::Settings.server.role) if role.blank? + end + def deactivate_all_roles deactivate_roles("*") end From cb805e3a0a640fdf94990dd56160a7abc982d436 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 28 Jun 2017 17:52:17 -0400 Subject: [PATCH 2/5] Rename set_assigned_roles to sync_assigned_roles --- app/models/miq_server.rb | 2 +- app/models/miq_server/role_management.rb | 2 +- app/models/miq_server/worker_management/monitor.rb | 2 +- spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/miq_server.rb b/app/models/miq_server.rb index f7764cb922e..f33206fa7df 100644 --- a/app/models/miq_server.rb +++ b/app/models/miq_server.rb @@ -63,7 +63,7 @@ def self.atStartup if roles != starting_roles # tell the server to pick up the role change server = MiqServer.my_server - server.set_assigned_roles + server.sync_assigned_roles server.sync_active_roles server.set_active_role_flags end diff --git a/app/models/miq_server/role_management.rb b/app/models/miq_server/role_management.rb index 4f3ffee5667..62033d7b3e2 100644 --- a/app/models/miq_server/role_management.rb +++ b/app/models/miq_server/role_management.rb @@ -50,7 +50,7 @@ def set_active_role_flags save end - def set_assigned_roles + def sync_assigned_roles self.role = ::Settings.server.role end diff --git a/app/models/miq_server/worker_management/monitor.rb b/app/models/miq_server/worker_management/monitor.rb index 10f44c057d2..2d5c1ba53f0 100644 --- a/app/models/miq_server/worker_management/monitor.rb +++ b/app/models/miq_server/worker_management/monitor.rb @@ -144,7 +144,7 @@ def sync_needed? end sync_config if config_changed - set_assigned_roles if config_changed + sync_assigned_roles if config_changed log_role_changes if roles_changed sync_active_roles if roles_changed set_active_role_flags if roles_changed diff --git a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb index 1b032a26153..f03cb6766da 100644 --- a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb @@ -52,7 +52,6 @@ context "'smartproxy' server and roles deactivated" do before(:each) do # Overwrite so that we set our own assigned roles instead of from config file - allow_any_instance_of(MiqServer).to receive(:set_assigned_roles).and_return(nil) allow_any_instance_of(MiqServer).to receive(:sync_workers).and_return(nil) allow_any_instance_of(MiqServer).to receive(:sync_log_level).and_return(nil) allow_any_instance_of(MiqServer).to receive(:wait_for_started_workers).and_return(nil) From 164bfc41df5790852c18eee0ddf0f1f3d4ceb729 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 28 Jun 2017 17:52:58 -0400 Subject: [PATCH 3/5] Delete a bunch of unnecessary allows --- .../job_proxy_dispatcher_vm_storage2proxies_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb index f03cb6766da..d2b224d21ae 100644 --- a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb @@ -51,16 +51,10 @@ context "'smartproxy' server and roles deactivated" do before(:each) do - # Overwrite so that we set our own assigned roles instead of from config file - allow_any_instance_of(MiqServer).to receive(:sync_workers).and_return(nil) - allow_any_instance_of(MiqServer).to receive(:sync_log_level).and_return(nil) - allow_any_instance_of(MiqServer).to receive(:wait_for_started_workers).and_return(nil) - server_roles = [FactoryGirl.create(:server_role, :name => "smartproxy", :max_concurrent => 0)] @server1.deactivate_all_roles - @server1.role = 'smartproxy' - allow_any_instance_of(Host).to receive_messages(:missing_credentials? => false) + @server1.role = 'smartproxy' end it "will have no roles active" do From a3e54049676b6b42506e6ed56df90142355ace10 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 29 Jun 2017 11:30:49 -0400 Subject: [PATCH 4/5] Save default roles to server settings so they are accurate in the UI --- app/models/miq_server/role_management.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/miq_server/role_management.rb b/app/models/miq_server/role_management.rb index 62033d7b3e2..b925ebf81c6 100644 --- a/app/models/miq_server/role_management.rb +++ b/app/models/miq_server/role_management.rb @@ -55,7 +55,8 @@ def sync_assigned_roles end def ensure_default_roles - self.role = (ENV["DEFAULT_ROLES"] || ::Settings.server.role) if role.blank? + MiqServer.my_server.add_settings_for_resource(:server => {:role => ENV["DEFAULT_ROLES"]}) if role.blank? && ENV["DEFAULT_ROLES"].present? + sync_assigned_roles end def deactivate_all_roles From 6e84d92428e107eef90842d791c3c4255c32fb4c Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 29 Jun 2017 13:47:51 -0400 Subject: [PATCH 5/5] Change ENV variable to MIQ_SERVER_DEFAULT_ROLES to avoid conflict --- app/models/miq_server/role_management.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_server/role_management.rb b/app/models/miq_server/role_management.rb index b925ebf81c6..43e6600e8f0 100644 --- a/app/models/miq_server/role_management.rb +++ b/app/models/miq_server/role_management.rb @@ -55,7 +55,7 @@ def sync_assigned_roles end def ensure_default_roles - MiqServer.my_server.add_settings_for_resource(:server => {:role => ENV["DEFAULT_ROLES"]}) if role.blank? && ENV["DEFAULT_ROLES"].present? + MiqServer.my_server.add_settings_for_resource(:server => {:role => ENV["MIQ_SERVER_DEFAULT_ROLES"]}) if role.blank? && ENV["MIQ_SERVER_DEFAULT_ROLES"].present? sync_assigned_roles end