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

[Performance] MiqGroup.seed #15586

Merged
merged 2 commits into from
Aug 1, 2017
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
9 changes: 6 additions & 3 deletions app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ def self.seed
ldap_to_filters = filter_map_file.exist? ? YAML.load_file(filter_map_file) : {}
root_tenant = Tenant.root_tenant

groups = where(:group_type => SYSTEM_GROUP).includes(:entitlement).index_by(&:description)
roles = MiqUserRole.where("name like 'EvmRole-%'").index_by(&:name)

role_map.each_with_index do |(group_name, role_name), index|
group = find_by(:description => group_name) || new(:description => group_name)
user_role = MiqUserRole.find_by(:name => "EvmRole-#{role_name}")
group = groups[group_name] || new(:description => group_name)
user_role = roles["EvmRole-#{role_name}"]
if user_role.nil?
raise StandardError,
_("Unable to find user_role 'EvmRole-%{role_name}' for group '%{group_name}'") %
{:role_name => role_name, :group_name => group_name}
end
group.miq_user_role = user_role
group.miq_user_role = user_role if group.entitlement.try(:miq_user_role_id) != user_role.id
group.sequence = index + 1
group.entitlement.filters = ldap_to_filters[group_name]
group.group_type = SYSTEM_GROUP
Expand Down
3 changes: 2 additions & 1 deletion app/models/server_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class ServerRole < ApplicationRecord
validates_uniqueness_of :name

def self.seed
server_roles = all.index_by(&:name)
CSV.foreach(fixture_path, :headers => true, :skip_lines => /^#/).each do |csv_row|
action = csv_row.to_hash

rec = find_by(:name => action['name'])
rec = server_roles[action['name']]
if rec.nil?
_log.info("Creating Server Role [#{action['name']}]")
create(action)
Expand Down