/
batch_connect_test.rb
1365 lines (1109 loc) · 49.1 KB
/
batch_connect_test.rb
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
# frozen_string_literal: true
require 'application_system_test_case'
require 'ood_core/job/adapters/slurm'
class BatchConnectTest < ApplicationSystemTestCase
def setup
stub_sys_apps
stub_user
Configuration.stubs(:bc_dynamic_js).returns(true)
Configuration.stubs(:bc_dynamic_js?).returns(true) #stub the alias too
end
def stub_git(dir)
Open3.stubs(:capture3)
.with('git', 'describe', '--always', '--tags', chdir: dir)
.returns(['1.2.3', '', exit_success])
end
def make_bc_app(dir, form)
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
app_dir = "#{dir}/app".tap { |d| Dir.mkdir(d) }
stub_scontrol
stub_sacctmgr
stub_git(app_dir)
Pathname.new(app_dir).join('form.yml').write(form)
end
test 'cluster choice changes node types' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# select oakley and 2 node types should be hidden
select('oakley', from: bc_ele_id('cluster'))
# FIXME: no idea why .visible? doesn't work here. Selenium/chrome native still shows element as visible?
assert_equal 'display: none;', find_option_style('node_type', 'advanced')
assert_equal 'display: none;', find_option_style('node_type', 'hugemem')
# select owens and now they're available
select('owens', from: bc_ele_id('cluster'))
assert_equal '', find_option_style('node_type', 'advanced')
assert_equal '', find_option_style('node_type', 'hugemem')
end
test 'node type choice changes python versions' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# select python 2.7 to initialize things
select('owens', from: bc_ele_id('cluster'))
select('any', from: bc_ele_id('node_type'))
select('2.7', from: bc_ele_id('python_version'))
assert_equal '', find_option_style('python_version', '2.7')
# now switch node type and find that 2.7, and more, are hidden and 3.6 is the choice now
select('advanced', from: bc_ele_id('node_type'))
assert_equal 'display: none;', find_option_style('python_version', '2.7')
assert_equal 'display: none;', find_option_style('python_version', '3.1')
assert_equal 'display: none;', find_option_style('python_version', '3.2')
assert_equal '3.6', find("##{bc_ele_id('python_version')}").value
end
test 'changing node type changes mins & maxs' do
# max starts out at 7
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
select('owens', from: bc_ele_id('cluster'))
# change the node type and we should have some new min/max & value
select('gpu', from: bc_ele_id('node_type'))
assert_equal 28, find_max('bc_num_slots')
assert_equal 2, find_min('bc_num_slots')
assert_equal '2', find_value('bc_num_slots')
select('hugemem', from: bc_ele_id('node_type'))
assert_equal 42, find_max('bc_num_slots')
assert_equal 42, find_min('bc_num_slots')
assert_equal '42', find_value('bc_num_slots')
end
test 'clamping works on maxes' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
assert_equal 'any', find_value('node_type')
# put the max for 'any'
fill_in bc_ele_id('bc_num_slots'), with: 7
# now toggle to gpu. Max is 28 and the value is 28
select('gpu', from: bc_ele_id('node_type'))
assert_equal 28, find_max('bc_num_slots')
assert_equal '28', find_value('bc_num_slots')
end
test 'clamping works on mins' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
assert_equal 'any', find_value('node_type')
# put the min for 'any'
fill_in bc_ele_id('bc_num_slots'), with: 3
# now toggle to gpu. min is 2 and the value is 2
select('gpu', from: bc_ele_id('node_type'))
assert_equal 2, find_min('bc_num_slots')
assert_equal '2', find_value('bc_num_slots')
end
test 'clamping shifts left' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# setup to start with same
select('same', from: bc_ele_id('node_type'))
assert_equal 200, find_max('bc_num_slots')
assert_equal 100, find_min('bc_num_slots')
# less than current max, but greater than the next choices'
fill_in bc_ele_id('bc_num_slots'), with: 150
# toggle back to 'gpu' and it should clamp to 150 down to 28
select('gpu', from: bc_ele_id('node_type'))
assert_equal 28, find_max('bc_num_slots')
assert_equal '28', find_value('bc_num_slots')
end
test 'clamping shifts right' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# start with defaults
assert_equal 3, find_min('bc_num_slots')
assert_equal 7, find_max('bc_num_slots')
assert_equal 'any', find_value('node_type')
# not the max, but less than the next choices'
fill_in bc_ele_id('bc_num_slots'), with: 18
# toggle back to 'oakley' and it should clamp 18 up to 100 (same's minimum)
select('same', from: bc_ele_id('node_type'))
assert_equal 100, find_min('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
end
test 'changing the cluster changes max' do
# max starts out at 7
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 7, find_max('bc_num_slots')
select('owens', from: bc_ele_id('cluster'))
select('gpu', from: bc_ele_id('node_type'))
assert_equal 28, find_max('bc_num_slots')
# changing the cluster changes the max
select('oakley', from: bc_ele_id('cluster'))
assert_equal 40, find_max('bc_num_slots')
end
test 'using same node sets min/max' do
# max starts out at 7
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 7, find_max('bc_num_slots')
select('same', from: bc_ele_id('node_type'))
assert_equal 100, find_min('bc_num_slots')
assert_equal 200, find_max('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
# toggle the cluster back and forth and it's still the same
select('oakley', from: bc_ele_id('cluster'))
select('owens', from: bc_ele_id('cluster'))
assert_equal 100, find_min('bc_num_slots')
assert_equal 200, find_max('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
select('oakley', from: bc_ele_id('cluster'))
assert_equal 100, find_min('bc_num_slots')
assert_equal 200, find_max('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
end
test 'can set multiple min/maxes' do
# ensure defaults
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 1, find_min('bc_num_hours')
assert_equal 20, find_max('bc_num_hours')
assert_equal 3, find_min('bc_num_slots')
assert_equal 7, find_max('bc_num_slots')
assert_equal 'any', find_value('node_type')
# changing the same node changes both bc_num_slots and bc_num_hours
select('same', from: bc_ele_id('node_type'))
assert_equal 100, find_min('bc_num_slots')
assert_equal 200, find_max('bc_num_slots')
assert_equal 444, find_min('bc_num_hours')
assert_equal 555, find_max('bc_num_hours')
end
test 'several elements can set min/max' do
# here we see that changing the node_type can set min & max on bc_num_hours
# but changing classroom can also set min & max on bc_num_hours
# ensure defaults
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 1, find_min('bc_num_hours')
assert_equal 20, find_max('bc_num_hours')
assert_equal 'any', find_value('node_type')
assert_equal 'physics_1234', find_value('classroom')
assert_equal 'owens', find_value('cluster')
# changing the node type sets mins & maxes
select('same', from: bc_ele_id('node_type'))
assert_equal 444, find_min('bc_num_hours')
assert_equal 555, find_max('bc_num_hours')
select('Astronomy 5678', from: bc_ele_id('classroom'))
assert_equal 100, find_min('bc_num_hours')
assert_equal 110, find_max('bc_num_hours')
end
test 'can set multiple min/maxes with for clauses' do
# ensure defaults
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 1, find_min('bc_num_hours')
assert_equal 20, find_max('bc_num_hours')
assert_equal 3, find_min('bc_num_slots')
assert_equal 7, find_max('bc_num_slots')
assert_equal 'any', find_value('node_type')
assert_equal 'owens', find_value('cluster')
# changing to the gpu node changes both bc_num_slots and bc_num_hours
select('gpu', from: bc_ele_id('node_type'))
assert_equal 2, find_min('bc_num_slots')
assert_equal 28, find_max('bc_num_slots')
assert_equal 80, find_min('bc_num_hours')
assert_equal 88, find_max('bc_num_hours')
# change the cluster and these change again (the for clause)
select('oakley', from: bc_ele_id('cluster'))
assert_equal 3, find_min('bc_num_slots')
assert_equal 40, find_max('bc_num_slots')
assert_equal 90, find_min('bc_num_hours')
assert_equal 99, find_max('bc_num_hours')
end
test 'nothing applied to broken node type' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
assert_equal '3', find_value('bc_num_slots')
select('broken', from: bc_ele_id('node_type'))
# changing clusters does nothing.
select('owens', from: bc_ele_id('cluster'))
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
assert_equal '3', find_value('bc_num_slots')
select('oakley', from: bc_ele_id('cluster'))
assert_equal 7, find_max('bc_num_slots')
assert_equal 3, find_min('bc_num_slots')
assert_equal '3', find_value('bc_num_slots')
# choose same to get a min & max set. Change back to
# broken and we keep the same min & max from same.
# TODO this is _current_ behaviour, will probably break
select('same', from: bc_ele_id('node_type'))
assert_equal 200, find_max('bc_num_slots')
assert_equal 100, find_min('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
select('broken', from: bc_ele_id('node_type'))
assert_equal 200, find_max('bc_num_slots')
assert_equal 100, find_min('bc_num_slots')
assert_equal '100', find_value('bc_num_slots')
end
test 'clamp min values' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal '3', find_value('bc_num_slots')
select('owens', from: bc_ele_id('cluster'))
select('gpu', from: bc_ele_id('node_type'))
# value gets set to the new min
assert_equal '2', find_value('bc_num_slots')
# change clusters and it bumps up again
select('oakley', from: bc_ele_id('cluster'))
assert_equal '3', find_value('bc_num_slots')
# edit the values, then change the cluster to ensure
# the change overwrites the edit
fill_in bc_ele_id('bc_num_slots'), with: 1
assert_equal '1', find_value('bc_num_slots')
select('owens', from: bc_ele_id('cluster'))
assert_equal '2', find_value('bc_num_slots')
end
test 'clamp max values' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal '3', find_value('bc_num_slots')
# this tests filling values by design, bc we have to set a giant max right off the bat
fill_in bc_ele_id('bc_num_slots'), with: 1000
assert_equal '1000', find_value('bc_num_slots')
select('owens', from: bc_ele_id('cluster'))
select('gpu', from: bc_ele_id('node_type'))
# value gets set to the new max
assert_equal '28', find_value('bc_num_slots')
# change clusters and it bumps up again
select('oakley', from: bc_ele_id('cluster'))
assert_equal '40', find_value('bc_num_slots')
end
test 'clamp zeros' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal '0', find_value('gpus')
assert_equal 'any', find_value('node_type')
# change to gpu node type and 0 is clamped to 1 (gpu's min)
select('gpu', from: bc_ele_id('node_type'))
assert_equal '1', find_value('gpus')
fill_in bc_ele_id('gpus'), with: 3
assert_equal '3', find_value('gpus')
# change back to any node type and 3 is clamped to 0 (any's min)
select('any', from: bc_ele_id('node_type'))
assert_equal '0', find_value('gpus')
end
test 'python choice sets account' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'python27', find_value('bc_account')
select('3.1', from: bc_ele_id('python_version'))
assert_equal 'python31', find_value('bc_account')
select('2.7', from: bc_ele_id('python_version'))
assert_equal 'python27', find_value('bc_account')
select('3.2', from: bc_ele_id('python_version'))
assert_equal 'python32', find_value('bc_account')
# 3.7 isn't configured to change the account, so it stays 3.2
select('3.7', from: bc_ele_id('python_version'))
assert_equal 'python32', find_value('bc_account')
end
# test case for https://github.com/OSC/ondemand/issues/2686
test 'python choice also sets near duplicate field bc_account_other' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'python27', find_value('bc_account')
assert_equal 'other_account_python27', find_value('bc_account_other')
select('3.1', from: bc_ele_id('python_version'))
assert_equal 'python31', find_value('bc_account')
assert_equal 'other_account_python31', find_value('bc_account_other')
select('2.7', from: bc_ele_id('python_version'))
assert_equal 'python27', find_value('bc_account')
assert_equal 'other_account_python27', find_value('bc_account_other')
select('3.2', from: bc_ele_id('python_version'))
assert_equal 'python32', find_value('bc_account')
assert_equal 'other_account_python32', find_value('bc_account_other')
# 3.7 isn't configured to change the account, so it stays 3.2
select('3.7', from: bc_ele_id('python_version'))
assert_equal 'python32', find_value('bc_account')
assert_equal 'other_account_python32', find_value('bc_account_other')
end
test 'python choice sets hidden change thing' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal '2.7', find_value('python_version')
assert_equal 'any', find_value('node_type')
assert_equal 'default', find_value('hidden_change_thing', visible: false)
select('advanced', from: bc_ele_id('node_type'))
assert_equal 'python36', find_value('hidden_change_thing', visible: false)
select('3.6', from: bc_ele_id('python_version'))
assert_equal 'python36', find_value('hidden_change_thing', visible: false)
select('3.7', from: bc_ele_id('python_version'))
assert_equal 'python37', find_value('hidden_change_thing', visible: false)
select('4.0.nightly', from: bc_ele_id('python_version'))
assert_equal 'python4nightly', find_value('hidden_change_thing', visible: false)
end
test 'inline edits dont affect updating values' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'python27', find_value('bc_account')
select('3.1', from: bc_ele_id('python_version'))
assert_equal 'python31', find_value('bc_account')
# insert some text into the field
account_element = find("##{bc_ele_id('bc_account')}")
account_element.send_keys " & some typed value"
assert_equal 'python31 & some typed value', find_value('bc_account')
# now change it and confirm the value
select('3.2', from: bc_ele_id('python_version'))
assert_equal 'python32', find_value('bc_account')
end
test 'inline changes to hidden fields get overwritten too' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'default', find_value('hidden_change_thing')
select('3.7', from: bc_ele_id('python_version'))
assert_equal 'python37', find_value('hidden_change_thing', visible: false)
update_script = <<~JAVASCRIPT
let ele = document.getElementById('batch_connect_session_context_hidden_change_thing');
ele.value = 'some new value';
JAVASCRIPT
execute_script(update_script)
assert_equal 'some new value', find_value('hidden_change_thing', visible: false)
select('4.0.nightly', from: bc_ele_id('python_version'))
assert_equal 'python4nightly', find_value('hidden_change_thing', visible: false)
end
test 'sessions respond to cache file' do
Dir.mktmpdir('bc_cache_test') do |tmpdir|
OodAppkit.stubs(:dataroot).returns(Pathname.new(tmpdir.to_s))
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'owens', find_value('cluster')
assert_equal 'any', find_value('node_type')
assert_equal '2.7', find_value('python_version')
cache_json = File.new("#{BatchConnect::Session.cache_root}/sys_bc_jupyter.json", 'w+')
cache_json.write({ cluster: 'oakley', node_type: 'gpu', python_version: '3.2' }.to_json)
cache_json.close
visit new_batch_connect_session_context_url('sys/bc_jupyter')
assert_equal 'oakley', find_value('cluster')
assert_equal 'gpu', find_value('node_type')
assert_equal '3.2', find_value('python_version')
end
end
test 'hiding cuda version' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# default is any, so we can't see cuda_version
assert_equal 'any', find_value('node_type')
assert !find("##{bc_ele_id('cuda_version')}", visible: false).visible?
# select gpu and you can
select('gpu', from: bc_ele_id('node_type'))
assert find("##{bc_ele_id('cuda_version')}").visible?
# toggle back to 'same' and it's gone
select('same', from: bc_ele_id('node_type'))
assert !find("##{bc_ele_id('cuda_version')}", visible: false).visible?
end
# similar to the use case above, but for https://github.com/OSC/ondemand/issues/1666
test 'hiding a second option' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# default is any, so we can't see cuda_version or advanced_options
assert_equal 'any', find_value('node_type')
assert !find("##{bc_ele_id('cuda_version')}", visible: false).visible?
assert !find("##{bc_ele_id('advanced_options')}", visible: false).visible?
# gpu shows both cuda_version and advanced_options
select('gpu', from: bc_ele_id('node_type'))
assert find("##{bc_ele_id('cuda_version')}").visible?
assert find("##{bc_ele_id('advanced_options')}").visible?
# toggle back to 'same' and both are gone
select('same', from: bc_ele_id('node_type'))
assert !find("##{bc_ele_id('cuda_version')}", visible: false).visible?
assert !find("##{bc_ele_id('advanced_options')}", visible: false).visible?
# now select advanced and cuda is hidden, but advanced is shown
select('advanced', from: bc_ele_id('node_type'))
assert !find("##{bc_ele_id('cuda_version')}", visible: false).visible?
assert find("##{bc_ele_id('advanced_options')}").visible?
end
test 'hiding using check boxes based on when checked' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
form:
- gpus
- checkbox_test
attributes:
gpus:
widget: 'number_field'
checkbox_test:
widget: 'check_box'
html_options:
data:
hide-gpus-when-checked: true
HEREDOC
Pathname.new("#{dir}/app/").join('form.yml').write(form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
refute(find("##{bc_ele_id('checkbox_test')}").checked?)
assert(find("##{bc_ele_id('gpus')}").visible?)
# check the checkbox, and 'gpus' is hidden
check(bc_ele_id('checkbox_test'))
refute(find("##{bc_ele_id('gpus')}", visible: :hidden).visible?)
# un-check the checkbox, and 'gpus' is back
uncheck(bc_ele_id('checkbox_test'))
assert(find("##{bc_ele_id('gpus')}").visible?)
end
end
test 'hiding using check boxes based on when unchecked' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
form:
- gpus
- checkbox_test
attributes:
gpus:
widget: 'number_field'
checkbox_test:
widget: 'check_box'
html_options:
data:
hide-gpus-when-not-checked: true
HEREDOC
Pathname.new("#{dir}/app/").join('form.yml').write(form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
refute(find("##{bc_ele_id('checkbox_test')}").checked?)
refute(find("##{bc_ele_id('gpus')}", visible: :hidden).visible?)
# check the checkbox, and 'gpus' is visible
check(bc_ele_id('checkbox_test'))
assert(find("##{bc_ele_id('gpus')}").visible?)
# un-check the checkbox, and 'gpus' is back to being hidden
uncheck(bc_ele_id('checkbox_test'))
refute(find("##{bc_ele_id('gpus')}", visible: :hidden).visible?)
end
end
test 'options with hyphens set min & max' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 'owens', find_value('cluster')
assert_equal 'any', find_value('node_type')
assert_equal 7, find_max('bc_num_slots')
select('other-40ish-option', from: bc_ele_id('node_type'))
assert_equal 40, find_max('bc_num_slots')
# now change the cluster and the max changes
select('oakley', from: bc_ele_id('cluster'))
assert_equal 48, find_max('bc_num_slots')
end
test 'options with hyphens get hidden' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 'owens', find_value('cluster')
assert_equal 'any', find_value('node_type')
assert_equal '2.7', find_value('python_version')
# now switch node type and find that 2.7, and more, are hidden and 3.6 is the choice now
# even when the options has hyphens in it
select('other-40ish-option', from: bc_ele_id('node_type'))
assert_equal 'display: none;', find_option_style('python_version', '2.7')
assert_equal 'display: none;', find_option_style('python_version', '3.1')
assert_equal 'display: none;', find_option_style('python_version', '3.2')
assert_equal '3.6', find("##{bc_ele_id('python_version')}").value
end
test 'help menus get hidden' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 'any', find_value('node_type')
find("##{bc_ele_id('bc_email_on_started')}")
find('p', text: 'this is a help message should be hidden, sometimes', visible: true)
select('hugemem', from: bc_ele_id('node_type'))
find('p', text: 'this is a help message should be hidden, sometimes', visible: false)
find("##{bc_ele_id('bc_email_on_started')}", visible: false)
end
test 'options that start with numbers hide other options' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal('physics_1234', find_value('classroom'))
assert_equal('small', find_value('classroom_size'))
assert_equal('', find_option_style('classroom_size', 'large'))
# now change the classroom and see large dissappear
select('123ABC', from: bc_ele_id('classroom'))
assert_equal('display: none;', find_option_style('classroom_size', 'large'))
# select the default, and it's back.
select('Physics 1234', from: bc_ele_id('classroom'))
assert_equal('', find_option_style('classroom_size', 'large'))
# now change the lowercase classroom and see large dissappear again.
select('456def', from: bc_ele_id('classroom'))
assert_equal('display: none;', find_option_style('classroom_size', 'large'))
end
test 'options with numbers and slashes' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal 'physics_1234', find_value('classroom')
assert_equal 'small', find_value('classroom_size')
assert_equal '', find_option_style('classroom_size', 'medium')
assert_equal '', find_option_style('classroom_size', 'large')
# now change the classroom and see the other sizes disappear
select('Astronomy 5678', from: bc_ele_id('classroom'))
assert_equal 'display: none;', find_option_style('classroom_size', 'medium')
assert_equal 'display: none;', find_option_style('classroom_size', 'large')
# go back to default
select('Physics 1234', from: bc_ele_id('classroom'))
assert_equal 'physics_1234', find_value('classroom')
assert_equal 'small', find_value('classroom_size')
assert_equal '', find_option_style('classroom_size', 'medium')
assert_equal '', find_option_style('classroom_size', 'large')
# choose the option with slashes, and large and medium are gone
select('Economics 8846', from: bc_ele_id('classroom'))
assert_equal 'small', find_value('classroom_size')
assert_equal 'display: none;', find_option_style('classroom_size', 'medium')
assert_equal 'display: none;', find_option_style('classroom_size', 'large')
end
test 'options can check and uncheck' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults
assert_equal('small', find_value('classroom_size'))
refute(checked?('checkbox_test'))
# select large and it's checked
select('large', from: bc_ele_id('classroom_size'))
assert(checked?('checkbox_test'))
# back to small and it's unchanged
select('small', from: bc_ele_id('classroom_size'))
assert(checked?('checkbox_test'))
# now choose medium and it's un-checked
select('medium', from: bc_ele_id('classroom_size'))
refute(checked?('checkbox_test'))
end
test 'stage errors are shown' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
err_msg = 'this is a just a test for staging error messages'
Open3.stubs(:capture2e).raises(StandardError.new(err_msg))
# defaults
click_on('Launch')
verify_bc_alert('sys/bc_jupyter', I18n.t('dashboard.batch_connect_sessions_errors_staging'), err_msg)
end
test 'submit errors are shown' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
err_msg = BrokenAdapter::SUBMIT_ERR_MSG
Open3.stubs(:capture2e).returns(['', exit_success])
BatchConnect::Session.any_instance.stubs(:adapter).returns(BrokenAdapter.new)
# defaults
click_on('Launch')
verify_bc_alert('sys/bc_jupyter', I18n.t('dashboard.batch_connect_sessions_errors_submission'), err_msg)
end
test 'save errors are shown' do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
err_msg = 'this is a just a test for staging error messages'
# Open3.stubs(:capture2e).returns(['', exit_failure])
BatchConnect::Session.any_instance.stubs(:stage).raises(StandardError.new(err_msg))
# defaults
click_on('Launch')
verify_bc_alert('sys/bc_jupyter', 'save', err_msg)
end
test 'auto generated modules are dynamic' do
with_modified_env({ OOD_MODULE_FILE_DIR: 'test/fixtures/modules' }) do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults, note that intel doesn't show the default version
assert_equal 'app_jupyter', find_value('auto_modules_app_jupyter')
assert_equal 'intel/2021.3.0', find_value('auto_modules_intel')
assert_equal 'owens', find_value('cluster')
# versions not available on owens
assert_equal 'display: none;', find_option_style('auto_modules_app_jupyter', 'app_jupyter/3.1.18')
assert_equal 'display: none;', find_option_style('auto_modules_app_jupyter', 'app_jupyter/0.35.6')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/18.0.4')
# select oakley and now they're available
select('oakley', from: bc_ele_id('cluster'))
assert_equal 'app_jupyter', find_value('auto_modules_app_jupyter')
assert_equal '', find_option_style('auto_modules_app_jupyter', 'app_jupyter/3.1.18')
assert_equal '', find_option_style('auto_modules_app_jupyter', 'app_jupyter/0.35.6')
# and lots of intel versions aren't
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/18.0.2')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/18.0.0')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/17.0.5')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/17.0.2')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/16.0.8')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/16.0.3')
end
end
test 'auto modules allow hyphens' do
with_modified_env({ OOD_MODULE_FILE_DIR: 'test/fixtures/modules' }) do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults to the default version
assert_equal('netcdf-serial', find_value('auto_modules_netcdf_serial'))
select('4.3.3.1', from: bc_ele_id('auto_modules_netcdf_serial'))
module_value = 'netcdf-serial/4.3.3.1'
assert_equal(module_value, find_value('auto_modules_netcdf_serial'))
# the script.sh.erb raises the message 'context.auto_modules_netcdf_serial' (note the _ in the name)
# which should be 'netcdf-serial/4.3.3.1'
click_on('Launch')
verify_bc_alert('sys/bc_jupyter', I18n.t('dashboard.batch_connect_sessions_errors_staging'), module_value)
end
end
test 'auto generated modules hide hidden modules' do
with_modified_env({ OOD_MODULE_FILE_DIR: 'test/fixtures/modules' }) do
visit new_batch_connect_session_context_url('sys/bc_jupyter')
# defaults, note that intel doesn't show the default version
assert_equal 'app_jupyter', find_value('auto_modules_app_jupyter')
assert_equal 'intel/2021.3.0', find_value('auto_modules_intel')
assert_equal 'owens', find_value('cluster')
# oakley has the hidden intel module 'intel/2021.4.0'
select('oakley', from: bc_ele_id('cluster'))
actual_options = find_all_options('auto_modules_intel', nil).map(&:text)
# '2021.4.0' is not listed here.
expected_options = [
'2021.3.0', '19.1.3', '19.0.5', '19.0.3', '18.0.4', '18.0.3', '18.0.2',
'18.0.0', '17.0.7', '17.0.5', '17.0.2', '16.0.8', '16.0.3'
]
assert_equal(expected_options, actual_options)
end
end
test 'auto accounts are cluster aware' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
- oakley
form:
- auto_accounts
HEREDOC
Pathname.new("#{dir}/app/").join("form.yml").write(form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
assert_equal 'pzs0715', find_value('auto_accounts')
assert_equal 'owens', find_value('cluster')
# these accounts are only on owens
assert_equal '', find_option_style('auto_accounts', 'pas1754')
assert_equal '', find_option_style('auto_accounts', 'pas1604')
# pzs1124 exists on both, so it's available
assert_equal '', find_option_style('auto_accounts', 'pzs1124')
# pzs0715 is available on oakely, so switching clusters should keep the same value.
select('oakley', from: bc_ele_id('cluster'))
assert_equal 'pzs0715', find_value('auto_accounts')
# now these are hidden when oakley is chosen
assert_equal 'display: none;', find_option_style('auto_accounts', 'pas1754')
assert_equal 'display: none;', find_option_style('auto_accounts', 'pas1604')
# pzs1124 exists on both, so it's still available
assert_equal '', find_option_style('auto_accounts', 'pzs1124')
end
end
test 'simple accounts are not dynamic but are full lists' do
with_modified_env({ OOD_BC_SIMPLE_AUTO_ACCOUNTS: '1' }) do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
- oakley
form:
- auto_accounts
HEREDOC
Pathname.new("#{dir}/app/").join("form.yml").write(form)
visit new_batch_connect_session_context_url('sys/app')
assert_equal 'pzs0715', find_value('auto_accounts')
assert_equal 'owens', find_value('cluster')
# notice that there are no duplicates. These accounts are not cluster aware
expected_accounts = ['pas1604', 'pas1754', 'pas1871', 'pas2051', 'pde0006', 'pzs0714', 'pzs0715', 'pzs1010',
'pzs1117', 'pzs1118', 'pzs1124'].to_set
id = bc_ele_id('auto_accounts')
actual_accounts = page.all("##{id} option").map(&:value).to_set
assert_equal expected_accounts, actual_accounts
end
end
end
test 'auto queues are cluster aware' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
- oakley
form:
- auto_queues
HEREDOC
Pathname.new("#{dir}/app/").join('form.yml').write(form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
assert_equal 'batch', find_value('auto_queues')
assert_equal 'owens', find_value('cluster')
# just a queues that exist only on oakley
assert_equal 'display: none;', find_option_style('auto_queues', 'serial-40core')
assert_equal 'display: none;', find_option_style('auto_queues', 'serial-48core')
assert_equal 'display: none;', find_option_style('auto_queues', 'gpudebug-48core')
# systems queue is not available anywhere and thus, doesn't show up at all.
# we have no account that can submit to it, on any cluster.
assert_selector("##{bc_ele_id('auto_queues')} option[value='systems']", count: 0)
# batch exists on both clusters, so switching clusters does nothing
select('oakley', from: bc_ele_id('cluster'))
assert_equal 'batch', find_value('auto_queues')
# now those oakley queues are available
assert_equal '', find_option_style('auto_queues', 'serial-40core')
assert_equal '', find_option_style('auto_queues', 'serial-48core')
assert_equal '', find_option_style('auto_queues', 'gpudebug-48core')
end
end
test 'auto queues are account aware' do
Dir.mktmpdir do |dir|
form = <<~HEREDOC
---
cluster:
- owens
- oakley
form:
- auto_accounts
- auto_queues
HEREDOC
make_bc_app(dir, form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
assert_equal 'batch', find_value('auto_queues')
assert_equal 'owens', find_value('cluster')
assert_equal 'pzs0715', find_value('auto_accounts')
select('oakley', from: bc_ele_id('cluster'))
# condo-osumed queues are disabled, but the backfill-serial variants are.
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-cpu-40core'))
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-gpu-48core'))
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-gpu-quad'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-cpu-40core-backfill-serial'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-gpu-48core-backfill-serial'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-gpu-quad-backfill-serial'))
# change the account to pas2051 and now it's flipped.
# this is becuase pas2051 is on the condo-osumed queues' allow list and
# on the backfill variants' deny list
select('pas2051', from: bc_ele_id('auto_accounts'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-cpu-40core'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-gpu-48core'))
assert_equal('', find_option_style('auto_queues', 'condo-osumed-gpu-quad'))
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-cpu-40core-backfill-serial'))
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-gpu-48core-backfill-serial'))
assert_equal('display: none;', find_option_style('auto_queues', 'condo-osumed-gpu-quad-backfill-serial'))
end
end
test 'auto qos are dynamic' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")
form = <<~HEREDOC
---
cluster:
- owens
- oakley
form:
- auto_qos
- auto_accounts
HEREDOC
Pathname.new("#{dir}/app/").join('form.yml').write(form)
visit new_batch_connect_session_context_url('sys/app')
# defaults
assert_equal 'pzs0715', find_value('auto_accounts')
assert_equal 'owens-default', find_value('auto_qos')
assert_equal 'owens', find_value('cluster')
find_all_options('auto_qos', 'ruby-default').each do |option|
assert_equal 'display: none;', option['style']
end
find_all_options('auto_qos', 'pitzer-default').each do |option|
assert_equal 'display: none;', option['style']
end