2024-01-23 19:06:10 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-10-26 14:53:56 +08:00
|
|
|
# Copyright 2021 Memgraph Ltd.
|
|
|
|
#
|
|
|
|
# Use of this software is governed by the Business Source License
|
|
|
|
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
# License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
#
|
|
|
|
# As of the Change Date specified in that file, in accordance with
|
|
|
|
# the Business Source License, use of this software will be governed
|
|
|
|
# by the Apache License, Version 2.0, included in the file
|
|
|
|
# licenses/APL.txt.
|
|
|
|
|
2021-01-16 02:04:44 +08:00
|
|
|
import atexit
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import subprocess
|
2023-06-29 17:44:55 +08:00
|
|
|
import time
|
2022-02-17 17:36:10 +08:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-06-20 18:28:42 +08:00
|
|
|
import interactive_mg_runner
|
2023-06-27 04:43:34 +08:00
|
|
|
import yaml
|
2021-01-16 02:04:44 +08:00
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
PROJECT_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", ".."))
|
|
|
|
BUILD_DIR = os.path.join(PROJECT_DIR, "build")
|
|
|
|
|
2021-03-19 15:43:48 +08:00
|
|
|
log = logging.getLogger("memgraph.tests.e2e")
|
2021-01-16 02:04:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
def load_args():
|
|
|
|
parser = ArgumentParser()
|
2021-05-19 00:28:17 +08:00
|
|
|
parser.add_argument("--workloads-root-directory", required=True)
|
2021-01-16 02:04:44 +08:00
|
|
|
parser.add_argument("--workload-name", default=None, required=False)
|
2023-06-29 17:44:55 +08:00
|
|
|
parser.add_argument("--debug", default=False, required=False)
|
2021-01-16 02:04:44 +08:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2021-05-19 00:28:17 +08:00
|
|
|
def load_workloads(root_directory):
|
|
|
|
workloads = []
|
2022-02-17 17:36:10 +08:00
|
|
|
for file in Path(root_directory).rglob("*.yaml"):
|
2021-05-19 00:28:17 +08:00
|
|
|
with open(file, "r") as f:
|
2022-02-17 17:36:10 +08:00
|
|
|
workloads.extend(yaml.load(f, Loader=yaml.FullLoader)["workloads"])
|
2021-05-19 00:28:17 +08:00
|
|
|
return workloads
|
2021-01-16 02:04:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
def run(args):
|
2021-05-19 00:28:17 +08:00
|
|
|
workloads = load_workloads(args.workloads_root_directory)
|
2021-01-16 02:04:44 +08:00
|
|
|
for workload in workloads:
|
2022-02-17 17:36:10 +08:00
|
|
|
workload_name = workload["name"]
|
|
|
|
if args.workload_name is not None and args.workload_name != workload_name:
|
2021-01-16 02:04:44 +08:00
|
|
|
continue
|
|
|
|
log.info("%s STARTED.", workload_name)
|
2023-06-27 04:43:34 +08:00
|
|
|
|
2021-01-16 02:04:44 +08:00
|
|
|
# Setup.
|
|
|
|
@atexit.register
|
2023-12-14 21:36:33 +08:00
|
|
|
def cleanup(keep_directories=True):
|
|
|
|
interactive_mg_runner.stop_all(keep_directories)
|
2022-02-17 17:36:10 +08:00
|
|
|
|
2023-10-26 00:27:44 +08:00
|
|
|
if "pre_set_workload" in workload:
|
|
|
|
binary = os.path.join(BUILD_DIR, workload["pre_set_workload"])
|
|
|
|
subprocess.run([binary], check=True, stderr=subprocess.STDOUT)
|
|
|
|
|
2022-06-20 18:28:42 +08:00
|
|
|
if "cluster" in workload:
|
|
|
|
procdir = ""
|
2022-02-17 17:36:10 +08:00
|
|
|
if "proc" in workload:
|
2022-06-20 18:28:42 +08:00
|
|
|
procdir = os.path.join(BUILD_DIR, workload["proc"])
|
2022-06-29 16:14:23 +08:00
|
|
|
interactive_mg_runner.start_all(workload["cluster"], procdir)
|
2022-06-20 18:28:42 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
if args.debug:
|
|
|
|
hosts = subprocess.check_output("pgrep memgraph", shell=True)
|
|
|
|
print(f"PID: {hosts}")
|
|
|
|
time.sleep(10)
|
|
|
|
|
2021-01-16 02:04:44 +08:00
|
|
|
# Test.
|
2022-02-17 17:36:10 +08:00
|
|
|
mg_test_binary = os.path.join(BUILD_DIR, workload["binary"])
|
|
|
|
subprocess.run([mg_test_binary] + workload["args"], check=True, stderr=subprocess.STDOUT)
|
2021-01-16 02:04:44 +08:00
|
|
|
# Validation.
|
2022-06-20 18:28:42 +08:00
|
|
|
if "cluster" in workload:
|
|
|
|
for name, config in workload["cluster"].items():
|
2023-06-27 04:43:34 +08:00
|
|
|
mg_instance = interactive_mg_runner.MEMGRAPH_INSTANCES[name]
|
|
|
|
# Explicitely check if there are validation queries and skip if
|
|
|
|
# nothing is to validate. If setup queries are dealing with
|
|
|
|
# users, any new connection requires auth details.
|
|
|
|
validation_queries = config.get("validation_queries", [])
|
|
|
|
if len(validation_queries) == 0:
|
|
|
|
continue
|
|
|
|
# NOTE: If the setup quries create users AND there are some
|
|
|
|
# validation queries, the connection here has to get the right
|
|
|
|
# username/password.
|
|
|
|
conn = mg_instance.get_connection()
|
|
|
|
for validation in validation_queries:
|
|
|
|
data = mg_instance.query(validation["query"], conn)[0][0]
|
2022-06-20 18:28:42 +08:00
|
|
|
assert data == validation["expected"]
|
2023-06-27 04:43:34 +08:00
|
|
|
conn.close()
|
2023-12-14 21:36:33 +08:00
|
|
|
cleanup(keep_directories=False)
|
2021-01-16 02:04:44 +08:00
|
|
|
log.info("%s PASSED.", workload_name)
|
|
|
|
|
|
|
|
|
2022-02-17 17:36:10 +08:00
|
|
|
if __name__ == "__main__":
|
2021-01-16 02:04:44 +08:00
|
|
|
args = load_args()
|
2022-02-17 17:36:10 +08:00
|
|
|
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(asctime)s %(name)s] %(message)s")
|
2021-01-16 02:04:44 +08:00
|
|
|
run(args)
|