From 6285913758e7122b0df9121ee227b57260d9d201 Mon Sep 17 00:00:00 2001 From: shivamcandela Date: Tue, 22 Dec 2020 23:37:16 +0530 Subject: [PATCH] added test status and path corrections --- py-scripts/test_utility.py | 73 ++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/py-scripts/test_utility.py b/py-scripts/test_utility.py index f1aa6e63..afe728b2 100644 --- a/py-scripts/test_utility.py +++ b/py-scripts/test_utility.py @@ -2,7 +2,7 @@ """ Candela Technologies Inc. -Info : Standard Script for Webconsole test utility +Info : Standard Script for Layer 4 Testing Date : Author : Shivam Thakur @@ -22,7 +22,12 @@ import datetime import time import matplotlib.pyplot as plt import threading -runtime_path = "../py-run/runtime.json" +import re +import json +import os +webconsole_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd()))) +updates_path = webconsole_dir + "/web_json/updates.js" + class ClientVisualization(LFCliBase, threading.Thread): def __init__(self, lfclient_host="localhost", lfclient_port=8080, num_clients= 64, max_data= 120, thread_id=None, _debug_on=False, _exit_on_error=False, _exit_on_fail=False): @@ -49,11 +54,12 @@ class ClientVisualization(LFCliBase, threading.Thread): self.ip = 0 self.down = 0 self.phantom = 0 - for i in self.json_get("/port/list?fields=port,alias,parent%20dev,down,phantom,ip,port%20type")[ - 'interfaces']: + for i in self.json_get("/port/list?fields=port,alias,parent%20dev,down,phantom,ip,port%20type")['interfaces']: for j in i: + print(i[j]['port type']) if i[j]['port type'] == "WIFI-STA" and i[j]['parent dev'] == "wiphy1" and i[j]['alias'] != 'wlan1': + #print(j) if i[j]['down'] == False and i[j]['phantom'] == False and i[j]['ip'] == '0.0.0.0': self.scanning += 1 elif i[j]['down'] == False and i[j]['phantom'] == True: @@ -77,9 +83,6 @@ class ClientVisualization(LFCliBase, threading.Thread): if len(self.client_data[i]) >= self.max_data: self.client_data[i].pop(0) time.sleep(1) - - - if self.stopped(): break @@ -89,7 +92,7 @@ class CreateHTML(): self.head = """ - Client Connectivity Test + """+test_name+"""
@@ -200,6 +203,7 @@ class CreateHTML(): for data in test_results['detail']['data']: self.detail_result = self.detail_result + "" + print("shivam") print(data) for i in data: print(data[i]) @@ -240,10 +244,59 @@ class CreateHTML(): +class RuntimeUpdates(): + def __init__(self, session_id, init_data): + self.session_id = session_id + self.init_data = init_data + f = open(updates_path, 'r+') + data = f.read() + f.close() + obj = data[data.find('{'): data.rfind('}') + 1] + obj = re.sub('[\']', '"', obj) + data = json.loads(obj) + print(data) + data["web_updates"].append({"ID": self.session_id, "data": self.init_data}) + print(data) + f = open(updates_path, 'r+') + f.seek(0) + f.truncate() + f.write("var updates = " + str(data) + ";") + f.close() + + def send_update(self, update_data): + f = open(updates_path, 'r+') + data = f.read() + f.close() + obj = data[data.find('{'): data.rfind('}') + 1] + obj = re.sub('[\']', '"', obj) + data = json.loads(obj) + + for update in data["web_updates"]: + if update["ID"] == self.session_id: + update["data"] = update_data + print(data) + f = open(updates_path, 'r+') + f.seek(0) + f.truncate() + f.write("var updates = " + str(data) + ";") + f.close() + + if __name__ == "__main__": thread1 = ClientVisualization(lfclient_host="192.168.200.15", thread_id=1) thread1.start() - for i in range(30): - print(thread1.client_data) + for i in range(0, 100): + time.sleep(1) + #print(thread1.client_data) thread1.stop() + # obj = RuntimeUpdates("1", {"test_status": 1, "data": "None"}) + # for i in range(0, 10): + # time.sleep(3) + # print(i) + # obj.send_update({"test_status": i, "data": "None"}) + # thread1 = ClientVisualization(lfclient_host="192.168.200.15", thread_id=1) + # thread1.start() + # for i in range(30): + # print(thread1.client_data) + # thread1.stop()