Skip to content

Commit

Permalink
Finally update the listeners
Browse files Browse the repository at this point in the history
Hopefully this will work for both v2 and v3 Listeners
Issue #174
  • Loading branch information
damies13 committed Apr 1, 2024
1 parent 459e7fb commit 16b9048
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions rfswarm_agent/rfswarm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,7 @@ def create_V3_listner_file(self):
fd.append("import socket")
fd.append("from datetime import datetime")
fd.append("import time")
fd.append("import random")
fd.append("import requests")
fd.append("import inspect")
fd.append("import threading")
Expand All @@ -1514,6 +1515,9 @@ def create_V3_listner_file(self):
fd.append(" robot = 0")
fd.append(" iter = 0")
fd.append(" seq = 0")
fd.append(" injectsleep = False")
fd.append(" sleepminimum = 15")
fd.append(" sleepmaximum = 45")
fd.append("")
fd.append(" def start_suite(self, suite: running.TestSuite, result: result.TestSuite):")
fd.append(" if 'RFS_DEBUGLEVEL' in result.metadata:")
Expand All @@ -1534,6 +1538,23 @@ def create_V3_listner_file(self):
fd.append(" if 'RFS_EXCLUDELIBRARIES' in result.metadata:")
fd.append(" self.excludelibraries = result.metadata['RFS_EXCLUDELIBRARIES'].split(\",\")")
fd.append(" self.debugmsg(6, 'excludelibraries: ', self.excludelibraries)")
fd.append(" if 'RFS_INJECTSLEEP' in result.metadata:")
fd.append(" self.injectsleep = result.metadata['RFS_INJECTSLEEP']")
fd.append(" self.debugmsg(6, 'injectsleep: ', self.injectsleep)")
fd.append(" if 'RFS_SLEEPMINIMUM' in result.metadata:")
fd.append(" self.sleepminimum = result.metadata['RFS_SLEEPMINIMUM']")
fd.append(" self.debugmsg(6, 'sleepminimum: ', self.sleepminimum)")
fd.append(" if 'RFS_SLEEPMAXIMUM' in result.metadata:")
fd.append(" self.sleepmaximum = result.metadata['RFS_SLEEPMAXIMUM']")
fd.append(" self.debugmsg(6, 'sleepmaximum: ', self.sleepmaximum)")
fd.append(" self.seedseed()")
fd.append("")
fd.append(" def seedseed(self):")
fd.append(" random.seed()")
fd.append(" r1 = random.random()%1000")
fd.append(" random.seed(r1)")
fd.append(" r2 = random.random()%10000")
fd.append(" random.seed(r2)")
fd.append("")
fd.append(" def log_message(self, message: result.Message):")
# fd.append(" self.debugmsg(8, 'message[\\'message\\']: ', message['message'])")
Expand Down Expand Up @@ -1601,11 +1622,27 @@ def create_V3_listner_file(self):
# fd.append(" self.send_result(payload)")
fd.append(" t = threading.Thread(target=self.send_result, args=(payload,))")
fd.append(" t.start()")
fd.append("")
fd.append(" if str(self.injectsleep).lower in ('true', 't', 'yes', '1'):")
fd.append(" if 'lineno' in data.to_dict():")
fd.append(" tmeslp = self.randsleep(self.sleepminimum, self.sleepmaximum)")
fd.append(" index = parent.to_dict()['body'].index(data.to_dict())")
fd.append(" data.parent.body.insert(index + 1, running.Keyword('Sleep', [tmeslp, 'Sleep added by RFSwarm']))")
fd.append("")
fd.append(" else:")
fd.append(" self.debugmsg(5, attrs['owner'], 'is an excluded library')")
fd.append(" ")
fd.append(" self.msg = None")
fd.append("")
fd.append(" def randsleep(self, min, max):")
fd.append(" isfloat = False")
fd.append(" if "." in str(min) or "." in str(max):")
fd.append(" isfloat = True")
fd.append(" if isfloat:")
fd.append(" return random.uniform(float(min), float(max))")
fd.append(" else:")
fd.append(" return random.randint(int(min), int(max))")
fd.append("")
fd.append(" def debugmsg(self, lvl, *msg):")
fd.append(" msglst = []")
fd.append(" prefix = \"\"")
Expand Down Expand Up @@ -1668,6 +1705,7 @@ def create_V2_listner_file(self):
fd.append("import socket")
fd.append("from datetime import datetime")
fd.append("import time")
fd.append("import random")
fd.append("import requests")
fd.append("import inspect")
fd.append("import threading")
Expand All @@ -1684,6 +1722,9 @@ def create_V2_listner_file(self):
fd.append(" robot = 0")
fd.append(" iter = 0")
fd.append(" seq = 0")
fd.append(" injectsleep = False")
fd.append(" sleepminimum = 15")
fd.append(" sleepmaximum = 45")
fd.append("")
fd.append(" def start_suite(self, name, attrs):")
fd.append(" if 'RFS_DEBUGLEVEL' in attrs['metadata']:")
Expand All @@ -1704,6 +1745,23 @@ def create_V2_listner_file(self):
fd.append(" if 'RFS_EXCLUDELIBRARIES' in attrs['metadata']:")
fd.append(" self.excludelibraries = attrs['metadata']['RFS_EXCLUDELIBRARIES'].split(\",\")")
fd.append(" self.debugmsg(6, 'excludelibraries: ', self.excludelibraries)")
fd.append(" if 'RFS_INJECTSLEEP' in result.metadata:")
fd.append(" self.injectsleep = result.metadata['RFS_INJECTSLEEP']")
fd.append(" self.debugmsg(6, 'injectsleep: ', self.injectsleep)")
fd.append(" if 'RFS_SLEEPMINIMUM' in result.metadata:")
fd.append(" self.sleepminimum = result.metadata['RFS_SLEEPMINIMUM']")
fd.append(" self.debugmsg(6, 'sleepminimum: ', self.sleepminimum)")
fd.append(" if 'RFS_SLEEPMAXIMUM' in result.metadata:")
fd.append(" self.sleepmaximum = result.metadata['RFS_SLEEPMAXIMUM']")
fd.append(" self.debugmsg(6, 'sleepmaximum: ', self.sleepmaximum)")
fd.append(" self.seedseed()")
fd.append("")
fd.append(" def seedseed(self):")
fd.append(" random.seed()")
fd.append(" r1 = random.random()%1000")
fd.append(" random.seed(r1)")
fd.append(" r2 = random.random()%10000")
fd.append(" random.seed(r2)")
fd.append("")
fd.append(" def log_message(self, message):")
# fd.append(" self.debugmsg(8, 'message[\\'message\\']: ', message['message'])")
Expand Down Expand Up @@ -1762,11 +1820,25 @@ def create_V2_listner_file(self):
# fd.append(" self.send_result(payload)")
fd.append(" t = threading.Thread(target=self.send_result, args=(payload,))")
fd.append(" t.start()")
fd.append("")
fd.append(" if str(self.injectsleep).lower in ('true', 't', 'yes', '1'):")
fd.append(" tmeslp = self.randsleep(self.sleepminimum, self.sleepmaximum)")
fd.append(" BuiltIn().run_keyword('Sleep', tmeslp, 'Sleep added by RFSwarm')")
fd.append("")
fd.append(" else:")
fd.append(" self.debugmsg(5, attrs['libname'], 'is an excluded library')")
fd.append(" ")
fd.append(" self.msg = None")
fd.append("")
fd.append(" def randsleep(self, min, max):")
fd.append(" isfloat = False")
fd.append(" if "." in str(min) or "." in str(max):")
fd.append(" isfloat = True")
fd.append(" if isfloat:")
fd.append(" return random.uniform(float(min), float(max))")
fd.append(" else:")
fd.append(" return random.randint(int(min), int(max))")
fd.append("")
fd.append(" def debugmsg(self, lvl, *msg):")
fd.append(" msglst = []")
fd.append(" prefix = \"\"")
Expand Down

0 comments on commit 16b9048

Please sign in to comment.