ci/cd - fix log() call
This commit is contained in:
parent
b95d1bc6d5
commit
88a2955173
|
@ -21,10 +21,7 @@ on:
|
|||
|
||||
jobs:
|
||||
tests:
|
||||
strategy:
|
||||
matrix:
|
||||
runs-on: ${{ fromJSON(inputs.RUNS_ON) }}
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
runs-on: ${{ fromJSON(inputs.RUNS_ON) }}
|
||||
steps:
|
||||
# Prepare
|
||||
- name: Checkout source code
|
||||
|
|
|
@ -167,35 +167,35 @@ jobs:
|
|||
uses: ./.github/workflows/staging-tests.yml
|
||||
with:
|
||||
TYPE: docker
|
||||
RUNS_ON: '["self-hosted", "bw-docker"]'
|
||||
RUNS_ON: "['self-hosted', 'bw-docker']"
|
||||
secrets: inherit
|
||||
tests-autoconf:
|
||||
needs: [create-infra-autoconf]
|
||||
uses: ./.github/workflows/staging-tests.yml
|
||||
with:
|
||||
TYPE: autoconf
|
||||
RUNS_ON: '["self-hosted", "bw-autoconf"]'
|
||||
RUNS_ON: "['self-hosted', 'bw-autoconf']"
|
||||
secrets: inherit
|
||||
tests-swarm:
|
||||
needs: [create-infra-swarm]
|
||||
uses: ./.github/workflows/staging-tests.yml
|
||||
with:
|
||||
TYPE: swarm
|
||||
RUNS_ON: '["self-hosted", "bw-swarm"]'
|
||||
RUNS_ON: "['self-hosted', 'bw-swarm']"
|
||||
secrets: inherit
|
||||
tests-k8s:
|
||||
needs: [create-infra-k8s]
|
||||
uses: ./.github/workflows/staging-tests.yml
|
||||
with:
|
||||
TYPE: k8s
|
||||
RUNS_ON: '["ubuntu-latest"]'
|
||||
RUNS_ON: "['ubuntu-latest']"
|
||||
secrets: inherit
|
||||
tests-linux:
|
||||
needs: [create-infra-linux]
|
||||
uses: ./.github/workflows/staging-tests.yml
|
||||
with:
|
||||
TYPE: linux
|
||||
RUNS_ON: '["self-hosted", "bw-linux"]'
|
||||
RUNS_ON: "['self-hosted', 'bw-linux']"
|
||||
secrets: inherit
|
||||
|
||||
# Delete infrastructures
|
||||
|
|
|
@ -4,7 +4,7 @@ from os import getenv
|
|||
from traceback import format_exc
|
||||
from subprocess import run
|
||||
from time import sleep
|
||||
from logger import setup_logger
|
||||
from logger import log
|
||||
|
||||
|
||||
class LinuxTest(Test):
|
||||
|
@ -17,10 +17,9 @@ class LinuxTest(Test):
|
|||
r"app2\.example\.com": getenv("TEST_DOMAIN1_2"),
|
||||
r"app3\.example\.com": getenv("TEST_DOMAIN1_3"),
|
||||
}
|
||||
if not distro in ("ubuntu", "debian", "fedora", "centos"):
|
||||
if not distro in ("ubuntu", "debian", "fedora", "centos", "rhel"):
|
||||
raise Exception(f"unknown distro {distro}")
|
||||
self.__distro = distro
|
||||
self.__logger = setup_logger("Linux_test", getenv("LOGLEVEL", "INFO"))
|
||||
|
||||
@staticmethod
|
||||
def init(distro):
|
||||
|
@ -75,9 +74,7 @@ class LinuxTest(Test):
|
|||
)
|
||||
sleep(60)
|
||||
except:
|
||||
setup_logger("Linux_test", getenv("LOGLEVEL", "INFO")).error(
|
||||
f"exception while running LinuxTest.init()\n{format_exc()}",
|
||||
)
|
||||
log("LINUX", "❌", "exception while running LinuxTest.init()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -91,9 +88,7 @@ class LinuxTest(Test):
|
|||
if proc.returncode != 0:
|
||||
ret = False
|
||||
except:
|
||||
setup_logger("Linux_test", getenv("LOGLEVEL", "INFO")).error(
|
||||
f"exception while running LinuxTest.end()\n{format_exc()}"
|
||||
)
|
||||
log("LINUX", "❌", "exception while running LinuxTest.end()\n" + format_exc())
|
||||
return False
|
||||
return ret
|
||||
|
||||
|
@ -132,9 +127,7 @@ class LinuxTest(Test):
|
|||
if proc.returncode != 0:
|
||||
raise Exception("docker exec systemctl restart failed (linux stack)")
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running LinuxTest._setup_test()\n{format_exc()}",
|
||||
)
|
||||
log("LINUX", "❌", "exception while running LinuxTest._setup_test()\n" + format_exc())
|
||||
self._debug_fail()
|
||||
self._cleanup_test()
|
||||
return False
|
||||
|
@ -150,9 +143,7 @@ class LinuxTest(Test):
|
|||
raise Exception("docker exec rm failed (cleanup)")
|
||||
super()._cleanup_test()
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running LinuxTest._cleanup_test()\n{format_exc()}",
|
||||
)
|
||||
log("DOCKER", "❌", "exception while running LinuxTest._cleanup_test()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from shutil import copytree, rmtree
|
|||
from traceback import format_exc
|
||||
from subprocess import run
|
||||
from time import sleep
|
||||
from logger import setup_logger
|
||||
from logger import log
|
||||
|
||||
|
||||
class SwarmTest(Test):
|
||||
|
@ -18,7 +18,6 @@ class SwarmTest(Test):
|
|||
r"app2\.example\.com": getenv("TEST_DOMAIN2"),
|
||||
r"app3\.example\.com": getenv("TEST_DOMAIN3"),
|
||||
}
|
||||
self.__logger = setup_logger("Swarm_test", getenv("LOGLEVEL", "INFO"))
|
||||
|
||||
@staticmethod
|
||||
def init():
|
||||
|
@ -76,15 +75,12 @@ class SwarmTest(Test):
|
|||
shell=True,
|
||||
capture_output=True,
|
||||
)
|
||||
logger = setup_logger("Swarm_test", getenv("LOGLEVEL", "INFO"))
|
||||
logger.error(f"stdout logs = {proc.stdout.decode()}")
|
||||
logger.error(f"stderr logs = {proc.stderr.decode()}")
|
||||
log("SWARM", "❌", "stdout logs = " + proc.stdout.decode())
|
||||
log("SWARM", "❌", "stderr logs = " + proc.stderr.decode())
|
||||
raise (Exception("swarm stack is not healthy"))
|
||||
sleep(60)
|
||||
except:
|
||||
setup_logger("Swarm_test", getenv("LOGLEVEL", "INFO")).error(
|
||||
f"exception while running SwarmTest.init()\n{format_exc()}",
|
||||
)
|
||||
log("SWARM", "❌", "exception while running SwarmTest.init()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -99,9 +95,7 @@ class SwarmTest(Test):
|
|||
ret = False
|
||||
rmtree("/tmp/swarm")
|
||||
except:
|
||||
setup_logger("Swarm_test", getenv("LOGLEVEL", "INFO")).error(
|
||||
f"exception while running SwarmTest.end()\n{format_exc()}"
|
||||
)
|
||||
log("SWARM", "❌", "exception while running SwarmTest.end()\n" + format_exc())
|
||||
return False
|
||||
return ret
|
||||
|
||||
|
@ -157,9 +151,7 @@ class SwarmTest(Test):
|
|||
if not healthy:
|
||||
raise (Exception("swarm stack is not healthy"))
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running SwarmTest._setup_test()\n{format_exc()}",
|
||||
)
|
||||
log("SWARM", "❌", "exception while running SwarmTest._setup_test()\n" + format_exc())
|
||||
self._cleanup_test()
|
||||
return False
|
||||
return True
|
||||
|
@ -190,9 +182,7 @@ class SwarmTest(Test):
|
|||
raise (Exception("docker pruner rm failed"))
|
||||
super()._cleanup_test()
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running SwarmTest._cleanup_test()\n{format_exc()}",
|
||||
)
|
||||
log("SWARM", "❌", "exception while running SwarmTest._cleanup_test()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from os.path import isdir, join
|
|||
from os import getenv, mkdir, walk, rename
|
||||
from re import sub, search, MULTILINE
|
||||
from subprocess import run
|
||||
from logger import setup_logger
|
||||
from logger import log
|
||||
|
||||
|
||||
class Test(ABC):
|
||||
|
@ -20,10 +20,7 @@ class Test(ABC):
|
|||
self._no_copy_container = no_copy_container
|
||||
self.__delay = delay
|
||||
self._domains = {}
|
||||
self.__logger = setup_logger("Test", getenv("LOG_LEVEL", "INFO"))
|
||||
self.__logger.info(
|
||||
f"instantiated with {len(tests)} tests and timeout of {timeout}s for {self._name}",
|
||||
)
|
||||
log("TEST", "ℹ️", "instiantiated with " + str(len(tests)) + " tests and timeout of " + str(timeout) + "s for " + self._name)
|
||||
|
||||
# called once before running all the different tests for a given integration
|
||||
@staticmethod
|
||||
|
@ -39,9 +36,7 @@ class Test(ABC):
|
|||
if not isdir("/tmp/tests"):
|
||||
mkdir("/tmp/tests")
|
||||
except:
|
||||
setup_logger("Test", getenv("LOG_LEVEL", "INFO")).error(
|
||||
f"exception while running Test.init()\n{format_exc()}"
|
||||
)
|
||||
log("TEST", "❌", "exception while running Test.init()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -65,9 +60,7 @@ class Test(ABC):
|
|||
run(f"sudo rm -rf /tmp/tests/{self._name}", shell=True)
|
||||
copytree(f"./examples/{self._name}", f"/tmp/tests/{self._name}")
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running Test._setup_test()\n{format_exc()}",
|
||||
)
|
||||
log("TEST", "❌", "exception while running Test._setup_test()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -76,9 +69,7 @@ class Test(ABC):
|
|||
try:
|
||||
run(f"sudo rm -rf /tmp/tests/{self._name}", shell=True)
|
||||
except:
|
||||
self.__logger.error(
|
||||
f"exception while running Test._cleanup_test()\n{format_exc()}",
|
||||
)
|
||||
log("TEST", "❌", "exception while running Test._cleanup_test()\n" + format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -88,7 +79,7 @@ class Test(ABC):
|
|||
self._debug_fail()
|
||||
return False
|
||||
if self.__delay != 0:
|
||||
self.__logger.info(f"delay is set, sleeping {self.__delay}s")
|
||||
log("TEST", "ℹ️", "delay is set, sleeping " + str(self.__delay) + "s")
|
||||
sleep(self.__delay)
|
||||
start = time()
|
||||
while time() < start + self._timeout:
|
||||
|
@ -101,14 +92,12 @@ class Test(ABC):
|
|||
break
|
||||
if all_ok:
|
||||
elapsed = str(int(time() - start))
|
||||
self.__logger.info(
|
||||
f"success ({elapsed}/{self._timeout}s)",
|
||||
)
|
||||
log("TEST", "ℹ️", "success (" + elapsed + "/" + str(self._timeout) + "s)")
|
||||
return self._cleanup_test()
|
||||
self.__logger.warning("tests not ok, retrying in 1s ...")
|
||||
self._debug_fail()
|
||||
self._cleanup_test()
|
||||
self.__logger.error(f"failed (timeout = {self._timeout}s)")
|
||||
log("TEST", "❌", "failed (timeout = " + str(self._timeout) + "s)")
|
||||
return False
|
||||
|
||||
# run a single test
|
||||
|
@ -140,9 +129,7 @@ class Test(ABC):
|
|||
sub(old, new, Path(path).read_text(), flags=MULTILINE)
|
||||
)
|
||||
except:
|
||||
setup_logger("Test", getenv("LOG_LEVEL", "INFO")).warning(
|
||||
f"Can't replace file {path}"
|
||||
)
|
||||
log("TEST", "⚠️", "can't replace file " + path + " : " + format_exc())
|
||||
|
||||
@staticmethod
|
||||
def replace_in_files(path, old, new):
|
||||
|
|
|
@ -16,22 +16,20 @@ from AutoconfTest import AutoconfTest
|
|||
from SwarmTest import SwarmTest
|
||||
from KubernetesTest import KubernetesTest
|
||||
from LinuxTest import LinuxTest
|
||||
from logger import setup_logger
|
||||
|
||||
logger = setup_logger("Tests", getenv("LOG_LEVEL", "INFO"))
|
||||
from logger import log
|
||||
|
||||
if len(argv) <= 1:
|
||||
logger.error("Missing type argument")
|
||||
log("TESTS", "❌", "Missing type argument")
|
||||
exit(1)
|
||||
|
||||
test_type = argv[1]
|
||||
if not test_type in ("linux", "docker", "autoconf", "swarm", "kubernetes", "ansible"):
|
||||
logger.error(f"Wrong type argument {test_type}")
|
||||
log("TESTS", "❌", "Wrong type argument " + test_type)
|
||||
exit(1)
|
||||
|
||||
run("docker system prune", shell=True)
|
||||
|
||||
logger.info(f"Starting tests for {test_type} ...")
|
||||
log("TESTS", "ℹ️", "Starting tests for " + test_type + " ...")
|
||||
ret = False
|
||||
end_fun = None
|
||||
if test_type == "docker":
|
||||
|
@ -51,7 +49,7 @@ elif test_type == "linux":
|
|||
ret = LinuxTest.init(distro)
|
||||
end_fun = LinuxTest.end
|
||||
if not ret:
|
||||
logger.error("Test.init() failed")
|
||||
log("TESTS", "❌", "Test.init() failed")
|
||||
exit(1)
|
||||
|
||||
for example in glob("./examples/*"):
|
||||
|
@ -60,9 +58,7 @@ for example in glob("./examples/*"):
|
|||
with open(f"{example}/tests.json") as f:
|
||||
tests = loads(f.read())
|
||||
if not test_type in tests["kinds"]:
|
||||
logger.info(
|
||||
f"Skipping tests for {tests['name']} (not in kinds)",
|
||||
)
|
||||
log("TESTS", "ℹ️", "Skipping tests for " + tests["name"] + " (not in kinds)")
|
||||
continue
|
||||
test_obj = None
|
||||
no_copy_container = False
|
||||
|
@ -100,16 +96,14 @@ for example in glob("./examples/*"):
|
|||
tests["name"], tests["timeout"], tests["tests"], distro
|
||||
)
|
||||
if not test_obj.run_tests():
|
||||
logger.error(f"Tests failed for {tests['name']}")
|
||||
log("TESTS", "❌", "Tests failed for " + tests["name"])
|
||||
if test_type == "linux":
|
||||
ret = end_fun(distro)
|
||||
else:
|
||||
ret = end_fun()
|
||||
_exit(1)
|
||||
except:
|
||||
logger.error(
|
||||
f"Exception while executing test for example {example} :\n{format_exc()}",
|
||||
)
|
||||
log("TESTS", "❌", "Exception while executing test for example " + example + " : " + format_exc())
|
||||
if test_type == "linux":
|
||||
ret = end_fun(distro)
|
||||
else:
|
||||
|
@ -121,9 +115,9 @@ if test_type == "linux":
|
|||
else:
|
||||
ret = end_fun()
|
||||
if not ret:
|
||||
logger.error("Test.end() failed")
|
||||
log("TESTS", "❌", "Test.end() failed")
|
||||
exit(1)
|
||||
|
||||
logger.info(f"All tests finished for {test_type} !")
|
||||
log("TESTS", "ℹ️", "All tests finished for " + test_type + " !")
|
||||
|
||||
run("docker system prune", shell=True)
|
||||
|
|
Loading…
Reference in New Issue