forked from jinengandhi-intel/curated_apps
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
96 lines (86 loc) · 4.27 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pytest
import os
from data.constants import *
from libs import utils
import re
@pytest.fixture(scope="session", autouse=True)
def curated_setup():
print_env_variables()
cleanup()
os.mkdir(LOGS)
print("Cloning and checking out Contrib Git Repo")
utils.run_subprocess(CONTRIB_GIT_CMD)
utils.run_subprocess(GIT_CHECKOUT_CMD, ORIG_CURATED_PATH)
if REBASE_CONTRIB_GIT_REPO:
utils.run_subprocess(REBASE_GIT_REPO_CMD, ORIG_CURATED_PATH)
utils.run_subprocess(FETCH_REBASE_REPO_CMD, ORIG_CURATED_PATH)
utils.run_subprocess(REBASE_BRANCH_CMD, ORIG_CURATED_PATH)
update_env_variables()
def update_env_variables():
if os.environ["gramine_commit"]:
update_gramine_branch(os.environ["gramine_commit"])
if os.environ["gsc_repo"] or os.environ["gsc_commit"]:
update_gsc(os.environ["gsc_commit"], os.environ["gsc_repo"])
def print_env_variables():
os.environ["gramine_commit"] = os.environ.get("gramine_commit", "")
os.environ["gsc_repo"] = os.environ.get("gsc_repo", "")
os.environ["gsc_commit"] = os.environ.get("gsc_commit", "")
os.environ["contrib_repo"] = os.environ.get("contrib_repo", "")
os.environ["contrib_branch"] = os.environ.get("contrib_branch", "")
os.environ["rebase_contrib_repo"] = os.environ.get("rebase_contrib_repo", "")
os.environ["rebase_contrib_branch"] = os.environ.get("rebase_contrib_branch", "")
print("\n\n############################################################################")
print("Printing the environment variables")
print("Gramine Commit: ", os.environ["gramine_commit"])
print("GSC Repo: ", os.environ["gsc_repo"])
print("GSC Commit: ", os.environ["gsc_commit"])
print("Contrib Repo: ", os.environ["contrib_repo"])
print("Contrib Commit: ", os.environ["contrib_branch"])
print("Rebase Contrib Repo: ", os.environ["rebase_contrib_repo"])
print("Rebase Contrib Commit: ", os.environ["rebase_contrib_branch"])
print("############################################################################\n\n")
@pytest.fixture(scope="function", autouse=True)
def copy_repo():
utils.run_subprocess("sudo rm -rf {}".format(REPO_PATH), FRAMEWORK_PATH)
utils.run_subprocess("cp -rf {} {}".format(ORIG_CURATED_PATH, REPO_PATH))
def update_gramine_branch(commit):
copy_cmd = "cp -f config.yaml.template config.yaml"
gsc_tag = utils.run_subprocess(f"git ls-remote --sort='version:refname' --tags {GSC_MAIN_REPO} | tail --lines=1 | cut --delimiter=\"/\" --fields=3")
if not "v1" in commit:
utils.run_subprocess(f"cp -rf helper-files/{VERIFIER_TEMPLATE} {VERIFIER_DOCKERFILE}")
sed_string = "sed -i \"s/Branch.*master.*\\|Branch.*{}.*/Branch: '{}'/\" config.yaml".format(gsc_tag, commit.replace('/', '\\/'))
utils.update_file_contents(copy_cmd, (copy_cmd + "\n" + sed_string), CURATION_SCRIPT)
utils.update_file_contents("git checkout(.*)", f"git checkout {commit}", VERIFIER_DOCKERFILE)
def update_gsc(gsc_commit='', gsc_repo=''):
if gsc_repo:
utils.update_file_contents(GSC_MAIN_REPO, gsc_repo, CURATION_SCRIPT)
if gsc_commit:
utils.update_file_contents("git checkout(.*)", f"git checkout {gsc_commit}", CURATION_SCRIPT)
@pytest.fixture(scope="class", autouse=True)
def teardown():
yield
utils.execute_cmd("docker system prune -f --all", timeout=300)
utils.execute_cmd("sudo apt remove gramine -y", timeout=60)
@pytest.fixture(scope="session", autouse=True)
def test_gramine_gsc_version():
yield
test_result = utils.verify_build_env_details()
assert test_result
@pytest.fixture(scope="function", autouse=True)
def cleanup_ports(ports=None):
if ports == None:
ports = [MYSQL_PORT, MARIADB_PORT, OVMS_PORT, TFSERVING_PORT]
for port in ports:
try:
out = utils.run_subprocess(f"sudo lsof -P -i:{port}")
if out:
proc_pid = re.sub("\s+", " ", out.split("\n")[1]).split(" ")[1]
utils.terminate_process(pid=int(proc_pid))
except:
pass
def cleanup():
utils.run_subprocess(f"rm -rf {LOGS}")
utils.run_subprocess("docker system prune -f --all")
utils.stop_docker_process("server_dcap")
print("Cleaning old contrib repo")
utils.run_subprocess("rm -rf {}".format(ORIG_CURATED_PATH))