diff --git a/lib/ood_core/job/adapters/slurm.rb b/lib/ood_core/job/adapters/slurm.rb index fa7d6cc79..72f111210 100644 --- a/lib/ood_core/job/adapters/slurm.rb +++ b/lib/ood_core/job/adapters/slurm.rb @@ -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 diff --git a/spec/fixtures/output/slurm/non_utf8_job_name.txt b/spec/fixtures/output/slurm/non_utf8_job_name.txt new file mode 100644 index 000000000..53e4e5064 --- /dev/null +++ b/spec/fixtures/output/slurm/non_utf8_job_name.txt @@ -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 diff --git a/spec/job/adapters/slurm_spec.rb b/spec/job/adapters/slurm_spec.rb index 4bdde1e7b..d4c707fd9 100644 --- a/spec/job/adapters/slurm_spec.rb +++ b/spec/job/adapters/slurm_spec.rb @@ -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