Adjust DFC test files to use FTPES instead of FTPS
[integration.git] / test / mocks / datafilecollector-testharness / mr-sim / README.md
1 # MR-simulator
2
3 This readme contains:
4
5 - Introduction
6 - Building and running
7 - Configuration
8
9 ## Introduction
10
11 The MR-sim is a python script delivering batches of events including one or more fileReady for one or more PNFs.
12 It is possible to configure number of events, PNFs, consumer groups, exising or missing files, file prefixes and change identifier.
13 In addition, MR sim can be configured to deliver file url for up to 5 FTP servers (simulating the PNFs).
14
15 ## Building and running
16
17 It is possible build and run MR-sim manually as a container if needed. In addition MR-sim can be executed as python script, see instuctions further down.
18 Otherwise it is recommended to use the test scripts in the auto-test dir or run all simulators in one go using scripts in the simulator-group dir.
19
20 To build and run manually as a docker container:
21
22 1. Build docker container with `docker build -t mrsim:latest .`
23 2. Run the container `docker-compose up`
24
25 ## Configuration
26
27 The event pattern, called TC, of the MR-sim is controlled with a arg to python script. See section TC info for available patterns.
28 All other configuration is done via envrionment variables.
29 The simulator listens to port 2222.
30
31 The following envrionment vaiables are used:
32
33 - **FTPES_SIMS** - A comma-separated list of hostname:port for the FTP servers to generate ftpes file urls for. If not set MR sim will assume 'localhost:21'. Minimum 1 and maximum 5 host-port pairs can be given.
34 - **SFTP_SIMS** - A comma-separated list of hostname:port for the FTP servers to generate sftp file urls for. If not set MR sim will assume 'localhost:1022'. Minimum 1 and maximum 5 host-port pairs can be given.
35 - **NUM_FTP_SERVERS** - Number of FTP servers to use out of those specified in the envrioment variables above. The number shall be in the range 1-5.
36 - **MR_GROUPS** - A comma-separated list of consummer-group:changeId[:changeId]\*. Defines which change identifier that should be used for each consumer gropu. If not set the MR-sim will assume 'OpenDcae-c12:PM_MEAS_FILES'.
37 - **MR_FILE_PREFIX_MAPPING** - A comma-separated list of changeId:filePrefix. Defines which file prefix to use for each change identifier, needed to distinguish files for each change identifiers. If not set the MR-sim will assume 'PM_MEAS_FILES:A
38
39 ## Statistics read-out and commands
40
41 The simulator can be queried for statistics  and  started/stopped (use curl from cmd line or open in browser, curl used below):
42
43 `curl localhost:2222` - Just returns 'Hello World'.
44
45 `curl localhost:2222/tc_info` - returns the tc string (as given on the cmd line)
46
47 `curl localhost:2222/start` - start event delivery (default status).
48
49 `curl localhost:2222/stop` - stop event delivery.
50
51 `curl localhost:2222/status` - returns the status, started or stopped .
52
53 `curl localhost:2222/execution_time` - returns the execution time in mm:ss
54
55 `curl localhost:2222/groups` - returns a comma-separated list of configured consumer groups..
56
57 `curl localhost:2222/changeids` - returns a commar-separated list of configured change id sets, where each set is a list of colon-separated change for each configured consumer group.
58
59 `curl localhost:2222/fileprefixes` - returns the setting of env var MR_FILE_PREFIX_MAPPING.
60
61 `curl localhost:2222/ctr_requests`   - returns an integer of the number of get requests, for all groups,  to the event poll path
62
63 `curl localhost:2222/groups/ctr_requests`   - returns a list of integers of the number of get requests, for each consumer group, to the event poll path
64
65 `curl localhost:2222/ctr_requests/<consumer-group>`   - returns an integer of the number of get requests, for the specified consumer group, to the event poll path
66
67 `curl localhost:2222/ctr_responses`   - returns an integer of the number of get responses, for all groups,  to the event poll path
68
69 `curl localhost:2222/groups/ctr_responses`   - returns a list of integers of the number of get responses, for each consumer group, to the event poll path
70
71 `curl localhost:2222/ctr_responses/<consumer-group>`   - returns an integer of the number of get responses, for the specified consumer group, to the event poll path
72
73 `curl localhost:2222/ctr_files` - returns an integer of the number generated files for all groups
74
75 `curl localhost:2222/groups/ctr_files` - returns a list of integers of the number generated files for each group
76
77 `curl localhost:2222/ctr_files/<consumer-group>` - returns an integer or the number generated files for the specified group
78
79 `curl localhost:2222/ctr_unique_files` - returns an integer of the number generated unique files for all groups
80
81 `curl localhost:2222/groups/ctr_unique_files` - returns a list of integers of the number generated unique files for each group
82
83 `curl localhost:2222/ctr_unique_files/<consumer-group>` - returns an integer or the number generated unique files for the specified group
84
85 `curl localhost:2222/ctr_events` - returns the total number of events for all groups
86
87 `curl localhost:2222/groups/ctr_events` - returns a list the integer of the total number of events for each group
88
89 `curl localhost:2222/ctr_events/<consumer-group>` - returns the total number of events for a specified group
90
91 `curl localhost:2222/exe_time_first_poll` - returns the execution time in mm:ss from the first poll
92
93 `curl localhost:2222/groups/exe_time_first_poll` - returns a list of the execution time in mm:ss from the first poll for each group
94
95 `curl localhost:2222/exe_time_first_poll/<consumer-group>` - returns the execution time in mm:ss from the first poll for the specified group
96
97 `curl localhost:2222/ctr_unique_PNFs` - returns the number of unique PNFS in all events.
98
99 `curl localhost:2222/groups/ctr_unique_PNFs` - returns a list of the number of unique PNFS in all events for each group.
100
101 `curl localhost:2222/ctr_unique_PNFs/<consumer-group>` - returns the number of unique PNFS in all events for the specified group.
102
103 ## Alternative to running python (as described below) on your machine, use the docker files
104
105 1. Build docker container with `docker build -t mrsim:latest .`
106 2. Run the container `docker-compose up`
107    The behavior can be changed by argument to the python script in the docker-compose.yml
108
109 ## Common TC info
110
111 File names for 1MB, 5MB and 50MB files
112 Files in the format: <size-in-mb>MB\_<sequence-number>.tar.gz    Ex. for 5MB file with sequence number 12:  5MB_12.tar.gz
113 The sequence numbers are stepped so that all files have unique names
114 Missing files (files that are not expected to be found in the ftp server. Format: MissingFile\*<sequence-number>.tar.gz
115
116 When the number of events are exhausted, empty replies are returned '\[]', for the limited test cases. For endless tc no empty replies will be given.
117
118 Test cases are limited unless noted as 'endless'.
119
120 TC100 - One ME, SFTP, 1 1MB file, 1 event
121
122 TC101 - One ME, SFTP, 1 5MB file, 1 event
123
124 TC102 - One ME, SFTP, 1 50MB file, 1 event
125
126 TC110 - One ME, SFTP, 1MB files, 1 file per event, 100 events, 1 event per poll.
127
128 TC111 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll.
129
130 TC112 - One ME, SFTP, 5MB files, 100 files per event, 100 events, 1 event per poll.
131
132 TC113 - One ME, SFTP, 1MB files, 100 files per event, 100 events. All events in one poll.
133
134 TC120 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% of replies each: no response, empty message, slow response, 404-error, malformed json
135
136 TC121 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files
137
138 TC122 - One ME, SFTP, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name.
139
140 TC500 - 700 MEs, SFTP, 1MB files, 2 new files per event, 700 events, all event in one poll
141
142 TC501 - 700 MEs, SFTP, 5MB files, 2 new files per event, 700 events, all event in one poll
143
144 TC502 - 700 MEs, SFTP, 50MB files, 2 new files per event, 700 events, all event in one poll
145
146 TC510 - 700 MEs, SFTP, 1MB files, 1 file per event, 3500 events, 700 event per poll.
147
148 TC511 - 700 MEs, SFTP, 1KB files, 1 file per event, 3500 events, 700 event per poll
149
150 TC550 - 700 MEs, SFTP, 50MB files, 1 file per event, 3500 events, 700 event per poll
151
152 TC710 - 700 MEs, SFTP, 1MB files, 100 files per event, 3500 events, 35 event per poll
153
154 TC1000 - One ME, SFTP, 1MB files, 100 files per event, endless number of events, 1 event per poll
155
156 TC1001 - One ME, SFTP, 5MB files, 100 files per event, endless number of events, 1 event per poll
157
158 TC1100 - 700 ME, SFTP, 1MB files, 100 files per event, endless number of events, 35 event per poll
159
160 TC1101 - 700 ME, SFTP, 5MB files, 100 files per event, endless number of events, 35 event per poll
161
162 TC1102 - 700 ME, SFTP, 50MB files, 100 files per event, endless number of events, 35 event per poll
163
164 TC1200 - 700 ME, SFTP, 1MB files, 100 new files per event, endless number of events, 35 event per poll
165
166 TC1201 - 700 ME, SFTP, 5MB files, 100 new files per event, endless number of events, 35 event per poll
167
168 TC1202 - 700 ME, SFTP, 50MB files, 100 new files per event, endless number of events, 35 event per poll
169
170 TC1300 - 700 ME, SFTP, 1MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min
171
172 TC1301 - 700 ME, SFTP, 5MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min
173
174 TC1302 - 700 ME, SFTP, 50MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min
175
176 TC1500 - 700 ME, SFTP, 1MB files, 100 files per event, 35 events per poll, simulating 25h backlog of decreasing number of outdated files and then 20 event polls every 15min for 1h
177
178 Changing the first digit in tc number will change the test case to run FTPES instead. Eg. TC201 is FTPES version of TC101.
179
180 TC2XX is same as TC1XX but with FTPES
181
182 TC6XX is same as TC5XX but with FTPES
183
184 TC8XX is same as TC7XX but with FTPES
185
186 TC2XXX is same as TC1XXX but with FTPES
187
188 ## Developer workflow
189
190 1. `sudo apt install python3-venv`
191 2. `source .env/bin/activate/`
192 3. `pip3 install "anypackage"`      #also include in source code
193 4. `pip3 freeze | grep -v "pkg-resources" > requirements.txt`  #to create a req file
194 5. `FLASK_APP=mr-sim.py flask run`
195    or
196    `python3 mr-sim.py `
197 6. Check/lint/format the code before commit/amed by `autopep8 --in-place --aggressive --aggressive mr-sim.py`
198
199 ## User workflow on \*NIX
200
201 When cloning/fetching from the repository first time:
202
203 1. `git clone`
204 2. `cd "..." `          #navigate to this folder
205 3. `source setup.sh `   #setting up virtualenv and install requirements
206    you'll get a sourced virtualenv shell here, check prompt
207 4. `(env) $ python3 mr-sim.py --help`
208    alternatively
209    `(env) $ python3 mr-sim.py --tc1`
210
211 Every time you run the script, you'll need to step into the virtualenv by following step 3 first.
212
213 ## User workflow on Windows
214
215 When cloning/fetching from the repository first time:
216
217 1. 'git clone'
218 2. then step into the folder
219 3. 'pip3 install virtualenv'
220 4. 'pip3 install virtualenvwrapper-win'
221 5. 'mkvirtualenv env'
222 6. 'workon env'
223 7. 'pip3 install -r requirements.txt'   #this will install in the local environment then
224 8. 'python3 dfc-sim.py'
225
226 Every time you run the script, you'll need to step into the virtualenv by step 2+6.