Skip to content

Commit

Permalink
Merge pull request ManageIQ#15470 from bdunne/set_default_server_role…
Browse files Browse the repository at this point in the history
…s_from_env

Set default server roles from env
  • Loading branch information
jrafanie committed Jun 29, 2017
2 parents 1ff9c94 + 6e84d92 commit 3376fa4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
13 changes: 6 additions & 7 deletions app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
7 changes: 6 additions & 1 deletion app/models/miq_server/role_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ def set_active_role_flags
save
end

def set_assigned_roles
def sync_assigned_roles
self.role = ::Settings.server.role
end

def ensure_default_roles
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

def deactivate_all_roles
deactivate_roles("*")
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +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(: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)

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
Expand Down

0 comments on commit 3376fa4

Please sign in to comment.