diff --git a/test/streaming-sim/VerifySimResults.py b/test/streaming-sim/VerifySimResults.py new file mode 100644 index 0000000000000000000000000000000000000000..e4479c657f34b815c432695818c4ccf3a9b3708c --- /dev/null +++ b/test/streaming-sim/VerifySimResults.py @@ -0,0 +1,66 @@ +import sys +import urllib.parse +import urllib.request + +queryReference = { + "cpu_usage" : "SELECT count(*) FROM \"CLMCMetrics\".\"autogen\".\"cpu_usage\"", + "ipendpoint_route" : "SELECT count(*) FROM \"CLMCMetrics\".\"autogen\".\"ipendpoint_route\"", + "mpegdash_service" : "SELECT count(*) FROM \"CLMCMetrics\".\"autogen\".\"mpegdash_service\"", + "net_port_io" : "SELECT count(*) FROM \"CLMCMetrics\".\"autogen\".\"net_port_io\"", + "vm_res_alloc" : "SELECT count(*) FROM \"CLMCMetrics\".\"autogen\".\"vm_res_alloc\"" +} + +resultReference = { + "cpu_usage" : "{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"cpu_usage\",\"columns\":[\"time\",\"count_cpu_active_time\",\"count_cpu_idle_time\",\"count_cpu_usage\"],\"values\":[[\"1970-01-01T00:00:00Z\",7200,7200,7200]]}]}]}", + "ipendpoint_route" : "{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"ipendpoint_route\",\"columns\":[\"time\",\"count_http_requests_fqdn_m\",\"count_network_fqdn_latency\"],\"values\":[[\"1970-01-01T00:00:00Z\",7200,7200]]}]}]}", + "mpegdash_service" : "{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"mpegdash_service\",\"columns\":[\"time\",\"count_avg_response_time\",\"count_peak_response_time\",\"count_requests\"],\"values\":[[\"1970-01-01T00:00:00Z\",7200,7200,7200]]}]}]}", + "net_port_io" : "{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"net_port_io\",\"columns\":[\"time\",\"count_RX_BYTES_PORT_M\",\"count_TX_BYTES_PORT_M\"],\"values\":[[\"1970-01-01T00:00:00Z\",7200,7200]]}]}]}", + "vm_res_alloc" : "{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"vm_res_alloc\",\"columns\":[\"time\",\"count_cpu\",\"count_memory\",\"count_storage\"],\"values\":[[\"1970-01-01T00:00:00Z\",12,12,12]]}]}]}" +} + +def checkResult( query, queryResult ): + result = False + + if query != None and queryResult != None: + if ( query in resultReference ): + if ( resultReference[query] == queryResult ): + print ( "Result correct" ) + result = True + else: + print ( "Incorrect result for query: " + query ) + print ( "Expected = " + resultReference[query] ) + print ( "Result = " + queryResult ) + else: + print( "Could not find query result for: " + query ) + else: + print( "Could not check result: invalid parameters" ) + + return result + +def sendInfluxQuery( url, query ): + query = urllib.parse.urlencode( {'q': query} ) + query = query.encode( 'ascii' ) + req = urllib.request.Request( url + '/query ', query ) + result = urllib.request.urlopen( req ) + + return result.read().decode("utf-8").strip() + +# Entry point +# --------------------------------------------------------------------------------------- +testFailed = False + +for key in list( queryReference ): + query = queryReference[key] + result = sendInfluxQuery( "http://:8086", query ) + + if checkResult( key, result ) == False: + testFailed = True + break + +if testFailed : + print( "Failed simulation result test" ) + sys.exit( 1 ) +else: + print( "Test succeeded" ) + +sys.exit( 0 ) \ No newline at end of file