Skip to content

Commit

Permalink
refactor: logging for hub build tests (#1923)
Browse files Browse the repository at this point in the history
* refactor: logging for hub build tests

* test: logging for hub fix test

* refactor: hubio logging
  • Loading branch information
florian-hoenicke committed Feb 15, 2021
1 parent caaf59c commit 47ae81f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions jina/docker/hubio.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def build(self) -> Dict:
self.args.test_level,
self.config_yaml_path,
self.args.timeout_ready,
self.args.daemon)
self.args.daemon,
self.logger)
if any(test_level in failed_test_levels for test_level in
[BuildTestLevel.POD_DOCKER, BuildTestLevel.FLOW]):
is_build_success = False
Expand Down Expand Up @@ -467,51 +468,64 @@ def _test_build(image, # type docker image object
test_level: 'BuildTestLevel',
config_yaml_path: str,
timeout_ready: int,
daemon_arg: bool):
daemon_arg: bool,
logger: 'JinaLogger'):
p_names = []
failed_levels = []

logger.info(f'run tests using test level {test_level}')
# test uses at executor level
if test_level >= BuildTestLevel.EXECUTOR:
logger.info(f'test to initialize an executor from yaml configuration: {config_yaml_path}')
try:
with BaseExecutor.load_config(config_yaml_path):
pass
logger.info(f'successfully tested to initialize an executor')
except:
logger.error(f'failed to initialize an executor')
failed_levels.append(BuildTestLevel.EXECUTOR)

# test uses at Pod level (no docker)
if test_level >= BuildTestLevel.POD_NONDOCKER:
logger.info(f'test to initialize a pod from yaml configuration: {config_yaml_path}')
try:
with Pod(set_pod_parser().parse_args(
['--uses', config_yaml_path, '--timeout-ready', str(timeout_ready)])):
pass
logger.info(f'successfully tested to initialize a pod from yaml configuration')
except:
logger.error(f'failed to initialize a pod')
failed_levels.append(BuildTestLevel.POD_NONDOCKER)

# test uses at Pod level (with docker)
if test_level >= BuildTestLevel.POD_DOCKER:
p_name = random_name()
logger.info(f'test to initialize a pod via docker image {image.tags[0]} named {p_name}')
try:
with Pod(set_pod_parser().parse_args(
['--uses', f'docker://{image.tags[0]}', '--name', p_name, '--timeout-ready',
str(timeout_ready)] +
['--daemon'] if daemon_arg else [])):
pass
p_names.append(p_name)
logger.info(f'successfully tested to initialize a pod via docker')
except:
logger.error(f'failed to initialize a pod via docker image')
failed_levels.append(BuildTestLevel.POD_DOCKER)

# test uses at Flow level
if test_level >= BuildTestLevel.FLOW:
p_name = random_name()
logger.info(f'test to build a flow from docker image {image.tags[0]} named {p_name} '
f'with daemon={daemon_arg} and timeout_ready={timeout_ready}')
try:
with Flow().add(name=random_name(), uses=f'docker://{image.tags[0]}', daemon=daemon_arg,
with Flow().add(name=p_name, uses=f'docker://{image.tags[0]}', daemon=daemon_arg,
timeout_ready=timeout_ready):
pass
p_names.append(p_name)
logger.info('successfully tested to build a flow from docker image')
except:
logger.error(f'failed to build a flow from docker image')
failed_levels.append(BuildTestLevel.FLOW)

return p_names, failed_levels

def dry_run(self) -> Dict:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/docker/test_hub_build_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from jina.docker.hubio import HubIO
from jina.enums import BuildTestLevel
from jina.executors import BaseExecutor
from jina.logging import JinaLogger
from jina.parsers.hub import set_hub_build_parser

cli = docker.APIClient(base_url='unix://var/run/docker.sock')
Expand All @@ -23,7 +23,7 @@ def test_hub_build_level_pass(monkeypatch, test_workspace):
docker_image = cli.get_image('jinahub/pod.dummy_mwu_encoder')
expected_failed_levels = []

_, failed_levels = HubIO(args)._test_build(docker_image, BuildTestLevel.EXECUTOR, os.path.join(cur_dir, 'yaml/test-joint.yml'), 60, True)
_, failed_levels = HubIO(args)._test_build(docker_image, BuildTestLevel.EXECUTOR, os.path.join(cur_dir, 'yaml/test-joint.yml'), 60, True, JinaLogger('unittest'))

assert expected_failed_levels == failed_levels

Expand All @@ -33,6 +33,6 @@ def test_hub_build_level_fail(monkeypatch, test_workspace):
docker_image = cli.get_image('jinahub/pod.dummy_mwu_encoder')
expected_failed_levels = [BuildTestLevel.POD_NONDOCKER, BuildTestLevel.POD_DOCKER, BuildTestLevel.FLOW]

_, failed_levels = HubIO(args)._test_build(docker_image, BuildTestLevel.FLOW, os.path.join(cur_dir, 'yaml/test-joint.yml'), 60, True)
_, failed_levels = HubIO(args)._test_build(docker_image, BuildTestLevel.FLOW, os.path.join(cur_dir, 'yaml/test-joint.yml'), 60, True, JinaLogger('unittest'))

assert expected_failed_levels == failed_levels

0 comments on commit 47ae81f

Please sign in to comment.