-
Notifications
You must be signed in to change notification settings - Fork 327
/
pbs_soft_walltime.py
1062 lines (859 loc) · 39.2 KB
/
pbs_soft_walltime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding: utf-8
# Copyright (C) 1994-2019 Altair Engineering, Inc.
# For more information, contact Altair at www.altair.com.
#
# This file is part of the PBS Professional ("PBS Pro") software.
#
# Open Source License Information:
#
# PBS Pro is free software. You can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Commercial License Information:
#
# For a copy of the commercial license terms and conditions,
# go to: (http://www.pbspro.com/UserArea/agreement.html)
# or contact the Altair Legal Department.
#
# Altair’s dual-license business model allows companies, individuals, and
# organizations to create proprietary derivative works of PBS Pro and
# distribute them - whether embedded or bundled with other software -
# under a commercial license agreement.
#
# Use of Altair’s trademarks, including but not limited to "PBS™",
# "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
# trademark licensing policies.
from tests.functional import *
def cvt_duration(duration):
"""
convert string form of a duration (HH:MM:SS) into seconds
"""
h = 0
m = 0
sp = duration.split(':')
if len(sp) == 3:
h = int(sp[0])
m = int(sp[1])
s = int(sp[2])
elif len(sp) == 2:
m = int(sp[0])
s = int(sp[1])
else:
s = int(sp[0])
return h * 3600 + m * 60 + s
class TestSoftWalltime(TestFunctional):
"""
Test that the soft_walltime resource is being used properly and
being extended properly when exceeded
"""
def setUp(self):
TestFunctional.setUp(self)
self.server.manager(
MGR_CMD_UNSET, SERVER, 'Resources_default.soft_walltime')
# Delete operators if added
self.server.manager(MGR_CMD_UNSET, SERVER, 'operators')
def stat_job(self, job):
"""
stat a job for its estimated.start_time and soft_walltime or walltime
:param job: Job to stat
:type job: string
"""
a = ['estimated.start_time', 'Resource_List.soft_walltime',
'Resource_List.walltime']
# If we're in CLI mode, qstat returns times in a human readable format
# We need to turn it back into an epoch. API mode will be the epoch.
Jstat = self.server.status(JOB, id=job, attrib=a)
wt = 0
if self.server.get_op_mode() == PTL_CLI:
strp = time.strptime(Jstat[0]['estimated.start_time'], '%c')
est = int(time.mktime(strp))
if 'Resource_List.soft_walltime' in Jstat[0]:
wt = cvt_duration(Jstat[0]['Resource_List.soft_walltime'])
elif 'Resource_List.walltime' in Jstat[0]:
wt = cvt_duration(Jstat[0]['Resource_List.walltime'])
else:
est = int(Jstat[0]['estimated.start_time'])
if 'Resource_List.soft_walltime' in Jstat[0]:
wt = int(Jstat[0]['Resource_List.soft_walltime'])
elif 'Resource_List.walltime' in RN_stat[0]:
wt = int(Jstat[0]['Resource_List.walltime'])
return (est, wt)
def compare_estimates(self, baseline_job, jobs):
"""
Check if estimated start times are correct
:param baseline_job: initial top job to base times off of
:type baseline_job: string (job id)
:param jobs: calendared jobs
:type jobs: list of strings (job ids)
"""
est, wt = self.stat_job(baseline_job)
for j in jobs:
est2, wt2 = self.stat_job(j)
self.assertEquals(est + wt, est2)
est = est2
wt = wt2
def setup_holidays(self, prime_offset, nonprime_offset):
"""
Set up the holidays file for test execution. This function will
first remove all entries in the holidays file and then add a year,
prime, and nonprime for all days. The prime and nonprime entries
will be offsets from the current time.
This all is necessary because there are some holidays set by default.
The test should be able to be run on any day of the year. If it is
run on one of these holidays, it will be nonprime time only.
"""
# Delete all entries in the holidays file
self.scheduler.holidays_delete_entry('a')
lt = time.localtime(time.time())
self.scheduler.holidays_set_year(str(lt[0]))
now = int(time.time())
prime = time.strftime('%H%M', time.localtime(now + prime_offset))
nonprime = time.strftime('%H%M', time.localtime(now + nonprime_offset))
# set prime-time and nonprime-time for all days
self.scheduler.holidays_set_day('weekday', prime, nonprime)
self.scheduler.holidays_set_day('saturday', prime, nonprime)
self.scheduler.holidays_set_day('sunday', prime, nonprime)
def test_soft_walltime_perms(self):
"""
Test to see if soft_walltime can't be submitted with a job or
altered by a normal user or operator
"""
J = Job(TEST_USER, attrs={'Resource_List.soft_walltime': 10})
msg = 'Cannot set attribute, read only or insufficient permission'
jid = None
try:
jid = self.server.submit(J)
except PbsSubmitError as e:
self.assertTrue(msg in e.msg[0])
self.assertEquals(jid, None)
J = Job(TEST_USER)
jid = self.server.submit(J)
try:
self.server.alterjob(jid, {'Resource_List.soft_walltime': 10},
runas=TEST_USER)
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.soft_walltime',
op=UNSET, id=jid)
operator = str(OPER_USER) + '@*'
self.server.manager(MGR_CMD_SET, SERVER,
{'operators': (INCR, operator)},
sudo=True)
try:
self.server.alterjob(jid, {'Resource_List.soft_walltime': 10},
runas=OPER_USER)
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.soft_walltime',
op=UNSET, id=jid)
def test_soft_walltime_STF(self):
"""
Test that STF jobs can't have soft_walltime
"""
msg = 'soft_walltime is not supported with Shrink to Fit jobs'
J = Job(attrs={'Resource_List.min_walltime': 120, ATTR_h: None})
jid = self.server.submit(J)
try:
self.server.alterjob(jid, {'Resource_List.soft_walltime': 10})
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.soft_walltime',
op=UNSET, id=jid)
J = Job(TEST_USER, attrs={ATTR_h: None})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 10})
try:
self.server.alterjob(jid, {'Resource_List.min_walltime': 120})
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.min_walltime',
op=UNSET, id=jid)
J = Job(TEST_USER, attrs={ATTR_h: None})
jid = self.server.submit(J)
a = {'Resource_List.soft_walltime': 10,
'Resource_List.min_walltime': 120}
try:
self.server.alterjob(jid, a)
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
al = ['Resource_List.min_walltime', 'Resource_List.soft_walltime']
self.server.expect(JOB, al, op=UNSET, id=jid)
def test_soft_greater_hard(self):
"""
Test that a job's soft_walltime can't be greater than its hard walltime
"""
msg = 'Illegal attribute or resource value'
J = Job(TEST_USER, attrs={'Resource_List.walltime': 120, ATTR_h: None})
jid = self.server.submit(J)
try:
self.server.alterjob(jid, {'Resource_List.soft_walltime': 240})
except PbsAlterError as e:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.soft_walltime',
op=UNSET, id=jid)
J = Job(TEST_USER, {ATTR_h: None})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 240})
try:
self.server.alterjob(jid, {'Resource_List.walltime': 120})
except PbsAlterError:
self.assertTrue(msg in e.msg[0])
self.server.expect(JOB, 'Resource_List.walltime', op=UNSET, id=jid)
J = Job(TEST_USER, {ATTR_h: None})
jid = self.server.submit(J)
try:
self.server.alterjob(jid, {'Resource_List.walltime': 120,
'Resource_List.soft_walltime': 240})
except PbsAlterError:
self.assertTrue(msg in e.msg[0])
al = ['Resource_List.walltime', 'Resource_List.soft_walltime']
self.server.expect(JOB, al, op=UNSET, id=jid)
def test_direct_set_soft_walltime(self):
"""
Test setting soft_walltime directly
"""
hook_body = \
"""import pbs
e = pbs.event()
j = e.job
j.Resource_List["soft_walltime"] = \
pbs.duration(j.Resource_List["set_soft_walltime"])
e.accept()
"""
self.server.manager(MGR_CMD_CREATE, RSC, {'type': 'long'},
id='set_soft_walltime')
a = {'event': 'queuejob', 'enabled': 'True'}
self.server.create_import_hook("que", a, hook_body)
J = Job(TEST_USER, attrs={'Resource_List.set_soft_walltime': 5})
jid = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 5}, id=jid)
def test_soft_walltime_extend(self):
"""
Test to see that soft_walltime is extended properly
"""
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 6})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
time.sleep(7)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 6}, op=GT, id=jid)
# Get the current soft_walltime
jstat = self.server.status(JOB, id=jid,
attrib=['estimated.soft_walltime'])
est_soft_walltime = jstat[0]['estimated.soft_walltime']
time.sleep(7)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
# Check if soft_walltime extended
self.server.expect(JOB, {'estimated.soft_walltime':
est_soft_walltime}, op=GT, id=jid)
def test_soft_walltime_extend_hook(self):
"""
Test to see that soft_walltime is extended properly when submitted
through a queue job hook
"""
hook_body = \
"""import pbs
e = pbs.event()
e.job.Resource_List["soft_walltime"] = pbs.duration(5)
e.accept()
"""
a = {'event': 'queuejob', 'enabled': 'True'}
self.server.create_import_hook("que", a, hook_body)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 5}, id=jid)
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
time.sleep(6)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 5}, op=GT, id=jid)
# Get the current soft_walltime
jstat = self.server.status(JOB, id=jid,
attrib=['estimated.soft_walltime'])
est_soft_walltime = jstat[0]['estimated.soft_walltime']
time.sleep(6)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime':
est_soft_walltime}, op=GT, id=jid)
def test_soft_then_hard(self):
"""
Test to see if a job has both a soft and a hard walltime, that
the job's soft_walltime is not extended past its hard walltime.
It should first extend once and then extend to its hard walltime
"""
self.server.manager(MGR_CMD_SET, SERVER,
{'job_history_enable': 'True'})
J = Job(TEST_USER,
attrs={'Resource_List.ncpus': 1, 'Resource_List.walltime': 16})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 6})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
time.sleep(7)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 6}, op=GT, id=jid)
time.sleep(7)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 16},
offset=4, extend='x', id=jid)
self.server.expect(JOB, 'queue', op=UNSET, id=jid)
def test_soft_before_dedicated(self):
"""
Make sure that if a job's soft_walltime won't complete before
dedicated time, the job does not start
"""
now = int(time.time())
self.scheduler.add_dedicated_time(start=now + 60, end=now + 2500)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 90})
comment = 'Not Running: Job would cross dedicated time boundary'
self.server.expect(JOB, {'comment': comment})
def test_soft_extend_dedicated(self):
"""
Have a job with a soft_walltime extend into dedicated time and see
the job continue running like normal
"""
# Dedicated time is in the granularity of minutes. This can't be set
# any shorter without making it dedicated time right now.
now = int(time.time())
self.scheduler.add_dedicated_time(start=now + 70, end=now + 180)
J = Job(TEST_USER, {'Resource_List.walltime': 180})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
self.logger.info("Waiting until dedicated time starts")
time.sleep(61)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 65},
op=GE, id=jid)
def test_soft_before_prime(self):
"""
Make sure that if a job's soft_walltime won't complete before
prime boundry, the job does not start
"""
self.scheduler.set_sched_config({'backfill_prime': 'True'})
self.setup_holidays(3600, 7200)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5400})
comment = 'Not Running: Job will cross into primetime'
self.server.expect(JOB, {'comment': comment}, id=jid)
def test_soft_backfill_prime(self):
"""
Test if soft_walltime is used to see if a job can run before
the next prime boundry
"""
self.scheduler.set_sched_config({'backfill_prime': 'True'})
self.setup_holidays(60, 3600)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'False'})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5})
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
self.logger.info("Waiting until prime time starts.")
time.sleep(61)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 65}, op=GE,
id=jid)
def test_resv_conf_soft(self):
"""
Test that there is no change in the reservation behavior with
soft_walltime set on jobs with no hard walltime set
"""
a = {'resources_available.ncpus': 4}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
now = int(time.time())
J = Job(TEST_USER, attrs={'Resource_List.ncpus': 4})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
a = {'Resource_List.ncpus': 1, 'reserve_start': now + 10,
'reserve_end': now + 130}
R = Reservation(TEST_USER, attrs=a)
rid = self.server.submit(R)
self.server.log_match(rid + ';reservation deleted', max_attempts=5)
def test_resv_conf_soft_with_hard(self):
"""
Test that there is no change in the reservation behavior with
soft_walltime set on jobs with a hard walltime set. The soft_walltime
should be ignored and only the hard walltime should be used.
"""
a = {'resources_available.ncpus': 4}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
now = int(time.time())
J = Job(TEST_USER, attrs={'Resource_List.ncpus': 4,
'Resource_List.walltime': 120})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
a = {'Resource_List.ncpus': 1, 'reserve_start': now + 60,
'reserve_end': now + 250}
R = Reservation(TEST_USER, attrs=a)
rid = self.server.submit(R)
self.server.log_match(rid + ';reservation deleted', max_attempts=5)
def test_resv_job_soft(self):
"""
Test to see that a job with a soft walltime which would "end" before
a reservation starts does not start. It would interfere with the
reservation.
"""
a = {'resources_available.ncpus': 4}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
now = int(time.time())
a = {'Resource_List.ncpus': 4, 'reserve_start': now + 120,
'reserve_end': now + 240}
R = Reservation(TEST_USER, attrs=a)
rid = self.server.submit(R)
self.server.expect(RESV,
{'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')},
id=rid)
a = {'Resource_List.ncpus': 4, ATTR_h: None}
J = Job(TEST_USER, attrs=a)
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 60})
self.server.rlsjob(jid, 'u')
a = {ATTR_state: 'Q', ATTR_comment:
'Not Running: Job would conflict with reservation or top job'}
self.server.expect(JOB, a, id=jid, attrop=PTL_AND)
def test_resv_job_soft_hard(self):
"""
Test to see that a job with a soft walltime and a hard walltime does
not interfere with a confirmed reservation. The soft walltime would
have the job "end" before the reservation starts, but the hard
walltime would not.
"""
a = {'resources_available.ncpus': 4}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
now = int(time.time())
a = {'Resource_List.ncpus': 4, 'reserve_start': now + 120,
'reserve_end': now + 240}
R = Reservation(TEST_USER, attrs=a)
rid = self.server.submit(R)
self.server.expect(RESV,
{'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')},
id=rid)
a = {'Resource_List.ncpus': 4,
'Resource_List.walltime': 150, ATTR_h: None}
J = Job(TEST_USER, attrs=a)
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 60})
self.server.rlsjob(jid, 'u')
a = {ATTR_state: 'Q', ATTR_comment:
'Not Running: Job would conflict with reservation or top job'}
self.server.expect(JOB, a, id=jid, attrop=PTL_AND)
def test_topjob(self):
"""
Test that soft_walltime is used for calendaring of topjobs
Submit 3 jobs:
Job1 has a soft_walltime=150 and runs now
Job2 has a soft_walltime=150 and gets added to the calendar at now+150
Job3 has a soft_walltime=150 and gets added to the calendar at now+300
Job4 has a soft_walltime=150 and gets added to the calendar at now+450
"""
self.scheduler.set_sched_config({'strict_ordering': 'True'})
a = {'resources_available.ncpus': 1}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
self.server.manager(MGR_CMD_SET, SERVER, {ATTR_backfill_depth: 3})
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'False'})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid1 = self.server.submit(J)
self.server.alterjob(jid1, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid2 = self.server.submit(J)
self.server.alterjob(jid2, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid3 = self.server.submit(J)
self.server.alterjob(jid3, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid4 = self.server.submit(J)
self.server.alterjob(jid4, {'Resource_List.soft_walltime': 150})
now = int(time.time())
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.scheduler.log_match('Leaving Scheduling Cycle', starttime=now,
max_attempts=20)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid1)
self.compare_estimates(jid2, [jid3, jid4])
def test_topjob2(self):
"""
Test a mixture of soft_walltime and walltime used in the calendar
Submit 3 jobs:
Job1 has a soft_walltime=150 runs now
Job2 has a soft_walltime=150 and gets added to the calendar at now+150
Job3 has a soft_walltime=150 and gets added to the calendar at now+300
Job4 has a walltime=300 and gets added to the calendar at now+450
Job5 gets added to the calendar at now+750
"""
self.scheduler.set_sched_config({'strict_ordering': 'True'})
a = {'resources_available.ncpus': 1}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
self.server.manager(MGR_CMD_SET, SERVER, {ATTR_backfill_depth: 4})
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'False'})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid1 = self.server.submit(J)
self.server.alterjob(jid1, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid2 = self.server.submit(J)
self.server.alterjob(jid2, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid3 = self.server.submit(J)
self.server.alterjob(jid3, {'Resource_List.soft_walltime': 150})
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid4 = self.server.submit(J)
J = Job(TEST_USER, {'Resource_List.walltime': 300})
jid5 = self.server.submit(J)
now = int(time.time())
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.scheduler.log_match('Leaving Scheduling Cycle', starttime=now)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid1)
self.compare_estimates(jid2, [jid3, jid4, jid5])
def test_filler_job(self):
"""
Test to see if filler jobs will run based on their soft_walltime
Submit 3 jobs:
Job1 requests 1cpu and runs now
Job2 requests 2cpus gets added to the calendar at now+300
Job3 requests 1cpu and has a soft_walltime=150 and walltime=450
Job3 should run because its soft_walltime will finish before now+300
"""
self.scheduler.set_sched_config({'strict_ordering': 'True'})
a = {'resources_available.ncpus': 2}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'False'})
J1 = Job(TEST_USER, {'Resource_List.walltime': 300,
'Resource_List.ncpus': 1})
jid1 = self.server.submit(J1)
J2 = Job(TEST_USER, {'Resource_List.walltime': 300,
'Resource_List.ncpus': 2})
jid2 = self.server.submit(J2)
J3 = Job(TEST_USER, {'Resource_List.walltime': 450,
'Resource_List.ncpus': 1})
jid3 = self.server.submit(J3)
self.server.alterjob(jid3, {'Resource_List.soft_walltime': 150})
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid1)
self.server.expect(JOB, {ATTR_state: 'Q'}, id=jid2)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid3)
def test_preempt_order(self):
"""
Test if soft_walltime is used for preempt_order. It should be used
to calculate percent done and also if the soft_walltime is exceeded,
the percent done should remain at 100%
"""
self.server.manager(MGR_CMD_SET, SCHED, {'preempt_order': 'R 10 '},
runas=ROOT_USER)
a = {'resources_available.ncpus': 2}
self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname)
a = {'queue_type': 'Execution', 'enabled': 'True',
'started': 'True', 'Priority': 150}
self.server.manager(MGR_CMD_CREATE, QUEUE, a, id='expressq')
a = {'Resource_List.walltime': 600}
J1 = Job(TEST_USER, attrs=a)
jid1 = self.server.submit(J1)
a = {'Resource_List.soft_walltime': 45}
self.server.alterjob(jid1, a)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid1)
# test preempt_order with percentage < 90. jid1 should be requeued.
express_a = {'Resource_List.ncpus': 2, ATTR_queue: 'expressq'}
J2 = Job(TEST_USER, attrs=express_a)
jid2 = self.server.submit(J2)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid2)
self.server.expect(JOB, {ATTR_state: 'Q'}, id=jid1)
self.server.deljob(jid2, wait=True)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid1)
# preempt_order percentage done is based on resources_used.walltime
# this is only periodically updated. Sleep until half way through
# the extended soft_walltime to make sure we're over 100%
self.logger.info("Sleeping 60 seconds to accumulate "
"resources_used.walltime")
time.sleep(60)
J3 = Job(TEST_USER, attrs=express_a)
jid3 = self.server.submit(J3)
self.server.expect(JOB, {ATTR_state: 'R'}, id=jid3)
self.server.expect(JOB, {ATTR_state: 'S'}, id=jid1)
def test_soft_values_default(self):
"""
Test to verify that soft_walltime will only take integer/long type
value
"""
msg = 'Illegal attribute or resource value'
try:
self.server.manager(
MGR_CMD_SET, SERVER, {'resources_default.soft_walltime': '0'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '00:00:00'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': 'abc'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '01:20:aa'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(MGR_CMD_SET, SERVER, {
'resources_default.soft_walltime':
'1000000000000000000000000'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '-1'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
try:
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '00.10'})
except PbsManagerError as e:
self.assertTrue(msg in e.msg[0])
self.server.manager(
MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '00:01:00'})
def test_soft_runjob_hook(self):
"""
Test that soft walltime is set by runjob hook
"""
hook_body = \
"""import pbs
e = pbs.event()
e.job.Resource_List["soft_walltime"] = pbs.duration(5)
e.accept()
"""
a = {'event': 'runjob', 'enabled': 'True'}
self.server.create_import_hook("que", a, hook_body)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 5}, id=jid)
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
def test_soft_modifyjob_hook(self):
"""
Test that soft walltime is set by modifyjob hook
"""
hook_body = \
"""import pbs
e = pbs.event()
e.job.Resource_List["soft_walltime"] = pbs.duration(15)
e.accept()
"""
a = {'event': 'modifyjob', 'enabled': 'True'}
self.server.create_import_hook("que", a, hook_body)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.expect(
JOB, 'Resource_List.soft_walltime', op=UNSET, id=jid)
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 5})
self.server.expect(JOB, {'Resource_List.soft_walltime': 15}, id=jid)
def test_walltime_default(self):
"""
Test soft walltime behavior with hard walltime is same
even if set under resource_default
"""
self.server.manager(MGR_CMD_SET, SERVER,
{'resources_default.soft_walltime': '15'})
J = Job(TEST_USER, attrs={'Resource_List.walltime': 15})
jid = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 15}, id=jid)
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
self.server.deljob(jid, wait=True)
J = Job(TEST_USER, attrs={'Resource_List.walltime': 16})
jid1 = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 15}, id=jid1)
self.server.expect(JOB, {'job_state': 'R'}, id=jid1)
self.server.deljob(jid1, wait=True)
# following piece is commented due to PP-1058
# try:
# J = Job(TEST_USER, attrs={'Resource_List.walltime': 10})
# jid1 = self.server.submit(J)
# except PtlSubmitError as e:
# self.assertTrue("illegal attribute or resource value" in e.msg[0])
# self.assertEqual(jid1, None)
def test_soft_held(self):
"""
Test that if job is held soft_walltime will not get extended
"""
J = Job(TEST_USER, attrs={'Resource_List.walltime': '100'})
jid = self.server.submit(J)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 7})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
self.logger.info(
"Sleep to let soft_walltime get extended")
time.sleep(10)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 7}, op=GT,
id=jid)
# Save the soft_walltime before holding the job
jstat = self.server.status(JOB, id=jid,
attrib=['estimated.soft_walltime'])
est_soft_walltime = jstat[0]['estimated.soft_walltime']
self.server.holdjob(jid, 'u')
self.server.rerunjob(jid)
self.server.expect(JOB, {'job_state': 'H'}, id=jid)
self.logger.info(
"Sleep to verify that soft_walltime: %s"
" doesn't change while job is held" % est_soft_walltime)
time.sleep(10)
self.server.expect(JOB, {'estimated.soft_walltime':
est_soft_walltime}, id=jid)
# release the job and look for the soft_walltime again
self.server.rlsjob(jid, 'u')
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'job_state': 'R', 'estimated.soft_walltime':
est_soft_walltime}, attrop=PTL_AND, id=jid)
# Wait for some more time and verify that soft_walltime
# extending again
self.logger.info(
"Sleep enough to let soft_walltime get extended again"
" since the walltime was reset to 0")
time.sleep(17)
self.server.expect(JOB, {'estimated.soft_walltime': est_soft_walltime},
op=GT, id=jid)
def test_soft_less_cput(self):
"""
Test that soft_walltime has no impact on cput enforcement limit
"""
script = """
i=0
while [ 1 ]
do
sleep 0.125;
dd if=/dev/zero of=/dev/null;
done
"""
j1 = Job(TEST_USER, {'Resource_List.cput': 5})
j1.create_script(body=script)
jid = self.server.submit(j1)
self.server.alterjob(jid, {'Resource_List.soft_walltime': 300})
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
# verify that job is deleted when cput limit is reached
time.sleep(10)
self.server.expect(JOB, 'queue', op=UNSET, id=jid)
def test_soft_walltime_resv(self):
"""
Submit a job with soft walltime inside a reservation
"""
now = int(time.time())
a = {'Resource_List.ncpus': 1, 'reserve_start': now + 5,
'reserve_end': now + 10}
R = Reservation(TEST_USER, attrs=a)
rid = self.server.submit(R)
self.server.expect(RESV,
{'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')},
id=rid)
r1 = rid.split('.')[0]
j1 = Job(TEST_USER, attrs={ATTR_queue: r1})
jid = self.server.submit(j1)
# Set soft walltime to greater than reservation end time
self.server.alterjob(jid, {'Resource_List.soft_walltime': 300})
self.server.expect(JOB, {'Resource_List.soft_walltime': 300}, id=jid)
# verify that the job gets deleted when reservation ends
self.server.expect(
JOB, 'queue', op=UNSET, id=jid, offset=10, max_attempts=10)
def test_restart_server(self):
"""
Test that on server restart soft walltime is not reset
"""
self.server.manager(MGR_CMD_SET, SERVER,
{'job_history_enable': 'True'})
hook_body = \
"""import pbs
e = pbs.event()
e.job.Resource_List["soft_walltime"] = pbs.duration(8)
e.accept()
"""
a = {'event': 'queuejob', 'enabled': 'True'}
self.server.create_import_hook("que", a, hook_body)
J = Job(TEST_USER)
jid = self.server.submit(J)
self.server.expect(JOB, {'Resource_List.soft_walltime': 8}, id=jid)
self.server.expect(JOB, {'job_state': 'R'}, id=jid)
self.logger.info("Wait till the soft_walltime is extended once")
time.sleep(9)
self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'True'})
self.server.expect(JOB, {'estimated.soft_walltime': 8}, op=GT,
id=jid)
self.server.restart()
self.server.expect(JOB, {'Resource_List.soft_walltime': 8}, id=jid)
self.server.expect(JOB, {'estimated.soft_walltime': 8}, op=GT,
id=jid)
# Get the current soft_walltime
jstat = self.server.status(JOB, id=jid,
attrib=['estimated.soft_walltime'])
est_soft_walltime = jstat[0]['estimated.soft_walltime']
# Delete the job and verify that estimated.soft_walltime is set
# for job history
self.server.deljob(jid, wait=True)
self.server.expect(JOB,