Skip to content

Commit

Permalink
csv validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbasunag committed Mar 22, 2024
1 parent c70b791 commit a047276
Show file tree
Hide file tree
Showing 19 changed files with 750 additions and 3 deletions.
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM fedora:39

ARG OPENSHIFT_PYTHON_WRAPPER_COMMIT=''
ARG POETRY_HOME='/usr/local'

RUN dnf -y install dnf-plugins-core && \
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo && \
dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && \
dnf -y install --setopt=skip_missing_names_on_install=False \
python3-pip \
python3-devel \
procps-ng \
rsync \
gcc \
git \
libcurl-devel \
libxslt-devel \
libxml2-devel \
openssl-devel \
terraform \
vim \
gh && \
dnf clean all && \
rm -rf /var/cache/yum

ENV USER_HOME=/home/openshift-virtualization-tests
ENV PATH="${PATH}:$USER_HOME/.local/bin"

COPY . /openshift-virtualization-tests/
WORKDIR /openshift-virtualization-tests/

RUN python3 -m pip install pip --upgrade \
&& python3 -m venv ${POETRY_HOME} \
&& ${POETRY_HOME}/bin/pip install pip --upgrade \
&& ${POETRY_HOME}/bin/pip install poetry \
&& ${POETRY_HOME}/bin/poetry --version \
&& ${POETRY_HOME}/bin/poetry config cache-dir /openshift-virtualization-tests \
&& ${POETRY_HOME}/bin/poetry config virtualenvs.in-project true \
&& ${POETRY_HOME}/bin/poetry config --list \
&& ${POETRY_HOME}/bin/poetry install \
&& ${POETRY_HOME}/bin/poetry export --without-hashes -n \
&& if [[ -n "${OPENSHIFT_PYTHON_WRAPPER_COMMIT}" ]]; then ${POETRY_HOME}/bin/poetry run pip install git+https://github.com/RedHatQE/openshift-python-wrapper.git@$OPENSHIFT_PYTHON_WRAPPER_COMMIT -U; fi \
&& rm -rf /openshift-virtualization-tests/cache \
&& rm -rf /openshift-virtualization-tests/artifacts \
&& find /openshift-virtualization-tests/ -type d -name "__pycache__" -print0 | xargs -0 rm -rfv

ENV OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL=DEBUG

ENTRYPOINT ["poetry", "run", "pytest"]
CMD ["--collect-only"]
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Building cluster-sanity container
IMAGE_BUILD_CMD = "$(shell which podman 2>/dev/null || which docker)"
IMAGE_REGISTRY ?= "quay.io"
ORG_NAME ?= "openshift-cnv"
IMAGE_NAME ?= "openshift-virtualization-tests"
IMAGE_TAG ?= "latest"

FULL_OPERATOR_IMAGE ?= "$(IMAGE_REGISTRY)/$(ORG_NAME)/$(IMAGE_NAME):$(IMAGE_TAG)"

all: check poetry run_cluster_sanity_tests build-container push-container
publish-image: build-container push-container

check:
tox

poetry:
-poetry env remove --all
poetry install
poetry show

build-container:
$(IMAGE_BUILD_CMD) build --no-cache -f Dockerfile -t $(FULL_OPERATOR_IMAGE) .

push-container:
$(IMAGE_BUILD_CMD) push $(FULL_OPERATOR_IMAGE)

.PHONY: all
97 changes: 97 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os
import pathlib
import logging
import shutil
import pytest

from utilities.logger import setup_logging

LOGGER = logging.getLogger(__name__)
BASIC_LOGGER = logging.getLogger("basic")


def separator(symbol_, val=None):
terminal_width = shutil.get_terminal_size(fallback=(120, 40))[0]
if not val:
return f"{symbol_ * terminal_width}"

sepa = int((terminal_width - len(val) - 2) // 2)
return f"{symbol_ * sepa} {val} {symbol_ * sepa}"


def pytest_addoption(parser):
log_collector_group = parser.getgroup(name="LogCollector")

log_collector_group.addoption(
"--pytest-log-file",
help="Path to pytest log file",
default="pytest-tests.log",
)


def pytest_sessionstart(session):
tests_log_file = session.config.getoption("pytest_log_file")
if os.path.exists(tests_log_file):
pathlib.Path(tests_log_file).unlink()
setup_logging(
log_file=tests_log_file,
log_level=session.config.getoption("log_cli_level") or logging.INFO,
)


def pytest_report_teststatus(report, config):
test_name = report.head_line
when = report.when
call_str = "call"
if report.passed:
if when == call_str:
BASIC_LOGGER.info(f"\nTEST: {test_name} STATUS: \033[0;32mPASSED\033[0m")

elif report.skipped:
BASIC_LOGGER.info(f"\nTEST: {test_name} STATUS: \033[1;33mSKIPPED\033[0m")

elif report.failed:
if when != call_str:
BASIC_LOGGER.info(
f"\nTEST: {test_name} [{when}] STATUS: \033[0;31mERROR\033[0m"
)
else:
BASIC_LOGGER.info(f"\nTEST: {test_name} STATUS: \033[0;31mFAILED\033[0m")


def pytest_sessionfinish(session, exitstatus):
reporter = session.config.pluginmanager.get_plugin("terminalreporter")
reporter.summary_stats()


def pytest_runtest_makereport(item, call):
"""
incremental tests implementation
"""
if call.excinfo is not None and "incremental" in item.keywords:
parent = item.parent
parent._previousfailed = item


def pytest_fixture_setup(fixturedef, request):
LOGGER.info(f"Executing {fixturedef.scope} fixture: {fixturedef.argname}")


def pytest_runtest_setup(item):
"""
Use incremental
"""
BASIC_LOGGER.info(f"\n{separator(symbol_='-', val=item.name)}")
BASIC_LOGGER.info(f"{separator(symbol_='-', val='SETUP')}")
if "incremental" in item.keywords:
previousfailed = getattr(item.parent, "_previousfailed", None)
if previousfailed is not None:
pytest.xfail("previous test failed (%s)" % previousfailed.name)


def pytest_runtest_call(item):
BASIC_LOGGER.info(f"{separator(symbol_='-', val='CALL')}")


def pytest_runtest_teardown(item):
BASIC_LOGGER.info(f"{separator(symbol_='-', val='TEARDOWN')}")
Loading

0 comments on commit a047276

Please sign in to comment.