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

force utf-8 encoding #842

Merged
merged 5 commits into from
Jul 26, 2024
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
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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some issue with stubbing the output data here where we expect 3 of these characters instead of one. In any case, comment out the line line = line.encode('UTF-8', invalid: :replace, undef: :replace) in the slurm adapter and it does indeed fail with the same ArgumentError: invalid byte sequence in US-ASCII so the test case does indeed cover that.

end
end
end

describe "#status" do
Expand Down
Loading