Skip to content

Commit

Permalink
Add kserve private endpoint tests (#22)
Browse files Browse the repository at this point in the history
* Add kserve private endpoint tests

Signed-off-by: lugi0 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix typing annotations

Signed-off-by: lugi0 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix pre-commit checks, add mypy ini file for vscode extension integration, specify in README that pre-commit shoulb be run and needs NPM installed

Signed-off-by: lugi0 <[email protected]>

* Fix typo in function signature

Signed-off-by: lugi0 <[email protected]>

* Update renovate.json (#26)

* Lock file maintenance (#28)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#29)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.0 → v0.7.1](astral-sh/ruff-pre-commit@v0.7.0...v0.7.1)
- [github.com/renovatebot/pre-commit-hooks: 38.129.0 → 38.133.1](renovatebot/pre-commit-hooks@38.129.0...38.133.1)
- [github.com/gitleaks/gitleaks: v8.21.1 → v8.21.2](gitleaks/gitleaks@v8.21.1...v8.21.2)
- [github.com/pre-commit/mirrors-mypy: v1.12.1 → v1.13.0](pre-commit/mirrors-mypy@v1.12.1...v1.13.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#32)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](astral-sh/ruff-pre-commit@v0.7.1...v0.7.2)
- [github.com/renovatebot/pre-commit-hooks: 38.133.1 → 39.0.0](renovatebot/pre-commit-hooks@38.133.1...39.0.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Lock file maintenance (#31)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* add CONTRIBUTING and update README (#25)

* Move to Python 3.9 (#33)

* move aws creds and buckets config to pytest_addoption (#34)

* Add kserve private endpoint tests

Signed-off-by: lugi0 <[email protected]>

* Fix pre-commit checks, add mypy ini file for vscode extension integration, specify in README that pre-commit shoulb be run and needs NPM installed

Signed-off-by: lugi0 <[email protected]>

* Address PR comments

Signed-off-by: lugi0 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix failures, pre-commit

Signed-off-by: lugi0 <[email protected]>

* Fix typo in gitignore

Signed-off-by: lugi0 <[email protected]>

* Remove duplicated lines

Signed-off-by: lugi0 <[email protected]>

* Address review comments

Signed-off-by: lugi0 <[email protected]>

* fix broken import

Signed-off-by: lugi0 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address PR comments, improve typing, remove mypy.ini, update CONTRIBUTING.MD

Signed-off-by: lugi0 <[email protected]>

* add typing to storage_check func

Signed-off-by: lugi0 <[email protected]>

* update deployment readiness check

Signed-off-by: lugi0 <[email protected]>

* Address PR comments

Signed-off-by: lugi0 <[email protected]>

* Address PR comments

Signed-off-by: lugi0 <[email protected]>

* Address new comments

Signed-off-by: lugi0 <[email protected]>

* Remove Enum inheritance

Signed-off-by: lugi0 <[email protected]>

---------

Signed-off-by: lugi0 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ruth Netser <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 27, 2024
1 parent 828571c commit a5512d1
Show file tree
Hide file tree
Showing 17 changed files with 687 additions and 153 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# OS generated files #
.DS_Store
.DS_Store?
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ pre-commit install
## General

- Add typing to new code; typing is enforced using [mypy](https://mypy-lang.org/)
- Rules are defined in [our pyproject.toml file](//pyproject.toml#L10)

If you use Visual Studio Code as your IDE, we recommend using the [Mypy Type Checker](https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker) extension.
After installing it, make sure to update the `Mypy-type-checkers: Args` setting
to `"mypy-type-checker.args" = ["--config-file=pyproject.toml"]`.
50 changes: 40 additions & 10 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os
import pathlib
import shutil
from pytest import Parser, Session, FixtureRequest, FixtureDef, Item, Config, CollectReport
from _pytest.terminal import TerminalReporter
from typing import Optional, Any

from utilities.logger import separator, setup_logging

Expand All @@ -10,7 +13,7 @@
BASIC_LOGGER = logging.getLogger("basic")


def pytest_addoption(parser):
def pytest_addoption(parser: Parser) -> None:
aws_group = parser.getgroup(name="AWS")
buckets_group = parser.getgroup(name="Buckets")

Expand All @@ -31,8 +34,34 @@ def pytest_addoption(parser):
"--ci-s3-bucket-name", default=os.environ.get("CI_S3_BUCKET_NAME"), help="Ci S3 bucket name"
)

buckets_group.addoption(
"--ci-s3-bucket-region", default=os.environ.get("CI_S3_BUCKET_REGION"), help="Ci S3 bucket region"
)

buckets_group.addoption(
"--ci-s3-bucket-endpoint", default=os.environ.get("CI_S3_BUCKET_ENDPOINT"), help="Ci S3 bucket endpoint"
)

buckets_group.addoption(
"--models-s3-bucket-name",
default=os.environ.get("MODELS_S3_BUCKET_NAME"),
help="Models S3 bucket name",
)

buckets_group.addoption(
"--models-s3-bucket-region",
default=os.environ.get("MODELS_S3_BUCKET_REGION"),
help="Models S3 bucket region",
)

buckets_group.addoption(
"--models-s3-bucket-endpoint",
default=os.environ.get("MODELS_S3_BUCKET_ENDPOINT"),
help="Models S3 bucket endpoint",
)


def pytest_sessionstart(session):
def pytest_sessionstart(session: Session) -> None:
tests_log_file = session.config.getoption("log_file") or "pytest-tests.log"
if os.path.exists(tests_log_file):
pathlib.Path(tests_log_file).unlink()
Expand All @@ -43,24 +72,24 @@ def pytest_sessionstart(session):
)


def pytest_fixture_setup(fixturedef, request):
def pytest_fixture_setup(fixturedef: FixtureDef[Any], request: FixtureRequest) -> None:
LOGGER.info(f"Executing {fixturedef.scope} fixture: {fixturedef.argname}")


def pytest_runtest_setup(item):
def pytest_runtest_setup(item: Item) -> None:
BASIC_LOGGER.info(f"\n{separator(symbol_='-', val=item.name)}")
BASIC_LOGGER.info(f"{separator(symbol_='-', val='SETUP')}")


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


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


def pytest_report_teststatus(report, config):
def pytest_report_teststatus(report: CollectReport, config: Config) -> None:
test_name = report.head_line
when = report.when
call_str = "call"
Expand All @@ -78,8 +107,9 @@ def pytest_report_teststatus(report, config):
BASIC_LOGGER.info(f"\nTEST: {test_name} STATUS: \033[0;31mFAILED\033[0m")


def pytest_sessionfinish(session, exitstatus):
def pytest_sessionfinish(session: Session, exitstatus: int) -> None:
shutil.rmtree(path=session.config.option.basetemp, ignore_errors=True)

reporter = session.config.pluginmanager.get_plugin("terminalreporter")
reporter.summary_stats()
reporter: Optional[TerminalReporter] = session.config.pluginmanager.get_plugin("terminalreporter")
if reporter:
reporter.summary_stats()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ disallow_untyped_defs = true
no_implicit_optional = true
show_error_codes = true
warn_unused_ignores = true
ignore_missing_imports = true

[tool.uv]
dev-dependencies = [
Expand Down
102 changes: 99 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Tuple, Any, Generator

import pytest
from pytest import FixtureRequest, Config
from kubernetes.dynamic import DynamicClient
from ocp_resources.namespace import Namespace
from ocp_resources.resource import get_client

from tests.utils import create_ns
from utilities.infra import create_ns


@pytest.fixture(scope="session")
Expand All @@ -12,6 +15,99 @@ def admin_client() -> DynamicClient:


@pytest.fixture(scope="class")
def model_namespace(request, admin_client: DynamicClient) -> Namespace:
with create_ns(client=admin_client, name=request.param["name"]) as ns:
def model_namespace(request: FixtureRequest, admin_client: DynamicClient) -> Generator[Namespace, Any, Any]:
with create_ns(admin_client=admin_client, name=request.param["name"]) as ns:
yield ns


@pytest.fixture(scope="session")
def aws_access_key_id(pytestconfig: Config) -> str:
access_key = pytestconfig.option.aws_access_key_id
if not access_key:
raise ValueError(
"AWS access key id is not set. "
"Either pass with `--aws-access-key-id` or set `AWS_ACCESS_KEY_ID` environment variable"
)
return access_key


@pytest.fixture(scope="session")
def aws_secret_access_key(pytestconfig: Config) -> str:
secret_access_key = pytestconfig.option.aws_secret_access_key
if not secret_access_key:
raise ValueError(
"AWS secret access key is not set. "
"Either pass with `--aws-secret-access-key` or set `AWS_SECRET_ACCESS_KEY` environment variable"
)
return secret_access_key


@pytest.fixture(scope="session")
def valid_aws_config(aws_access_key_id: str, aws_secret_access_key: str) -> Tuple[str, str]:
return aws_access_key_id, aws_secret_access_key


@pytest.fixture(scope="session")
def ci_s3_bucket_name(pytestconfig: Config) -> str:
bucket_name = pytestconfig.option.ci_s3_bucket_name
if not bucket_name:
raise ValueError(
"CI S3 bucket name is not set. "
"Either pass with `--ci-s3-bucket-name` or set `CI_S3_BUCKET_NAME` environment variable"
)
return bucket_name


@pytest.fixture(scope="session")
def ci_s3_bucket_region(pytestconfig: pytest.Config) -> str:
ci_bucket_region = pytestconfig.option.ci_s3_bucket_region
if not ci_bucket_region:
raise ValueError(
"Region for the ci s3 bucket is not defined."
"Either pass with `--ci-s3-bucket-region` or set `CI_S3_BUCKET_REGION` environment variable"
)
return ci_bucket_region


@pytest.fixture(scope="session")
def ci_s3_bucket_endpoint(pytestconfig: pytest.Config) -> str:
ci_bucket_endpoint = pytestconfig.option.ci_s3_bucket_endpoint
if not ci_bucket_endpoint:
raise ValueError(
"Endpoint for the ci s3 bucket is not defined."
"Either pass with `--ci-s3-bucket-endpoint` or set `CI_S3_BUCKET_ENDPOINT` environment variable"
)
return ci_bucket_endpoint


@pytest.fixture(scope="session")
def models_s3_bucket_name(pytestconfig: pytest.Config) -> str:
models_bucket = pytestconfig.option.models_s3_bucket_name
if not models_bucket:
raise ValueError(
"Bucket name for the models bucket is not defined."
"Either pass with `--models-s3-bucket-name` or set `MODELS_S3_BUCKET_NAME` environment variable"
)
return models_bucket


@pytest.fixture(scope="session")
def models_s3_bucket_region(pytestconfig: pytest.Config) -> str:
models_bucket_region = pytestconfig.option.models_s3_bucket_region
if not models_bucket_region:
raise ValueError(
"region for the models bucket is not defined."
"Either pass with `--models-s3-bucket-region` or set `MODELS_S3_BUCKET_REGION` environment variable"
)
return models_bucket_region


@pytest.fixture(scope="session")
def models_s3_bucket_endpoint(pytestconfig: pytest.Config) -> str:
models_bucket_endpoint = pytestconfig.option.models_s3_bucket_endpoint
if not models_bucket_endpoint:
raise ValueError(
"endpoint for the models bucket is not defined."
"Either pass with `--models-s3-bucket-endpoint` or set `MODELS_S3_BUCKET_ENDPOINT` environment variable"
)
return models_bucket_endpoint
Empty file.
Loading

0 comments on commit a5512d1

Please sign in to comment.