コード例 #1
0
ファイル: test_docker.py プロジェクト: rubaha96/ebonite
def registry(tmpdir_factory, pytestconfig):
    if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'):
        pytest.skip('skipping docker tests')
    with Container('registry:latest').with_exposed_ports(
            REGISTRY_PORT) as container:
        host = f'localhost:{container.get_exposed_port(REGISTRY_PORT)}'

        client = DockerClient()

        # migrate our image to custom Docker registry
        tag_name = f'{host}/{REPOSITORY_NAME}/{IMAGE_NAME}'
        client.images.pull(IMAGE_NAME, 'latest').tag(tag_name)
        client.images.push(tag_name)

        tmpdir = str(tmpdir_factory.mktemp("image"))
        # create failing image: alpine is too small to have python inside
        with open(os.path.join(tmpdir, 'Dockerfile'), 'w') as f:
            f.write("""
                FROM alpine:latest

                CMD python
           """)
        broken_tag_name = f'{host}/{REPOSITORY_NAME}/{BROKEN_IMAGE_NAME}'
        client.images.build(path=tmpdir, tag=broken_tag_name)
        client.images.push(broken_tag_name)

        yield RemoteDockerRegistry(host)
コード例 #2
0
def pytest_collection_modifyitems(items, config):
    for colitem in items:
        if colitem.nodeid.startswith('tests/client/remote.py::'):
            colitem.add_marker(pytest.mark.docker)
            colitem.add_marker(
                pytest.mark.skipif(not has_docker(),
                                   reason='no docker installed'))
コード例 #3
0
ファイル: conftest.py プロジェクト: koskotG/ebonite
def postgres_server(pytestconfig):
    if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'):
        pytest.skip('skipping docker tests')

    with DockerContainer('postgres:alpine') \
            .with_bind_ports(5432, PG_PORT) \
            .with_env("POSTGRES_USER", PG_USER) \
            .with_env("POSTGRES_PASSWORD", PG_PASS) \
            .with_env("POSTGRES_DB", PG_DB):
        sleep(5)  # wait to ensure that PostgreSQL server has enough time to properly start
        yield
コード例 #4
0
ファイル: conftest.py プロジェクト: rubaha96/ebonite
def s3server(pytestconfig):
    if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'):
        pytest.skip('skipping docker tests')

    with DockerContainer('minio/minio:latest') \
            .with_command('server /data') \
            .with_env('MINIO_ACCESS_KEY', ACCESS_KEY) \
            .with_env('MINIO_SECRET_KEY', SECRET_KEY) \
            .with_exposed_ports(PORT) as container:
        sleep(5)  # wait to ensure that S3 server has enough time to properly start
        yield container.get_exposed_port(PORT)
コード例 #5
0
def runner(pytestconfig):
    if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'):
        pytest.skip('skipping docker tests')
    args = []

    def _runner(host: str, img: DockerImage, container_name: str):
        args.append((host, img, container_name))
        return DockerRunner()

    yield _runner

    for h, i, c in args:
        rm_container(c, h)
        rm_image(i.get_uri(), h)
コード例 #6
0
def registry(tmpdir_factory, pytestconfig):
    if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'):
        pytest.skip('skipping docker tests')
    with Container('registry:latest').with_bind_ports(REGISTRY_PORT,
                                                      REGISTRY_PORT):
        client = DockerClient()

        # migrate our image to custom Docker registry
        client.images.pull(IMAGE_NAME, 'latest').tag(TAG_NAME)
        client.images.push(TAG_NAME)

        tmpdir = str(tmpdir_factory.mktemp("image"))
        # create failing image: alpine is too small to have python inside
        with open(os.path.join(tmpdir, 'Dockerfile'), 'w') as f:
            f.write("""
                FROM alpine:latest

                CMD python
           """)
        client.images.build(path=tmpdir, tag=BROKEN_TAG_NAME)
        client.images.push(BROKEN_TAG_NAME)

        yield RemoteDockerRegistry(REGISTRY_HOST)
コード例 #7
0
from ebonite.client import Ebonite
from ebonite.core.errors import ExistingModelError
from ebonite.core.objects.core import Model
from tests.build.builder.test_docker import has_docker
from tests.build.conftest import is_container_running, rm_container, rm_image, train_model
from tests.client.test_func import func

LOCAL_REPO_PATH = os.path.dirname(__file__)
LOCAL_ARTIFACT_REPO_PATH = os.path.join(LOCAL_REPO_PATH, 'artifacts')
CONTAINER_NAME = "ebonite-test-service"

CLEAR = True  # flag to disable removal of containers for easy inspection and debugging


@pytest.fixture
@pytest.mark.skipif(not has_docker(), reason='no docker installed')
def container_name():
    name = "{}-{}".format(CONTAINER_NAME, int(time.time() * 1000))
    yield name

    if not CLEAR:
        return

    rm_container(name)
    rm_image(name + ":latest")  # FIXME later


@pytest.fixture
def ebnt(tmpdir):
    with use_local_installation():
        yield Ebonite.local(str(tmpdir))
コード例 #8
0
ファイル: conftest.py プロジェクト: koskotG/ebonite
def pytest_collection_modifyitems(items, config):
    for colitem in items:
        if colitem.nodeid.startswith('tests/repository/metadata/postgres.py::'):
            colitem.add_marker(pytest.mark.docker)
            colitem.add_marker(pytest.mark.skipif(not has_docker(), reason='no docker installed'))