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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(installer).
-include("test_lib.hrl").
%%-compile(export_all).
-export([install_1/2]).
-export([install_2/1]).
-export([install_3/2]).
-export([install_6a/1]).
-export([install_4/1]).
-export([install_5/1]).
-export([install_5a/1]).
-export([install_6/1]).
-export([install_7/1]).
-export([install_7a/1]).
-export([install_8/1]).
-export([install_8a/1]).
-export([install_9/1]).
-export([install_10/1]).
-export([install_11/1]).
-export([install_12/1]).
-export([install_13/1]).
-export([install_14/1]).
-export([upgrade_restart_1/2]).
-export([upgrade_restart_1a/1]).
-export([upgrade_restart_2/1]).
-export([upgrade_restart_2a/1]).
-export([upgrade_restart_3/1]).
-export([client1_1/4]).
-export([client2/3]).
-export([stop/1]).
-export([unpack_p1h/2]).
-export([permanent_p1h/1]).
-export([reg_proc/1]).
-export([registered_loop/1]).
-define(print(List), {rh_print, TestNode} ! {print, {?MODULE, ?LINE}, List}).
-define(print_line(Line,List), {rh_print, TestNode} ! {print, {?MODULE, Line}, List}).
-define(fail(Term), exit({?MODULE, ?LINE, Term})).
-define(fail_line(Line,Term), exit({?MODULE, Line, Term})).
-define(check_release_states(States),
check_release_states(TestNode,node(),States,?LINE)).
-define(check_release_states_client(Node,States),
check_release_states(TestNode,Node,States,?LINE)).
-define(check_release_lib(Vsn,Apps),
check_release_lib(TestNode,node(),Vsn,Apps,?LINE)).
-define(check_release_lib_client(Node,Vsn,Apps),
check_release_lib(TestNode,Node,Vsn,Apps,?LINE)).
-define(check_running_app(App,Vsn),
check_running_app(TestNode,node(),App,Vsn,?LINE)).
-define(check_running_app_client(Node,App,Vsn),
check_running_app(TestNode,Node,App,Vsn,?LINE)).
-define(check_disallowed_calls,check_disallowed_calls(TestNode,?LINE)).
install_1(TestNode,PrivDir) ->
?print([TestNode]),
?print(["install_1 start"]),
?check_release_states([permanent]),
% Unpack and install P1H
{ok, "P1H"} = unpack_release(PrivDir,"rel1"),
?check_release_states([permanent,unpacked]),
?check_release_lib("P1H",["a-1.0"]),
{ok,"P1G",[new_appl]} = release_handler:install_release("P1H"),
?check_release_states([permanent,current]),
?check_running_app(a,"1.0"),
X = a:a(),
?print(["X", X]),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
?print(["install_1 end OK"]),
ok.
% release_handler_SUITE will reboot this node now!
install_2(TestNode) ->
?print(["install_2 start"]),
% Check that P1H is still unpacked, install it and make_permanent
?check_release_states([permanent,unpacked]),
{ok,"P1G",[new_appl]} = release_handler:install_release("P1H"),
?print(["install_2 install_release ok"]),
?check_release_states([permanent,current]),
?check_running_app(a,"1.0"),
ok = release_handler:make_permanent("P1H"),
?print(["install_2 make permanent P1H ok"]),
?check_release_states([old,permanent]),
?check_running_app(a,"1.0"),
ok.
% release_handler_SUITE will reboot this node now!
install_3(TestNode,PrivDir) ->
?print(["install_3 start"]),
% Check that P1H is permanent
?check_release_states([old,permanent]),
?check_running_app(a,"1.0"),
X = a:a(),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
% Unpack and install P1I
{ok, "P1I"} = unpack_release(PrivDir,"rel2"),
?check_release_states([old,permanent,unpacked]),
?check_release_lib("P1I",["a-1.1"]),
{ok,"P1H",[{extra, gott}]} = release_handler:check_install_release("P1I"),
?print(["install_3 check_install_release P1I ok"]),
{error,_} = release_handler:check_install_release("P1J"),
?print(["install_3 check_install_release P1J fails - ok"]),
{ok,"P1H",[{extra, gott}]} = release_handler:install_release("P1I"),
?check_release_states([old,permanent,current]),
?check_running_app(a,"1.1"),
X2 = a:a(),
{key2, newval2} = lists:keyfind(key2, 1, X2),
{key1, val1} = lists:keyfind(key1, 1, X2),
{ok, bval} = a:b(),
?print(["install_3 env ok"]),
% Unpack P2A
{ok, "P2A"} = unpack_release(PrivDir,"rel3"),
?check_release_states([old,permanent,current,unpacked]),
?check_release_lib("P2A",["a-1.1"]),
{ok, "P1I", [new_emu]} = release_handler:check_install_release("P2A"),
?print(["install_3 check_install_release P2A ok"]),
ok.
% release_handler_SUITE will reboot this node now!
install_4(TestNode) ->
?print(["install_4 start"]),
%% Check that P1H is the one that is used
?check_release_states([old,permanent,unpacked,unpacked]),
?check_running_app(a,"1.0"),
%% Install P2A
{continue_after_restart, "P1H", [new_emu,new_appl]} =
release_handler:install_release("P2A"),
%% Node is rebooted by the release_handler:install_release
%% (init:reboot) because P2A includes a new erts vsn and the relup
%% file contains a 'restart_new_emulator' instruction.
?print(["install_4 P2A installed"]),
ok.
install_5(TestNode) ->
?print(["install_5 start"]),
%% Check that the upgrade was done via a temporary release due to
%% new emulator version.
{"SASL-test","__new_emulator__P1H"} = init:script_id(),
%% Check that P2A is in use.
?check_release_states([old,permanent,unpacked,current]),
?check_running_app(a,"1.1"),
X = a:a(),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = a:b(),
?print(["install_5 check env ok"]),
ok.
install_5a(TestNode) ->
?print(["install_5a start"]),
%% Install P1I (this will be a downgrade)
{ok, "P1I", [old_emu]} = release_handler:install_release("P1I"),
%% Node is rebooted by the release_handler:install_release
%% (init:reboot) because P2A includes a new erts vsn and the relup
%% file contains a 'restart_new_emulator' instruction.
?print(["install_5a P1I installed"]),
ok.
install_6(TestNode) ->
?print(["install_6 start"]),
%% Check that P1I is used
?check_release_states([old,permanent,current,old]),
?check_running_app(a,"1.1"),
%% Make P1I permanent
ok = release_handler:make_permanent("P1I"),
?check_release_states([old,old,permanent,old]),
?check_running_app(a,"1.1"),
ok.
install_6a(TestNode) ->
%% Install P2A
{continue_after_restart, "P1I", [new_emu]} =
release_handler:install_release("P2A"),
%% Node is rebooted by the release_handler:install_release
%% (init:reboot) because P2A includes a new erts vsn and the relup
%% file contains a 'restart_new_emulator' instruction.
?print(["install_6a P2A installed"]),
ok.
install_7(TestNode) ->
?print(["install_7 start"]),
%% Check that the upgrade was done via a temporary release due to
%% new emulator version.
{"SASL-test","__new_emulator__P1I"} = init:script_id(),
% Check that P2A is in use.
?check_release_states([old,old,permanent,current]),
?check_running_app(a,"1.1"),
X = a:a(),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = a:b(),
?print(["install_7 check env ok"]),
ok.
install_7a(TestNode) ->
%% Install P1H (this will be a downgrade)
{ok, "P1H", [old_emu,old_appl]} = release_handler:install_release("P1H"),
%% Node is rebooted by the release_handler:install_release
%% (init:reboot) because P2A includes a new erts vsn and the relup
%% file contains a 'restart_new_emulator' instruction.
?print(["install_7a P1H installed"]),
ok.
install_8(TestNode) ->
?print(["install_8 start"]),
%% Check that P1H is used
?check_release_states([old,current,permanent,old]),
?check_running_app(a,"1.0"),
{ok,"P1H",[new_emu,new_appl]} = release_handler:check_install_release("P2A"),
?print(["install_8 check_install_release P2A ok"]),
%% Install P1I and check that it is permanent
{ok,"P1H",[{extra, gott}]} = release_handler:install_release("P1I"),
?check_release_states([old,old,permanent,old]),
?check_running_app(a,"1.1"),
ok.
install_8a(TestNode) ->
% Install P2A again
{continue_after_restart, "P1I", [new_emu]} =
release_handler:install_release("P2A"),
%% Node is rebooted by the release_handler:install_release
%% (init:reboot) because P2A includes a new erts vsn and the relup
%% file contains a 'restart_new_emulator' instruction.
?print(["install_8a P2A installed"]),
ok.
install_9(TestNode) ->
?print(["install_9 start"]),
%% Check that the upgrade was done via a temporary release due to
%% new emulator version.
{"SASL-test","__new_emulator__P1I"} = init:script_id(),
% Check that P2A is used
?check_release_states([old,old,permanent,current]),
?check_running_app(a,"1.1"),
X = a:a(),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = a:b(),
?print(["install_9 check env ok"]),
ok = release_handler:make_permanent("P2A"),
?check_release_states([old,old,old,permanent]),
?check_running_app(a,"1.1"),
ok.
% release_handler_SUITE will reboot this node now!
install_10(TestNode) ->
?print(["install_10 start"]),
% Check that P2A is used
?check_release_states([old,old,old,permanent]),
?check_running_app(a,"1.1"),
% Install old P1H
ok = release_handler:reboot_old_release("P1H"),
?print(["install_10 reboot_old ok"]),
ok.
install_11(TestNode) ->
?print(["install_11 start"]),
% Check that P1H is permanent
?check_release_states([old,permanent,old,old]),
?check_running_app(a,"1.0"),
X = a:a(),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
?print(["install_11 check env ok"]),
%% Remove P1I and P2A and check that a-1.1 and erts-<latest> are removed
ok = release_handler:remove_release("P2A"),
?check_release_states([old,permanent,old]),
ok = release_handler:remove_release("P1I"),
?check_release_states([old,permanent]),
{ok, Libs} = file:list_dir(code:lib_dir()),
{_,_,StdlibVsn} = lists:keyfind(stdlib,1,application:which_applications()),
true = lists:member("stdlib-"++StdlibVsn, Libs),
true = lists:member("a-1.0", Libs),
false = lists:member("a-1.1", Libs),
{ok, Dirs} = file:list_dir(code:root_dir()),
ErtsDir = "erts-"++?ertsvsn,
[ErtsDir] = lists:filter(fun(Dir) -> lists:prefix("erts-",Dir) end, Dirs),
?print(["install_11 file checks ok"]),
ok.
% release_handler_SUITE will reboot this node now!
install_12(TestNode) ->
?print(["install_12 start"]),
% Check that P1H is permanent
?check_release_states([old,permanent]),
?check_running_app(a,"1.0"),
X = a:a(),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
?print(["install_12 check env ok"]),
% Install old P1G
ok = release_handler:reboot_old_release("P1G"),
?print(["install_12 reboot_old ok"]),
ok.
install_13(TestNode) ->
?print(["install_13 start"]),
% Check that P1G is permanent
?check_release_states([permanent,old]),
false = lists:keysearch(a,1,application:loaded_applications()),
?print(["install_13 no a application found - ok"]),
%% Remove P1H and check that both versions of application a is removed
ok = release_handler:remove_release("P1H"),
?check_release_states([permanent]),
{ok, Libs} = file:list_dir(code:lib_dir()),
{_,_,StdlibVsn} = lists:keyfind(stdlib,1,application:which_applications()),
true = lists:member("stdlib-"++StdlibVsn, Libs),
false = lists:member("a-1.0", Libs),
false = lists:member("a-1.1", Libs),
?print(["install_13 file checks ok"]),
ok.
% release_handler_SUITE will reboot this node now!
install_14(TestNode) ->
?print(["install_14 start"]),
% Check that P1G is permanent
?check_release_states([permanent]),
false = lists:keysearch(a,1,application:loaded_applications()),
?print(["install_13 no a application found - ok"]),
ok.
%%%-----------------------------------------------------------------
%%% Ths test checks that an upgrade which both upgrades to a new
%%% emulator version, and had a restart_emulator option to
%%% systools:make_relup will be restarted twice on upgrade.
%%% (On downgrade it will happen only once.)
upgrade_restart_1(TestNode,PrivDir) ->
?print([TestNode]),
?print(["upgrade_restart_1 start"]),
?check_release_states([permanent]),
{ok, "P2B"} = unpack_release(PrivDir,"rel4"),
?check_release_states([permanent,unpacked]),
?check_release_lib("P2B",["a-1.1"]),
ok.
upgrade_restart_1a(TestNode) ->
?print(["upgrade_restart_1a start"]),
{continue_after_restart,"P1G",[new_emu,add_appl]} =
release_handler:install_release("P2B"),
?print(["upgrade_restart_1a P2B installed"]),
ok.
upgrade_restart_2(TestNode) ->
?print(["upgrade_restart_2 start"]),
%% Check that the node has been restarted once more after the tmp release
{"SASL-test","P2B"} = init:script_id(),
?check_release_states([permanent,current]),
?check_running_app(a,"1.1"),
ok = release_handler:make_permanent("P2B"),
?check_release_states([old,permanent]),
ok.
upgrade_restart_2a(TestNode) ->
?print(["upgrade_restart_2a start"]),
{ok,"P1G",[old_emu,rm_appl]} = release_handler:install_release("P1G"),
?print(["upgrade_restart_2a P1G installed"]),
ok.
upgrade_restart_3(TestNode) ->
?print(["upgrade_restart_3 start"]),
%% Ideally we should test that the node has only been restarted
%% once... but that's not so easy. Let's just check that P1G is running.
?check_release_states([current,permanent]),
false = lists:keysearch(a,1,application:loaded_applications()),
?print(["upgrade_restart_3 no a application found - ok"]),
ok.
%%-----------------------------------------------------------------
%% This test starts a client node which uses this node as master
%% for the release_handler.
%% The client node runs all tests as in installer/1 test case.
%% Thus, the client node will be rebooted several times.
%% The to_erl /tmp/NODENAME@HOSTNAME/ command can be used to connect
%% to the client node.
%% run_erl logs for the client can be found in the directory:
%% code:root_dir() ++ "/clients/type1/NODENAME@HOSTNAME/log
%%-----------------------------------------------------------------
client1_1(TestNode,PrivDir,MasterDir,ClientSname) ->
TestHost = test_host(),
?print(["client1_1 start"]),
{ok,IP} = inet:getaddr(TestHost,inet),
erl_boot_server:start([IP]),
ok = net_kernel:monitor_nodes(true),
Node = start_client(TestNode,client1,ClientSname),
trace_disallowed_calls(Node),
?check_release_states_client(Node,[permanent]),
%% Check env var for SASL on client node
SaslEnv = rpc:call(Node, application, get_all_env, [sasl]),
?print([{client1_1,sasl_env},SaslEnv]),
{_,CliDir} = lists:keyfind(client_directory,1,SaslEnv),
{_,[Master]} = lists:keyfind(masters,1,SaslEnv),
{_,StartCli} = lists:keyfind(start_prg,1,SaslEnv),
NodeStr = atom_to_list(Node),
[NodeStr,"type1","clients"|_] = lists:reverse(filename:split(CliDir)),
true = (Master =:= node()),
case os:type() of
{unix,_} ->
true = (StartCli =:= filename:join([CliDir,"bin","start"]));
_ ->
ok
end,
%% Unpack P1H on master
{ok, "P1H"} = unpack_release(PrivDir,"rel1"),
%% Unpack and install P1H on client
Root = code:root_dir(),
P1HDir = filename:join([Root, "releases", "P1H"]),
%% The AppDirs argument (last arg to set_unpacked) below is really
%% not necessary, it could just be [] since the path is the same
%% as default. But it is given here in order to force hitting the
%% release_handler:check_path function so it can be checked that
%% it does not use file:read_file_info on the client node, see
%% trace_disallowed_calls/1 and check_disallowed_calls/2 below.
%% (OTP-9142)
{ok, "P1H"} = rpc:call(Node, release_handler, set_unpacked,
[filename:join(P1HDir, "rel1.rel"),
[{a,"1.0",filename:join(MasterDir,lib)}]]),
?check_release_states_client(Node,[permanent,unpacked]),
?check_release_lib_client(Node,"P1H",["a-1.0"]),
ok = rpc:call(Node, release_handler, install_file,
["P1H", filename:join(P1HDir, "start.boot")]),
ok = rpc:call(Node, release_handler, install_file,
["P1H", filename:join(P1HDir, "sys.config")]),
ok = rpc:call(Node, release_handler, install_file,
["P1H", filename:join(P1HDir, "relup")]),
?print([{release_handler_state, Node},
rpc:call(Node, sys, get_status, [release_handler])]),
{ok,"P1G",[new_appl]} =
rpc:call(Node, release_handler, check_install_release, ["P1H"]),
{ok,"P1G",[new_appl]} =
rpc:call(Node, release_handler, install_release, ["P1H"]),
?check_release_states_client(Node,[permanent,current]),
?check_running_app_client(Node,a,"1.0"),
Apps = rpc:call(Node, application, which_applications, []),
{a,"A CXC 138 11","1.0"} = lists:keyfind(a, 1, Apps),
X = rpc:call(Node, a, a, []),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_2(TestNode,PrivDir,Node).
client1_2(TestNode,PrivDir,Node) ->
?print(["client1_2 start"]),
%% Check that P1H is still unpacked, install it and make_permanent
?check_release_states_client(Node,[permanent,unpacked]),
{ok,"P1G",[new_appl]} =
rpc:call(Node, release_handler, install_release, ["P1H"]),
?check_release_states_client(Node,[permanent,current]),
?check_running_app_client(Node,a,"1.0"),
ok = rpc:call(Node, release_handler, make_permanent, ["P1H"]),
?check_release_states_client(Node,[old,permanent]),
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_3(TestNode,PrivDir,Node).
client1_3(TestNode,PrivDir,Node) ->
?print(["client1_3 start"]),
%% Check that P1H is permanent
?check_release_states_client(Node,[old,permanent]),
?check_running_app_client(Node,a,"1.0"),
%% Unpack P1I on master
{ok, "P1I"} = unpack_release(PrivDir,"rel2"),
MasterRoot = code:root_dir(),
%% Unpack and install P1I on client
P1IDir = filename:join([MasterRoot, "releases", "P1I"]),
{ok, "P1I"} = rpc:call(Node, release_handler, set_unpacked,
[filename:join(P1IDir, "rel2.rel"),[]]),
?check_release_states_client(Node,[old,permanent,unpacked]),
?check_release_lib_client(Node,"P1I",["a-1.1"]),
ok = rpc:call(Node, release_handler, install_file,
["P1I", filename:join(P1IDir, "start.boot")]),
ok = rpc:call(Node, release_handler, install_file,
["P1I", filename:join(P1IDir, "sys.config")]),
ok = rpc:call(Node, release_handler, install_file,
["P1I", filename:join(P1IDir, "relup")]),
{ok,"P1H",[{extra, gott}]} =
rpc:call(Node, release_handler, check_install_release, ["P1I"]),
{error,_} = rpc:call(Node, release_handler, check_install_release, ["P1J"]),
{ok,"P1H",[{extra, gott}]} =
rpc:call(Node, release_handler, install_release, ["P1I"]),
?check_release_states_client(Node,[old,permanent,current]),
?check_running_app_client(Node,a,"1.1"),
X2 = rpc:call(Node, a, a, []),
{key2, newval2} = lists:keyfind(key2, 1, X2),
{key1, val1} = lists:keyfind(key1, 1, X2),
{ok, bval} = rpc:call(Node, a, b, []),
%% Unpack P2A on master
{ok, "P2A"} = unpack_release(PrivDir,"rel3"),
%% Unpack and install P2A on client
P2ADir = filename:join([MasterRoot, "releases", "P2A"]),
{ok, "P2A"} =
rpc:call(Node, release_handler, set_unpacked,
[filename:join(P2ADir, "rel3.rel"),[]]),
?check_release_states_client(Node,[old,permanent,current,unpacked]),
?check_release_lib_client(Node,"P2A",["a-1.1"]),
ok = rpc:call(Node, release_handler, install_file,
["P2A", filename:join(P2ADir, "start.boot")]),
ok = rpc:call(Node, release_handler, install_file,
["P2A", filename:join(P2ADir, "sys.config")]),
ok = rpc:call(Node, release_handler, install_file,
["P2A", filename:join(P2ADir, "relup")]),
{ok, "P1I", [new_emu]} =
rpc:call(Node, release_handler, check_install_release, ["P2A"]),
%% Reboot from P1H
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_4(TestNode,Node).
client1_4(TestNode,Node) ->
?print(["client1_4 start"]),
%% check that P1H is used
?check_release_states_client(Node,[old,permanent,unpacked,unpacked]),
%% since the install_release below reboot the node...
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
{continue_after_restart, "P1H", [new_emu,new_appl]} =
rpc:call(Node, release_handler, install_release, ["P2A"]),
%% Reboots the client !
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_5(TestNode,Node).
client1_5(TestNode,Node) ->
?print(["client1_5 start"]),
%% Check that P2A is in use.
?check_release_states_client(Node,[old,permanent,unpacked,current]),
?check_running_app_client(Node,a,"1.1"),
X = rpc:call(Node, a, a, []),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = rpc:call(Node, a, b, []),
%% since the install_release below reboot the node...
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
{ok,"P1I",[old_emu]} =
rpc:call(Node, release_handler, install_release, ["P1I"]),
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_6(TestNode,Node).
client1_6(TestNode,Node) ->
?print(["client1_6 start"]),
?check_release_states_client(Node,[old,permanent,current,old]),
?check_running_app_client(Node,a,"1.1"),
ok = rpc:call(Node, release_handler, make_permanent, ["P1I"]),
?check_release_states_client(Node,[old,old,permanent,old]),
%% since the install_release below reboot the node...
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
{continue_after_restart, "P1I", [new_emu]} =
rpc:call(Node, release_handler, install_release, ["P2A"]),
%% Reboots the client !
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_7(TestNode,Node).
client1_7(TestNode,Node) ->
?print(["client1_7 start"]),
%% Check that P2A is in use.
?check_release_states_client(Node,[old,old,permanent,current]),
?check_running_app_client(Node,a,"1.1"),
X = rpc:call(Node, a, a, []),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = rpc:call(Node, a, b, []),
%% since the install_release below reboot the node...
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
{ok,"P1H",[old_emu,old_appl]} =
rpc:call(Node, release_handler, install_release, ["P1H"]),
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_8(TestNode,Node).
client1_8(TestNode,Node) ->
?print(["client1_8 start"]),
%% Check that P1H is used
?check_release_states_client(Node,[old,current,permanent,old]),
?check_running_app_client(Node,a,"1.0"),
{ok, "P1H", [new_emu,new_appl]} =
rpc:call(Node, release_handler, check_install_release, ["P2A"]),
{ok,"P1H",[{extra, gott}]} =
rpc:call(Node, release_handler, install_release, ["P1I"]),
?check_release_states_client(Node,[old,old,permanent,old]),
?check_running_app_client(Node,a,"1.1"),
%% since the install_release below will reboot the node...
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
%% Install P2A again
{continue_after_restart, "P1I", [new_emu]} =
rpc:call(Node, release_handler, install_release, ["P2A"]),
%% We are rebooted again.
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_9(TestNode,Node).
client1_9(TestNode,Node) ->
?print(["client1_9 start"]),
%% Check that P2A is used
?check_release_states_client(Node,[old,old,permanent,current]),
?check_running_app_client(Node,a,"1.1"),
X = rpc:call(Node, a, a, []),
{key2, newval2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
{ok, bval} = rpc:call(Node, a, b, []),
%% Make P2A permanent
ok = rpc:call(Node, release_handler, make_permanent, ["P2A"]),
?check_release_states_client(Node,[old,old,old,permanent]),
%% Reboot from P2A
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_10(TestNode,Node).
client1_10(TestNode,Node) ->
?print(["client1_10 start"]),
%% Check that P2A is used
?check_release_states_client(Node,[old,old,old,permanent]),
%% since the reboot_old_release below will reboot the node
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
%% Install old P1H
rpc:call(Node, release_handler, reboot_old_release, ["P1H"]),
%% We are rebooted.
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_11(TestNode,Node).
client1_11(TestNode,Node) ->
?print(["client1_11 start"]),
%% Check that P1H is permanent
?check_release_states_client(Node,[old,permanent,old,old]),
?check_running_app_client(Node,a,"1.0"),
X = rpc:call(Node, a, a, []),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
%% Remove P1I and P2A from client
ok = rpc:call(Node, release_handler, set_removed, ["P2A"]),
?check_release_states_client(Node,[old,permanent,old]),
ok = rpc:call(Node, release_handler, set_removed, ["P1I"]),
?check_release_states_client(Node,[old,permanent]),
%% Check that P2A and P1I does not exists
Rels = rpc:call(Node, release_handler, which_releases, []),
false = lists:keysearch("P2A", 2, Rels),
false = lists:keysearch("P1I", 2, Rels),
X = rpc:call(Node, a, a, []),
{key2, val2} = lists:keyfind(key2, 1, X),
{key1, val1} = lists:keyfind(key1, 1, X),
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_12(TestNode,Node).
client1_12(TestNode,Node) ->
?print(["client1_12 start"]),
?check_release_states_client(Node,[old,permanent]),
%% since the reboot_old_release below will reboot the node
?check_disallowed_calls,
cover_client(TestNode,Node,stop_cover),
%% Install old P1G
rpc:call(Node, release_handler, reboot_old_release, ["P1G"]),
%% We are rebooted.
check_reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_13(TestNode,Node).
client1_13(TestNode,Node) ->
?print(["client1_13 start"]),
%% Check that P1G is permanent
?check_release_states_client(Node,[permanent,old]),
{error,client_node} = rpc:call(Node,release_handler,remove_release,["P1H"]),
ok = rpc:call(Node, release_handler, set_removed, ["P1H"]),
?check_release_states_client(Node,[permanent]),
?check_disallowed_calls,
reboot(TestNode,Node),
trace_disallowed_calls(Node),
client1_14(TestNode,Node).
client1_14(TestNode,Node) ->
?print(["client1_14 start"]),
%% Check that P1G is permanent
?check_release_states_client(Node,[permanent]),
?check_disallowed_calls,
stop_client(TestNode,Node), %% TEST IS OK !!
net_kernel:monitor_nodes(false),
%% Remove releases from master
ok = release_handler:remove_release("P2A"),
ok = release_handler:remove_release("P1I"),
ok = release_handler:remove_release("P1H"),
ok.
%% Start tracing of the file module on the client node. This module
%% shall never be called, since
%% 1) the node is a client from the release_handler's point of view,
%% so all file access should be done via rpc calls to the master
%% 2) it is started with erl_prim_loader loader set to 'inet' so all
%% code loading should be done via the inet to the master
%% (OTP-9142)
%% This function is called each time the client node is started and to
%% check if a call has been made, call check_disallowed_node/0
trace_disallowed_calls(Node) ->
MasterProc = self(),
rpc:call(Node,dbg,tracer,[process,{fun(T,_) -> MasterProc ! T end,[]}]),
rpc:call(Node,dbg,p,[all,call]),
rpc:call(Node,dbg,tp,[file,[{'_',[],[{message,{caller}}]}]]).
check_disallowed_calls(TestNode,Line) ->
receive
Trace when element(1,Trace)==trace ->
?print_line(Line,["Disallowed function called",Trace]),
exit({disallowed_function_call,Trace})
after 0 ->
ok
end.
start_client(TestNode,Client,Sname) ->
Node = list_to_atom(lists:concat([Sname,"@",test_host()])),
case os:type() of
{unix,_} -> start_client_unix(TestNode,Sname,Node);
{win32,_} -> start_client_win32(TestNode,Client,Sname)
end,
receive
{nodeup, Node} ->
wait_started(TestNode,Node)
after 30000 ->
?print([{start_client,failed,Node},net_adm:ping(Node)]),
?fail({"can not start", Node})
end.
start_client_unix(TestNode,Sname,Node) ->
Start = filename:join(["clients", "type1", Node, "bin", "start"]),
Cmd = lists:concat(["env NODENAME=",Sname," ",
filename:join(code:root_dir(), Start)]),
?print([{start_client,Sname},Cmd]),
Res = os:cmd(Cmd),
?print([{start_client,result},Res]).
start_client_win32(TestNode,Client,ClientSname) ->
Name = atom_to_list(ClientSname) ++ "_P1G",
RootDir = code:root_dir(),
ErtsBinDir = filename:join([RootDir,"erts-"++?ertsvsn,"bin"]),
{ClientArgs,RelClientDir} = rh_test_lib:get_client_args(Client,ClientSname,
RootDir),
StartErlArgs = rh_test_lib:get_start_erl_args(RootDir,RelClientDir,
ClientArgs),
ServiceArgs = rh_test_lib:get_service_args(RootDir, RelClientDir,
ClientSname, StartErlArgs),
?print([{start_client,ClientSname},ServiceArgs]),
Erlsrv = filename:nativename(filename:join(ErtsBinDir,"erlsrv")),
rh_test_lib:erlsrv(Erlsrv,stop,Name),
rh_test_lib:erlsrv(Erlsrv,remove,Name),
ok = rh_test_lib:erlsrv(Erlsrv,add,Name,ServiceArgs),
ok = rh_test_lib:erlsrv(Erlsrv,start,Name),
?print([{start_client,result},ok]),
ok.
reboot(TestNode,Node) ->
cover_client(TestNode,Node,stop_cover),
rpc:call(Node, init, reboot, []),
check_reboot(TestNode,Node).
%% This way of checking that the node is rebooted will only work if
%% the nodes are automatically re-connected after the reboot. This
%% happens for master/client (when sasl is started on the client).
check_reboot(TestNode,Node) ->
receive
{nodedown, Node} ->
receive
{nodeup, Node} -> wait_started(TestNode,Node)
after 30000 ->
?fail({Node, "not rebooted",net_adm:ping(Node)})
end
after 30000 ->
?fail({Node, "not closing down",net_adm:ping(Node)})
end.
stop_client(TestNode,Node) ->
cover_client(TestNode,Node,stop_cover),
rpc:call(Node, init, stop, []),
receive
{nodedown, Node} -> ok
after 30000 ->
?fail({Node, "not stopping"})
end.
wait_started(TestNode,Node) ->
case rpc:call(Node, init, get_status, []) of
{started, _} ->
cover_client(TestNode,Node,start_cover),
Node;
_ ->
timer:sleep(1000),
wait_started(TestNode,Node)
end.
cover_client(TestNode,Node,Func) ->
R = rpc:call(TestNode,release_handler_SUITE,Func,[Node]),
?print([{Func,Node,R}]).
%%-----------------------------------------------------------------
%% This test starts a client node which uses this node as master
%% for the release_handler.
%% The client node has the name cli2@HOSTNAME.
%% The client node is not allowed to do ANY release updates
%% as it also have another (non-existing) master node.
%%
%% The to_erl /tmp/cli2@HOSTNAME/ command can be used to connect
%% to the client node.
%% run_erl logs for the client can be found in the directory:
%% code:root_dir() ++ "/clients/type1/cli2@HOSTNAME/log
%%-----------------------------------------------------------------
client2(TestNode,PrivDir,ClientSname) ->
TestHost = test_host(),
?print(["client2 start"]),
%% Clean up if previous test case failed
release_handler:remove_release("P1H"),
ok = net_kernel:monitor_nodes(true),
Node = start_client(TestNode,client2,ClientSname),
%% Check env var for SASL on client node
SaslEnv = rpc:call(Node, application, get_all_env, [sasl]),
?print([{client1_1,sasl_env},SaslEnv]),
{_,CliDir} = lists:keyfind(client_directory,1,SaslEnv),
{_,[Master,Master2]} = lists:keyfind(masters,1,SaslEnv),
{_,StartCli} = lists:keyfind(start_prg,1,SaslEnv),
NodeStr = atom_to_list(Node),
[NodeStr,"type1","clients"|_] = lists:reverse(filename:split(CliDir)),
true = (Master =:= node()),
true = (Master2 =:= list_to_atom("master2@"++TestHost)),
case os:type() of
{unix,_} ->
true = (StartCli =:= filename:join([CliDir,"bin","start"]));
_ ->
ok
end,
%% Unpack P1H on master
{ok, "P1H"} = unpack_release(PrivDir,"rel1"),
%% Try to set P1H unpacked on client
Root = code:root_dir(),
{error,{bad_masters,[Master2]}} =
rpc:call(Node, release_handler, set_unpacked,
[filename:join([Root, "releases", "P1H", "rel1.rel"]),[]]),
{error,{no_such_release,"P1H"}} =
rpc:call(Node, release_handler, check_install_release, ["P1H"]),
stop_client(TestNode,Node), %% TEST IS OK !!
net_kernel:monitor_nodes(false),
release_handler:remove_release("P1H"),
ok.
stop(Now) ->
%% The timestamp is only used for debugging. It is printed by
%% release_handler_SUITE also.
R = init:stop(),
erlang:display({init_stop,Now,R}),
R.
unpack_p1h(TestNode,PrivDir) ->
{ok, "P1H"} = unpack_release(PrivDir,"rel1"),
?check_release_states([permanent,unpacked]),
?check_release_lib("P1H",["a-1.0"]),
ok.
permanent_p1h(TestNode) ->
?check_release_states([permanent,unpacked]),
?check_release_lib("P1H",["a-1.0"]),
{ok,"P1G",[new_appl]} = release_handler:install_release("P1H"),
?check_release_states([permanent,current]),
ok = release_handler:make_permanent("P1H"),
?check_release_states([old,permanent]),
ok.
reg_proc(Name) ->
catch unregister(Name),
Pid = spawn_link(?MODULE, registered_loop, [Name]),
global:register_name(Name, Pid),
ok.
registered_loop(_Name) ->
receive
kill ->
exit(killed)
end.
%% Checks that the list of states for all releases (sorted on vsn)
%% equals the input States
check_release_states(TestNode,Node,States,Line) ->
case rpc:call(Node,release_handler,which_releases,[]) of
{badrpc,_}=Error ->
?fail_line(Line,{check_release_states,Node,States,Error});
Rels ->
?print_line(Line,["check_release_states:", Rels]),
States = [Status || {_,_,_,Status} <- lists:keysort(2,Rels)],
ok
end.
%% Check that the given release (Vsn) sees the correct vsn of App.
check_release_lib(TestNode,Node,Vsn,Apps,Line) ->
case rpc:call(Node,release_handler,which_releases,[]) of
{badrpc,_}=Error ->
?fail_line(Line,{check_release_lib,Node,Vsn,Apps,Error});
Rels ->
?print_line(Line,["check_release_lib:", Rels]),
{"SASL-test", Vsn, Libs, _Status} = lists:keyfind(Vsn, 2, Rels),
true = lists:all(fun(App) -> lists:member(App,Libs) end,Apps),
ok
end.
%% Check that the given Vsn of App is executed
check_running_app(TestNode,Node,App,Vsn,Line) ->
case rpc:call(Node,application,which_applications,[]) of
{badrpc,_}=Error ->
?fail_line(Line,{check_running_app,Node,App,Vsn,Error});
Apps ->
?print_line(Line,["check_running_app:", Apps]),
{App, _, Vsn} = lists:keyfind(App, 1, Apps),
ok
end.
test_host() ->
{ok,Host} = inet:gethostname(),
Host.
unpack_release(PrivDir,Rel) ->
copy(filename:join([PrivDir,Rel,Rel++".tar.gz"]),
filename:join(code:root_dir(),releases)),
release_handler:unpack_release(Rel).
copy(Src, DestDir) ->
Dest = filename:join(DestDir, filename:basename(Src)),
{ok,_} = file:copy(Src, Dest),
ok.
|