Skip to content

Commit

Permalink
feat(test): update after Second Review
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipTamb committed Oct 23, 2023
1 parent a2f8716 commit 78a49b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 109 deletions.
157 changes: 49 additions & 108 deletions manual-tests/automated-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import os
import platform
import shutil
import signal
import time

import psutil
import yaml
from yaml.loader import SafeLoader


class ZF_conf:
Expand Down Expand Up @@ -73,50 +70,40 @@ def find(pattern, path):
"--build",
nargs="?",
type=str,
default="False",
default="debug",
help="Specifies a different directory for Zenoh-Flow artifacts (default=debug)",
)
parser.add_argument(
"-z",
"--zenohd",
nargs="?",
type=str,
default="/.local/bin/zenohd",
help="Specifies a different path for the zenohd process (default=/.local/bin/zenohd)",
default=os.path.expanduser("~") + "/.local/bin/zenohd",
help=f"Specifies a different path for the zenohd process (default={os.path.expanduser('~')}/.local/bin/zenohd)",
)
parser.add_argument(
"-c",
"--zfctl",
nargs="?",
type=str,
default="/.config/zenoh-flow/zfctl.json",
help="Specifies a different path for the zenoctl process (default=/.config/zenoh-flow/zfctl.json)",
default=os.path.expanduser("~") + "/.config/zenoh-flow/zfctl.json",
help=f"Specifies a different path for the zenoctl process (default={os.path.expanduser('~')}/.config/zenoh-flow/zfctl.json)",
)
parser.add_argument(
"-p",
"--plugin",
nargs="?",
type=str,
default="/.config/zenoh-flow/zenoh-zf-plugin-01.json",
help="Specifies a different path for Zenoh-Flow plugin file (default=/.config/zenoh-flow/zenoh-zf-plugin-01.json)",
default=os.path.expanduser("~") + "/.config/zenoh-flow/zenoh-zf-plugin-01.json",
help=f"Specifies a different path for Zenoh-Flow plugin file (default={os.path.expanduser('~')}/.config/zenoh-flow/zenoh-zf-plugin-01.json)",
)
args = parser.parse_args()

home_path = os.path.expanduser("~")
zenoh_release_flag = args.build

if (
args.zenohd == "/.local/bin/zenohd"
or args.zfctl == "/.config/zenoh-flow/zfctl.json"
):
print(home_path)
zf_conf.zenohd_path = home_path + str(args.zenohd)
zf_conf.zfctl_path = home_path + str(args.zfctl)
zf_conf.zf_plugin_path = home_path + str(args.plugin)
else:
zf_conf.zenohd_path = args.zenohd
zf_conf.zfctl_path = args.zfctl
zf_conf.zf_plugin_path = args.plugin
zf_conf.zenohd_path = args.zenohd
zf_conf.zfctl_path = args.zfctl
zf_conf.zf_plugin_path = args.plugin

print("[Info] Looking for paths...")
manual_tests_path = os.getcwd()
Expand Down Expand Up @@ -185,11 +172,11 @@ def find(pattern, path):
zf_command["zenohd_cmd"] = zf_conf.zenohd_path + " -c " + zf_conf.zf_plugin_path
print(f'Lauch Zenoh with Zenoh-Flow plugin: \n {zf_command["zenohd_cmd"]}')
zf_command["runtimes_cmd"] = zf_conf.zfctl_path + " list runtimes"
print(f'show the list of runtimes: \n {zf_command["runtimes_cmd"]}')
print(f'Show runtimes list: \n {zf_command["runtimes_cmd"]}')
zf_command["dataflow_yaml_cmd"] = zf_conf.zfctl_path + " launch " + data_flow_path
print(f'Lauch Zenoh-Flow configuration: \n {zf_command["dataflow_yaml_cmd"]}')
zf_command["instances_cmd"] = zf_conf.zfctl_path + " list instances"
print(f'show list of Zenoh-Flow instances: \n {zf_command["instances_cmd"]}')
print(f'Show Zenoh-Flow list instances: \n {zf_command["instances_cmd"]}')
else:
zf_command["zenohd_cmd"] = zf_conf.zenohd_path + " -c " + zf_conf.zf_plugin_path
print(f'Lauch Zenoh with Zenoh-Flow plugin: \n {zf_command["zenohd_cmd"]}')
Expand Down Expand Up @@ -222,15 +209,13 @@ def find(pattern, path):
)
print(f'show list of Zenoh-Flow instances: \n {zf_command["instances_cmd"]}')

print("[Info] Looking for Zenohd process...")
print("[Info] Killing extra `zenohd` processes...")
process_name = "zenohd"
pid = None
for process in psutil.process_iter():
if process_name in process.name():
pid = process.pid
print(f"[Info] kill process: {pid}")
os.kill(pid, signal.SIGKILL)

print(f"[Info] kill process: {process.pid}")
process.kill()

print(f'[Info] Launching Zenod process: {zf_command["zenohd_cmd"]}')
launch_zenohd = os.popen(zf_command["zenohd_cmd"])
Expand All @@ -245,98 +230,54 @@ def find(pattern, path):
print(f"[Info] Test {process_name} process pid {pid}")
zf_conf.zenohd_process = pid
if zf_conf.zenohd_process is not None:
print(f'[Info] Launching list runtimes command: {zf_command["runtimes_cmd"]}')
launch_runtimes = os.popen(zf_command["runtimes_cmd"])
runtimes_string = launch_runtimes.read().split()
for i in range(runtimes_string.__len__()):
if runtimes_string[i].__len__() == 32 and runtimes_string[i - 2][0] == "+":
print("[Info] test runtime: SUCCESS.")
print(f"[Info] UUID runtime: {runtimes_string[i]}")
zf_conf.uuid_runtimes = runtimes_string[i]
if zf_conf.uuid_runtimes is None:
print("[Info] test runtime: FAILED.")

