Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging for ci #23

Merged
merged 5 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python

python:
- 3.8

services:
- docker

before_install:
- pip install -U pip

script:
- ./steth.py logging_test
37 changes: 37 additions & 0 deletions lib/logging_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from lib.runner import run_module, file_to_module, return_code_to_status

LOGGING_TESTS_DIR = 'logging_tests'

def all_logging_test_files():
tests = []
for root, dirs, files in os.walk(LOGGING_TESTS_DIR):
tests.extend([f'{root}/{f}' for f in files if f.endswith('.py')])

return tests


def run_logging_tests(client):
print(client)

failures = {}
for file in all_logging_test_files():
module = file_to_module(file)
(return_code, logs) = run_module(module, {})

print(f'\t{module} {return_code_to_status(return_code)}')
if return_code != 0:
failures[module] = (return_code, logs)

if len(failures) > 0:
for module, (return_code, logs) in failures.items():
print('')
print(f'\t{module} {return_code_to_status(return_code)}')

for log in logs:
print(f'\t{log}')

return 1

return 0
27 changes: 14 additions & 13 deletions lib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

import trio
from colored import fg

from lib.console import ConsoleWriter
from lib.instance_configs import DEFAULT_ARGS
Expand All @@ -23,23 +24,23 @@ def all_test_files():
def file_to_module(script):
return script.replace('/', '.')[0:-3]

def return_code_to_status(return_code):
if return_code == 0:
return f"{fg('green')}\u2713{fg('white')}"

# TODO: add args back in
def run_module(module, args, cw):
print(f'Running module: {module} with args {args}')
#module = importlib.import_module(module)
else:
return f"{fg('red')}\u2717{fg('white')}"

#if not hasattr(module, 'run'):
#cw.fail(f'module {module} does not have a run method')
#return
def run_module(module_str, args):
module = importlib.import_module(module_str)

#return_code = trio.run(module.run, args)
#if return_code == 0:
#cw.success('SUCCESS')
if not hasattr(module, 'run'):
print(f'\t{module} does not have a run method')
return

#else:
#cw.fail('FAILED')
return_code, logs = trio.run(module.run, args)

return (return_code, logs)

def test_matches_filter(test, test_filter):
return test_filter is None or test == test_filter
Expand All @@ -49,4 +50,4 @@ def run_all_tests(cw=ConsoleWriter(None, None), test_filter=None):
if test_matches_filter(test_file, test_filter):
cw = cw._replace(test=file_to_module(test_file))

run_module(file_to_module(test_file), DEFAULT_ARGS, cw)
run_module(file_to_module(test_file), DEFAULT_ARGS)
2 changes: 2 additions & 0 deletions logging_tests/test_fail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
async def run(args):
return (1, ['error 1', 'error 2'])
2 changes: 2 additions & 0 deletions logging_tests/test_success.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
async def run(args):
return (0, [])
File renamed without changes.
14 changes: 14 additions & 0 deletions steth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lib.console import ConsoleWriter
from lib.fixtures import extract_fixtures, setup_fixture, teardown_fixture
from lib.runner import run_all_tests
from lib.logging_tests import run_logging_tests


def run_start_fixture(args):
Expand Down Expand Up @@ -61,6 +62,16 @@ def run_test(args):
teardown_fixture(fixture)


def run_logging_test(args):
failed = False
for client in SUPPORTED_CLIENTS:
return_code= run_logging_tests(client)
if return_code != 0:
failed = True

if failed:
exit(1)

if __name__ == '__main__':
steth = argparse.ArgumentParser(description='Stethoscope tool for running multi-client Eth2 scenarios')
steth_sub = steth.add_subparsers()
Expand All @@ -83,5 +94,8 @@ def run_test(args):
test.add_argument('-r', '--reuse', default=False, action='store_true', help='reuse running fixtures')
test.set_defaults(func=run_test)

test = steth_sub.add_parser('logging_test', help='Display example logs from ./steth.py test. Useful for testing CI integration')
test.set_defaults(func=run_logging_test)

args = steth.parse_args()
args.func(args)