Skip to content

Commit

Permalink
force utf-8 encoding (#842)
Browse files Browse the repository at this point in the history
Have Slurm force utf-8 encoding for some centers that have strange (ASCII) output.
  • Loading branch information
johrstrom authored Jul 26, 2024
1 parent dde2623 commit 9072be2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def get_jobs(id: "", owner: nil, attrs: nil)
# jobs << job
#
# assuming keys and values are same length! if not we have an error!
line = line.encode('UTF-8', invalid: :replace, undef: :replace)
values = line.chomp(RECORD_SEPARATOR).strip.split(UNIT_SEPARATOR)
jobs << Hash[fields.keys.zip(values)] unless values.empty?
end
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/output/slurm/non_utf8_job_name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ACCOUNTJOBIDEXEC_HOSTMIN_CPUSCPUSMIN_TMP_DISKNODESEND_TIMEDEPENDENCYFEATURESARRAY_JOB_IDGROUPGROUPOVER_SUBSCRIBESOCKETS_PER_NODEJOBIDCORES_PER_SOCKETNAMETHREADS_PER_CORECOMMENTARRAY_TASK_IDTIME_LIMITTIME_LEFTMIN_MEMORYTIMEREQ_NODESNODELISTCOMMANDCONTIGUOUSQOSPARTITIONPRIORITYREASONSTART_TIMESTSTATEUSERUIDRESERVATIONSUBMIT_TIMEWCKEYLICENSESEXC_NODESCORE_SPECNICESCHEDNODESS:C:TWORK_DIRTRES_PER_NODE
pas1960123p0220140012024-06-26T14:19:40(null)(null)29471683PAS06544067OK*29471683_9*� non-utf8*stdout=/tmp/job.output930:0026:554556M3:05p0220/tmp/job.sh0pitzer-defaultcondo-ccapp-backfill-serial100072289None2024-06-26T14:16:35CDCOMPLETEDannie.oakley23327(null)2024-06-26T14:01:13(null)(null)N/A0(null)*:*:*/tmpgres/gpfs:ess:1
23 changes: 23 additions & 0 deletions spec/job/adapters/slurm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,29 @@ def job_info(opts = {})
is_expected.to eql(job_info)
end
end

context "when job name has non utf8 characters" do

let(:squeue_args) {[
"squeue",
"--all",
"--states=all",
"--noconvert",
"-o",
"\u001E%a\u001F%A\u001F%B\u001F%c\u001F%C\u001F%d\u001F%D\u001F%e\u001F%E\u001F%f\u001F%F\u001F%g\u001F%G\u001F%h\u001F%H\u001F%i\u001F%I\u001F%j\u001F%J\u001F%k\u001F%K\u001F%l\u001F%L\u001F%m\u001F%M\u001F%n\u001F%N\u001F%o\u001F%O\u001F%q\u001F%P\u001F%Q\u001F%r\u001F%S\u001F%t\u001F%T\u001F%u\u001F%U\u001F%v\u001F%V\u001F%w\u001F%W\u001F%x\u001F%X\u001F%y\u001F%Y\u001F%z\u001F%Z\u001F%b",
"-j",
"123"
]}

it "correctly handles non utf8 characters" do
stdout = File.read('spec/fixtures/output/slurm/non_utf8_job_name.txt')
stdout.force_encoding(Encoding::ASCII)
allow(Open3).to receive(:capture3).with({}, *squeue_args, stdin_data: "").and_return([stdout, '', double("success?" => true)])
job = OodCore::Job::Factory.build_slurm({}).info('123')
expect(job.job_owner).to eq('annie.oakley')
expect(job.job_name).to eq('��� non-utf8')
end
end
end

describe "#status" do
Expand Down

0 comments on commit 9072be2

Please sign in to comment.