language: Erlang (erl-5.7.3)
date: 969 days 13 hours ago
link:
visibility: public
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
-module(python_migration_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
 
 
suite() ->
        % Make SSH and Python settings from config files, sshconfig.cfg 
        % and pyconfig.cfg, available in the suite
    [{require, server}, 
     {require, client1}, 
     {require, client2},
     {require, serverSettings},
     {require, client1Settings},
     {require, client2Settings}]. 
 
init_per_suite(Config) ->
    % Start ssh connection to server, client1 and client2
    {ok, Server}  = ct_ssh:connect(server),
    {ok, Client1} = ct_ssh:connect(client1),
        {ok, Client2} = ct_ssh:connect(client2),
        
        % Append handles to config variable
    [{ssh_handles,{Server, Client1, Client2}} | Config].
 
 
end_per_suite(Config) ->
        % Get ssh handles from config and make them a traversable list
    Handles = erlang:tuple_to_list(?config(ssh_handles, Config)),
 
    % Disconnect any active ssh handle
        lists:foreach(fun(Handle) -> ct_ssh:disconnect(Handle) end, 
                                  Handles).
 
 
init_per_group(_GroupName, Config) ->
    % Get ssh handles from config
        {Server, Client1, Client2} = ?config(ssh_handles, Config),
 
    % Start python server on server and log stdout
        ct_ssh:exec(Server, "python " ++ ct:get_config({serverSettings, serverpy}) 
                                ++ " -i " ++ ct:get_config({serverSettings, serverip}) 
                                ++ " -p " ++ ct:get_config({serverSettings, serverport}) 
                                ++ " >> " ++ ct:get_config({serverSettings, serverlog}), 
                                2000),
 
    % Start python client on client1 and log stdout
        ct_ssh:exec(Client1, "python " ++ ct:get_config({client1Settings, client1py}) 
                                ++ " -i " ++ ct:get_config({client1Settings, client1ip})
                                ++ " -p " ++ ct:get_config({client1Settings, client1port})
                            ++ " > " ++ ct:get_config({client1Settings, client1log}), 
                                2000),
 
    % Start python client on client2 and log stdout
        ct_ssh:exec(Client2, "python " ++ ct:get_config({client2Settings, client2py}) 
                                ++ " -i " ++ ct:get_config({client2Settings, client2ip})
                                ++ " -p " ++ ct:get_config({client2Settings, client2port})
                            ++ " > " ++ ct:get_config({client2Settings, client2log}), 
                                2000),
 
    Config.
 
end_per_group(_GroupName, Config) ->
    % Get ssh handles from config
        {Server, Client1, Client2} = ?config(ssh_handles, Config),
 
    % End python server on server
        ct_ssh:exec(Server, "python " ++ ct:get_config({serverSettings, commandpy}) ++ " -x"),
 
    % End python client on client1
        ct_ssh:exec(Client1, "pkill -f 'client.py'"),
 
    % End python client on client2
        ct_ssh:exec(Client2, "pkill -f 'client.py'"),
 
    ok.
 
init_per_testcase(_TestCase, Config) ->
    Config.
 
end_per_testcase(_TestCase, _Config) ->
    ok.
 
groups() ->
    % Define sequential group migrateC1, then migrate2
    [{migrateTest, [sequence], [migrateC1, migrateC2]}].
 
all() ->
        % Run the whole group when the suite is run
    [migrateTest].
 
migrateC1() ->
        % Do nothing in this testcase info function
    [].
 
migrateC2() ->
        % Do nothing in this testcase info function
    [].
 
migrateC1(Config) ->
    % Get server handle as it is the only one used in the testcase
        Server = element(1, ?config(ssh_handles,Config)),
        
        % Initial delay 2 seconds to assure that the server has been started properly
        ok = timer:sleep(2000),
 
    % Redirect server stream to client1 
        ct_ssh:exec(Server, "python " ++ ct:get_config({serverSettings, commandpy})
                                ++ " -i " ++ ct:get_config({client1Settings, client1ip}) 
                                ++ " -p " ++ ct:get_config({client1Settings, client1port})),
 
    % Delay 7 seconds
        ok = timer:sleep(7000),
 
    ok.
 
migrateC2(Config) ->
    % Get server handle as it is the only one used in the testcase
        Server = element(1, ?config(ssh_handles,Config)),
 
    % Redirect server stream to client2
        ct_ssh:exec(Server, "python " ++ ct:get_config({serverSettings, commandpy}) 
                                ++ " -i " ++ ct:get_config({client2Settings, client2ip}) 
                                ++ " -p " ++ ct:get_config({client2Settings, client2port})),
 
    % Delay 7 seconds
        ok = timer:sleep(7000),
 
    ok.