print(f'[Info] Launching Zenoh-Flow example: {zf_command["dataflow_yaml_cmd"]}')

launch_zf_yaml = os.popen(zf_command["dataflow_yaml_cmd"])

zf_example_string = launch_zf_yaml.read()
print(f"[Info] zf_example_string: {zf_example_string}")
if zf_example_string.__len__() == 0:
print("[Error] Zenoh-Flow example: FAILED.")
else:
zf_conf.uuid_runtimes = zf_example_string
print(f"[Info] Zenoh-Flow example UUID: {zf_conf.uuid_runtimes}")

print(f'[Info] Launching list instances: {zf_command["instances_cmd"]}')
launch_instances = os.popen(zf_command["instances_cmd"])
count = 0
instances_string = launch_instances.read().split()
for i in range(instances_string.__len__()):
if instances_string[i][0] == "+":
count = count + 1
if count <= 2:
print("[Error] test data flow: FAILED.")
exit()
else:
print("[Info] test data flow instance: SUCCESS.")
instance["uuid_instances"] = instances_string[23]
instance["flow"] = instances_string[25]
instance["operators"] = instances_string[27]
instance["sinks"] = instances_string[29]
instance["sources"] = instances_string[31]
instance["connectors"] = instances_string[33]
instance["links"] = instances_string[35]
else:
print("[Error] test zenohd process: FAILED.")

time.sleep(1)

with open(data_flow_path, "r") as f:
try:
data = yaml.load(f, Loader=SafeLoader)
except yaml.YAMLError as e:
print(f"[Error] {e}")

if str(tuple(data["sources"]).__len__()) == instance["sources"]:
print(
f'[Info] test active Source nodes: SUCCESS, the active Source nodes [{str(tuple(data["sources"]).__len__())}] are equal to declared Source nodes [{instance["sources"]}]'
)
if str(tuple(data["sinks"]).__len__()) == instance["sinks"]:
print(
f'[Info] test active Sink nodes: SUCCESS, the active Sink nodes [{str(tuple(data["sinks"]).__len__())}] are equal to those declared Sinks nodes [{instance["sinks"]}]'
)
if str(tuple(data["operators"]).__len__()) == instance["operators"]:
print(
f'[Info] test active Operator nodes: SUCCESS, the active Operator nodes [{str(tuple(data["operators"]).__len__())}] are equal declared Operator nodes [{instance["operators"]}]'
)
if (
str(tuple(data["sources"]).__len__()) != instance["sources"]
or str(tuple(data["sinks"]).__len__()) != instance["sinks"]
or str(tuple(data["operators"]).__len__()) != instance["operators"]
):
print("[Error] Test Zenoh-Flow configuration nodesSome nodes: FAILED.")

os.popen(
"curl -X PUT -H 'content-type:text/plain' -d 'Test' http://localhost:8000/zf/getting-started/hello"
if os.path.exists("/tmp/greetings.txt"):
txt_res = open("/tmp/greetings.txt", "r")
res = txt_res.read().splitlines()
previus_index = res.__len__()
curl_getting_started = "curl -X PUT -H 'content-type:text/plain' -d 'Test' http://localhost:8000/zf/getting-started/hello"
print(
f"[Info] Launching CURL request to `zf/getting-started/hello`: \n {curl_getting_started}\n"
)
os.popen(curl_getting_started)
time.sleep(1)
txt_res = open("/tmp/greetings.txt", "r")
res = txt_res.read()
if res.split()[1] == "Test!":
print(f"\n[Info] Test Recive: SUCCESS, {res}")
res = txt_res.read().splitlines()
print("res.__len__()", res.__len__())
if res.__len__() > previus_index and previus_index != 1:
result = res[previus_index:]
else:
print("\n[Error] Test Recive: FAILED.")

process_name = "zenohd"
pid = None
for process in psutil.process_iter():
if process_name in process.name():
pid = process.pid
print(f"[Info] kill process: {pid}")
os.kill(pid, signal.SIGKILL)

print("\n[Info] Commands:")
print(zf_command["zenohd_cmd"])
print(zf_command["runtimes_cmd"])
print(zf_command["dataflow_yaml_cmd"])
print(zf_command["instances_cmd"])
result = res

for i in range(result.__len__()):
if result[i] == "Hello, Test!":
print(f"\n[Info] Test Recive: SUCCESS, {result[i]}")
else:
print("\n[Error] Test Recive: FAILED.")

print("\n[Info] Killing `zenohd` processes...")
process_name = "zenohd"
pid = None
for process in psutil.process_iter():
if process_name in process.name():
print(f"[Info] kill process: {process.pid}")
process.kill()

print("\n[Info] Commands:")
print(zf_command["zenohd_cmd"])
print(zf_command["runtimes_cmd"])
print(zf_command["dataflow_yaml_cmd"])
print(zf_command["instances_cmd"])
1 change: 0 additions & 1 deletion manual-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
psutil==5.9.6
PyYAML==6.0.1

0 comments on commit 78a49b6

Please sign in to comment.