Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default server roles from env #15470

Merged
merged 5 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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["DEFAULT_ROLES"]}) if role.blank? && ENV["DEFAULT_ROLES"].present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should environment variable names be prefixed with MIQ_ or MANAGEIQ_?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too concerned about the variable name since I hope it will be short lived, but I namespaced it to avoid conflict.

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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ 🔥


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