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

Add MiqServer#server_role_names= #19327

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 14 additions & 10 deletions app/models/miq_server/role_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,12 @@ def server_role_names
alias_method :my_roles, :server_role_names
alias_method :assigned_role_names, :server_role_names

def role
server_role_names.join(',')
end
alias_method :my_role, :role
alias_method :assigned_role, :role

def role=(val)
def server_role_names=(roles)
zone.lock do
val = val.to_s.strip.downcase
if val.blank?
if roles.blank?
server_roles.delete_all
else
desired = (val == "*" ? ServerRole.all_names : val.split(",").collect { |v| v.strip.downcase }.sort)
desired = (roles == "*" ? ServerRole.all_names : roles.map { |role| role.strip.downcase }.sort)
jrafanie marked this conversation as resolved.
Show resolved Hide resolved
current = server_role_names

# MiqServer#server_role_names may include database scoped roles, which are managed elsewhere,
Expand All @@ -165,6 +158,17 @@ def role=(val)
end
end

roles
end

def role
server_role_names.join(',')
jrafanie marked this conversation as resolved.
Show resolved Hide resolved
end
alias_method :my_role, :role
alias_method :assigned_role, :role

def role=(val)
self.server_role_names = val == "*" ? val : val.split(",")
role
end

Expand Down
27 changes: 27 additions & 0 deletions spec/models/miq_server/role_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@
end
end

context "server_role_names=" do
it "normal case" do
@miq_server.assign_role('ems_operations', 1)
expect(@miq_server.server_role_names).to eq(['ems_operations'])

desired = %w[event scheduler user_interface]
@miq_server.server_role_names = desired
expect(@miq_server.server_role_names).to eq(desired)
end

it "with a duplicate existing role" do
@miq_server.assign_role('ems_operations', 1)

desired = %w[ems_operations ems_operations scheduler]
@miq_server.server_role_names = desired
expect(@miq_server.server_role_names).to eq(%w[ems_operations scheduler])
end

it "with duplicate new roles" do
@miq_server.assign_role('event', 1)

desired = %w[ems_operations scheduler scheduler]
@miq_server.server_role_names = desired
expect(@miq_server.server_role_names).to eq(%w[ems_operations scheduler])
end
end

it "should assign role properly when requested" do
@roles = [['ems_operations', 1], ['event', 2], ['ems_metrics_coordinator', 1], ['scheduler', 1], ['reporting', 1]]
@roles.each do |role, priority|
Expand Down