diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_output_directory.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_output_directory.rb index 24fc478321..1c19bf8e1c 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_output_directory.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_output_directory.rb @@ -16,12 +16,8 @@ class AutoOutputDirectory < Attribute # Value of auto_output_directory attribute # Defaults to first script path in the project # @return [String] attribute value - def error_path_value - "#{opts[:value]}/%j-output.log" || 'Default Output Directory' - end - - def output_path_value - "#{opts[:value]}/%j-error.log" || 'Default Output Directory' + def value + opts[:value] || 'Default Output Directory' end def widget @@ -32,13 +28,26 @@ def label(*) (opts[:label] || 'Output Directory').to_s end + def output_directory_hash + { output_path: output_path_value, error_path: error_path_value } + end + # Submission hash describing how to submit this attribute # @param fmt [String, nil] formatting of hash # @return [Hash] submission hash def submit(*) - { script: { output_path: output_path_value, error_path: error_path_value } } + opts[:value] ? { script: output_directory_hash } : nil end + private + + def error_path_value + "#{opts[:value]}/%j-error.log" + end + + def output_path_value + "#{opts[:value]}/%j-output.log" + end end end end diff --git a/apps/dashboard/test/lib/smart_attributes/auto_output_directory_test.rb b/apps/dashboard/test/lib/smart_attributes/auto_output_directory_test.rb new file mode 100644 index 0000000000..e4b1cbc103 --- /dev/null +++ b/apps/dashboard/test/lib/smart_attributes/auto_output_directory_test.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'smart_attributes' + +module SmartAttributes + class AutoOutputDirectoryTest < ActiveSupport::TestCase + def setup + stub_clusters + stub_user + stub_sacctmgr + end + + def dynamic_env + { + OOD_BC_DYNAMIC_JS: 'true' + } + end + + test 'correctly sets the value' do + with_modified_env(dynamic_env) do + options = { + value: 'output_extravaganza', + label: 'Output Directory' + } + attribute = SmartAttributes::AttributeFactory.build('auto_output_directory', options) + + assert_equal('output_extravaganza', attribute.value.to_s) + end + end + end +end diff --git a/apps/dashboard/test/system/project_manager_test.rb b/apps/dashboard/test/system/project_manager_test.rb index aadbf3d6b2..7cef744bae 100644 --- a/apps/dashboard/test/system/project_manager_test.rb +++ b/apps/dashboard/test/system/project_manager_test.rb @@ -456,6 +456,55 @@ def add_auto_environment_variable(project_id, script_id, save: true) end end + # super similar to test above, only it adds auto_output_directory + test 'submitting a script with output directory' do + Dir.mktmpdir do |dir| + project_id = setup_project(dir) + script_id = setup_script(project_id) + project_dir = File.join(dir, 'projects', project_id) + ondemand_dir = File.join(project_dir, '.ondemand') + add_account(project_id, script_id, save: false) + + click_on('Add new option') + select('Log Output Directory', from: 'add_new_field_select') + click_on(I18n.t('dashboard.add')) + fill_in('launcher_auto_output_directory', with: 'output_extravaganza') + click_on(I18n.t('dashboard.save')) + + launcher_path = project_launcher_path(project_id, script_id) + find("[href='#{launcher_path}'].btn-success").click + assert_selector('h1', text: 'the script title', count: 1) + + # assert defaults + assert_equal 'oakley', find('#launcher_auto_batch_clusters').value + assert_equal 'pzs0715', find('#launcher_auto_accounts').value + assert_equal "#{project_dir}/my_cool_script.sh", find('#launcher_auto_scripts').value + assert_nil YAML.safe_load(File.read("#{ondemand_dir}/job_log.yml")) + + select('owens', from: 'launcher_auto_batch_clusters') + select('pas2051', from: 'launcher_auto_accounts') + select('my_cooler_script.bash', from: 'launcher_auto_scripts') + + Open3 + .stubs(:capture3) + .with({}, 'sbatch', '-o', 'output_extravaganza/job-id-123-output.log', + '-e', 'output_extravaganza/job-id-123-error.log' '-A', 'pas2051', + '--export', 'NONE', '--parsable', '-M', 'owens', + stdin_data: "hostname\n") + .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)) + + click_on 'Launch' + assert_selector('.alert-success', text: 'job-id-123') + jobs = YAML.safe_load(File.read("#{ondemand_dir}/job_log.yml"), permitted_classes: [Time]) + + assert_equal(1, jobs.size) + assert_equal('job-id-123', jobs[0]['id']) + end + end + test 'submitting a script with auto attributes that fails' do Dir.mktmpdir do |dir| project_id = setup_project(dir) @@ -506,7 +555,8 @@ def add_auto_environment_variable(project_id, script_id, save: true) actual_new_options = page.all("##{new_field_id} option").map(&:value).to_set expected_new_options = [ 'bc_num_hours', 'auto_queues', 'bc_num_slots', 'auto_cores', - 'auto_accounts', 'auto_job_name', 'auto_environment_variable' + 'auto_accounts', 'auto_job_name', 'auto_environment_variable', + 'auto_output_directory' ].to_set assert_equal expected_new_options, actual_new_options end