Skip to content

Commit

Permalink
change the default value for auto_accounts when copying from template. (
Browse files Browse the repository at this point in the history
#3401)

Templates are based on the user that generated the template, so
when a project template is copied, auto_accounts potentially
needs to use a different default value because the user may not
have the same accounts as the user that generated the template.
  • Loading branch information
johrstrom authored Mar 19, 2024
1 parent 5a58482 commit fd67286
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@ def self.build_auto_accounts(opts = {})
end

static_opts = {
options: options
}.merge(opts.without(:options).to_h)
options: options,
value: default_value(opts, options)
}.merge(opts.without(:options, :value).to_h)

Attributes::AutoAccounts.new('auto_accounts', static_opts)
end

# try to find which default account value to use given
# all the input options and the actual users' account list.
def self.default_value(input_options, account_list)
input_value = input_options[:value].to_s
exclude_list = input_options[:exclude_options].to_a
available_accounts = account_list - exclude_list

if account_list.include?(input_value)
input_value
elsif !available_accounts.empty?
available_accounts.first
else
account_list.first
end
end
end

module Attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pzs1715|ruby|partition_a|ruby-default
pzs1714|ruby|partition_b|ruby-default
pzs2124|owens||owens-default,staff,phoenix,geophys,hal,gpt
pzs2118|owens||owens-default
pzs2117|owens||owens-default
pzs2010|owens||owens-default
pzs1715|owens||owens-default
pzs1714|owens||owens-default
pde1006|owens||owens-default
pas3051|owens||owens-default
pas2871|owens||owens-default
pas2754|owens||owens-default
pas2604|owens||owens-default
pzs2124|oakley||oakley-default
pzs2118|oakley||oakley-default
pzs2117|oakley||oakley-default
pzs2010|oakley||oakley-default
pzs1715|oakley||oakley-default
pzs1714|oakley||oakley-default
pde1006|oakley||oakley-default
pas3051|oakley||oakley-default
pas2871|oakley||oakley-default
38 changes: 38 additions & 0 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,42 @@ def add_bc_num_hours(project_id, script_id)
end
end
end

test 'submitting launchers from a template project works' do
Dir.mktmpdir do |dir|
# use different accounts than what the template was generated with
Open3
.stubs(:capture3)
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', stdin_data: '')
.returns([File.read('test/fixtures/cmd_output/sacctmgr_show_accts_alt.txt'), '', exit_success])

Project.stubs(:dataroot).returns(Pathname.new(dir))
Configuration.stubs(:project_template_dir).returns("#{Rails.root}/test/fixtures/projects")

visit(projects_root_path)
click_on(I18n.t('dashboard.jobs_create_template_project'))

select('Chemistry 5533', from: 'project_template')
click_on(I18n.t('dashboard.save'))

find('i.fa-atom').click
input_data = File.read('test/fixtures/projects/chemistry-5533/assignment_1.sh')

project_id = URI.parse(current_url).path.split('/').last

# note that we're using pzs1715 from sacctmgr_show_accts_alt.txt instead of psz0175
# from the template.
Open3
.stubs(:capture3)
.with({}, 'sbatch', '-A', 'pzs1715', '--export', 'NONE', '--parsable', '-M', 'owens',
stdin_data: input_data)
.returns(['job-id-123', '', exit_success])

OodCore::Job::Adapters::Slurm.any_instance
.stubs(:info).returns(OodCore::Job::Info.new(id: 'job-id-123', status: :running))

find("form[action='/projects/#{project_id}/launchers/8woi7ghd/submit']").click
assert_selector('.alert-success', text: 'job-id-123')
end
end
end

0 comments on commit fd67286

Please sign in to comment.