diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb index 628a09c433..4568af9fce 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb @@ -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 diff --git a/apps/dashboard/test/fixtures/cmd_output/sacctmgr_show_accts_alt.txt b/apps/dashboard/test/fixtures/cmd_output/sacctmgr_show_accts_alt.txt new file mode 100644 index 0000000000..d61980e0cf --- /dev/null +++ b/apps/dashboard/test/fixtures/cmd_output/sacctmgr_show_accts_alt.txt @@ -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 diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index 914c4fa350..1b33ed5d4b 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -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