diff options
Diffstat (limited to 'test/mocks/datafilecollector-testharness/mr-sim')
-rw-r--r-- | test/mocks/datafilecollector-testharness/mr-sim/README.md | 18 | ||||
-rw-r--r-- | test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py | 56 |
2 files changed, 64 insertions, 10 deletions
diff --git a/test/mocks/datafilecollector-testharness/mr-sim/README.md b/test/mocks/datafilecollector-testharness/mr-sim/README.md index 056136f94..055e7d914 100644 --- a/test/mocks/datafilecollector-testharness/mr-sim/README.md +++ b/test/mocks/datafilecollector-testharness/mr-sim/README.md @@ -10,7 +10,7 @@ This readme contains: The MR-sim is a python script delivering batches of events including one or more fileReady for one or more PNFs. It is possible to configure number of events, PNFs, consumer groups, exising or missing files, file prefixes and change identifier. -In addition, MR sim can be configured to deliver file url for up to 5 FTP servers (simulating the PNFs). +In addition, MR sim can be configured to deliver file url for up to 5 FTP and 5 HTTP servers (simulating the PNFs). ## Building and running @@ -32,8 +32,10 @@ The following envrionment vaiables are used: - **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. - **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. +- **HTTP_SIMS** - A comma-separated list of hostname:port for the HTTP servers to generate http file urls for. If not set MR sim will assume 'localhost:81'. Minimum 1 and maximum 5 host-port pairs can be given. - **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. -- **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'. +- **NUM_HTTP_SERVERS** - Number of HTTP servers to use out of those specified in the envrioment variables above. The number shall be in the range 1-5. +- **MR_GROUPS** - A comma-separated list of consummer-group:changeId\[:changeId]\*. Defines which change identifier that should be used for each consumer group. If not set the MR-sim will assume 'OpenDcae-c12:PM_MEAS_FILES'.not set the MR-sim will assume 'OpenDcae-c12:PM_MEAS_FILES'. - **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 ## Statistics read-out and commands @@ -109,7 +111,7 @@ The simulator can be queried for statistics and started/stopped (use curl from ## Common TC info File names for 1MB, 5MB and 50MB files -Files in the format: <size-in-mb>MB\_<sequence-number>.tar.gz Ex. for 5MB file with sequence number 12: 5MB_12.tar.gz +Files in the format: <size-in-mb>MB\_<sequence-number>.tar.gz Ex. for 5MB file with sequence number 12: 5MB\_12.tar.gz The sequence numbers are stepped so that all files have unique names Missing files (files that are not expected to be found in the ftp server. Format: MissingFile\*<sequence-number>.tar.gz @@ -175,9 +177,9 @@ TC1302 - 700 ME, SFTP, 50MB files, 100 files per event, endless number of events 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 -Changing the first digit in tc number will change the test case to run FTPES instead. Eg. TC201 is FTPES version of TC101. +Changing the first digit in tc number will change the test case to run FTPES or HTTP instead. Eg. TC201 is FTPES version of TC101. -TC2XX is same as TC1XX but with FTPES +TC2XX is same as TC1XX but with FTPES, TC3XX is same as TC1XX but with HTTP TC6XX is same as TC5XX but with FTPES @@ -193,7 +195,7 @@ TC2XXX is same as TC1XXX but with FTPES 4. `pip3 freeze | grep -v "pkg-resources" > requirements.txt` #to create a req file 5. `FLASK_APP=mr-sim.py flask run` or - `python3 mr-sim.py ` + ` python3 mr-sim.py ` 6. Check/lint/format the code before commit/amed by `autopep8 --in-place --aggressive --aggressive mr-sim.py` ## User workflow on \*NIX @@ -201,8 +203,8 @@ TC2XXX is same as TC1XXX but with FTPES When cloning/fetching from the repository first time: 1. `git clone` -2. `cd "..." ` #navigate to this folder -3. `source setup.sh ` #setting up virtualenv and install requirements +2. ` cd "..." ` #navigate to this folder +3. ` source setup.sh ` #setting up virtualenv and install requirements you'll get a sourced virtualenv shell here, check prompt 4. `(env) $ python3 mr-sim.py --help` alternatively diff --git a/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py b/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py index 982f4b8b3..809f18661 100644 --- a/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py +++ b/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py @@ -17,7 +17,10 @@ sftp_hosts = [] sftp_ports = [] ftpes_hosts = [] ftpes_ports = [] +http_hosts = [] +http_ports = [] num_ftp_servers = 1 +num_http_servers = 1 def sumList(ctrArray): @@ -515,11 +518,17 @@ def MR_reply(consumerGroup, consumerId): elif args.tc810: return tc710(groupIndex, changeId, filePrefix, "ftpes") + elif args.tc300: + return tc100(groupIndex, changeId, filePrefix, "http", "1MB") + elif args.tc301: + return tc100(groupIndex, changeId, filePrefix, "http", "5MB") + elif args.tc302: + return tc100(groupIndex, changeId, filePrefix, "http", "50MB") #### Test case functions -def tc100(groupIndex, changeId, filePrefix, ftpType, fileSize): +def tc100(groupIndex, changeId, filePrefix, schemeType, fileSize): global ctr_responses global ctr_events @@ -532,8 +541,11 @@ def tc100(groupIndex, changeId, filePrefix, ftpType, fileSize): nodeIndex = 0 nodeName = createNodeName(nodeIndex) fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, fileSize) - msg = getEventHead(groupIndex, changeId, nodeName) + getEventName(fileName, ftpType, "onap", "pano", + msg = getEventHead(groupIndex, changeId, nodeName) + getEventName(fileName, schemeType, "onap", "pano", nodeIndex) + getEventEnd() + if schemeType == "http": + msg = getEventHead(groupIndex, changeId, nodeName) + getEventName(fileName, schemeType, "demo", "demo123456!", + nodeIndex) + getEventEnd() fileMap[groupIndex][seqNr * hash(filePrefix)] = seqNr ctr_events[groupIndex] = ctr_events[groupIndex] + 1 return buildOkResponse("[" + msg + "]") @@ -1183,6 +1195,10 @@ def getEventName(fn, type, user, passwd, nodeIndex): if (type == "ftpes"): port = ftpes_ports[nodeIndex] ip = ftpes_hosts[nodeIndex] + elif (type == "http"): + nodeIndex = nodeIndex % num_http_servers + port = http_ports[nodeIndex] + ip = http_hosts[nodeIndex] nameStr = """{ "name": \"""" + fn + """", @@ -1231,11 +1247,15 @@ if __name__ == "__main__": # IP addresses to use for ftp servers, using localhost if not env var is set sftp_sims = os.environ.get('SFTP_SIMS', 'localhost:1022') ftpes_sims = os.environ.get('FTPES_SIMS', 'localhost:21') + http_sims = os.environ.get('HTTP_SIMS', 'localhost:81') num_ftp_servers = int(os.environ.get('NUM_FTP_SERVERS', 1)) + num_http_servers = int(os.environ.get('NUM_HTTP_SERVERS', 1)) print("Configured sftp sims: " + sftp_sims) print("Configured ftpes sims: " + ftpes_sims) + print("Configured http sims: " + http_sims) print("Configured number of ftp servers: " + str(num_ftp_servers)) + print("Configured number of http servers: " + str(num_http_servers)) tmp = sftp_sims.split(',') for i in range(len(tmp)): @@ -1249,6 +1269,12 @@ if __name__ == "__main__": ftpes_hosts.append(hp[0]) ftpes_ports.append(hp[1]) + tmp = http_sims.split(',') + for i in range(len(tmp)): + hp = tmp[i].split(':') + http_hosts.append(hp[0]) + http_ports.append(hp[1]) + groups = os.environ.get('MR_GROUPS', 'OpenDcae-c12:PM_MEAS_FILES') print("Groups detected: " + groups) configuredPrefixes = os.environ.get('MR_FILE_PREFIX_MAPPING', 'PM_MEAS_FILES:A') @@ -1597,6 +1623,20 @@ if __name__ == "__main__": action='store_true', help='TC810 - 700 MEs, FTPES, 1MB files, 100 files per event, 3500 events, 35 event per poll.') + # HTTP TCs with single ME + parser.add_argument( + '--tc300', + action='store_true', + help='TC300 - One ME, HTTP, 1 1MB file, 1 event') + parser.add_argument( + '--tc301', + action='store_true', + help='TC301 - One ME, HTTP, 1 5MB file, 1 event') + parser.add_argument( + '--tc302', + action='store_true', + help='TC302 - One ME, HTTP, 1 50MB file, 1 event') + args = parser.parse_args() if args.tc100: @@ -1731,6 +1771,13 @@ if __name__ == "__main__": elif args.tc810: tc_num = "TC# 810" + elif args.tc300: + tc_num = "TC# 300" + elif args.tc301: + tc_num = "TC# 301" + elif args.tc302: + tc_num = "TC# 302" + else: print("No TC was defined") print("use --help for usage info") @@ -1746,7 +1793,12 @@ if __name__ == "__main__": print("Using " + str(ftpes_hosts[i]) + ":" + str(ftpes_ports[i]) + " for ftpes server with index " + str( i) + " for ftpes server address and port in file urls.") + for i in range(len(http_hosts)): + print("Using " + str(http_hosts[i]) + ":" + str(http_ports[i]) + " for http server with index " + str( + i) + " for http server address and port in file urls.") + print("Using up to " + str(num_ftp_servers) + " ftp servers, for each protocol for PNFs.") + print("Using up to " + str(num_http_servers) + " http servers, for each protocol for PNFs.") def https_app(**kwargs): |