From ac33478eff5699701e25ab92858455c0a467bcbe Mon Sep 17 00:00:00 2001 From: Meni Yakove <441263+myakove@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:17:51 +0300 Subject: [PATCH] Remove openshift dependencies (#1288) * Remove openshift python module dependencies, use kubernetes * Remove openshift python module dependencies, use kubernetes --- README.md | 2 +- ocp_resources/constants.py | 4 +- ocp_resources/data_source.py | 2 +- .../node_network_configuration_policy.py | 2 +- ocp_resources/node_network_state.py | 2 +- ocp_resources/resource.py | 16 ++-- ocp_resources/virtual_machine_instance.py | 2 +- ocp_resources/virtual_machine_restore.py | 2 +- ocp_resources/virtual_machine_snapshot.py | 2 +- poetry.lock | 91 +++++++++++++------ pyproject.toml | 8 +- tests/test_resources.py | 2 +- tox.ini | 37 ++++---- 13 files changed, 108 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 5ff08bd54d..a56716eac2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # openshift-python-wrapper Pypi: [openshift-python-wrapper](https://pypi.org/project/openshift-python-wrapper) -A python wrapper for [openshift-restclient-python](https://github.com/openshift/openshift-restclient-python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization)) +A python wrapper for [kubernetes-python-client](https://github.com/kubernetes-client/python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization)) Docs: [openshift-python-wrapper docs](https://openshift-python-wrapper.readthedocs.io/en/latest/) ## Installation diff --git a/ocp_resources/constants.py b/ocp_resources/constants.py index 0d4027e289..b08c8d07a1 100644 --- a/ocp_resources/constants.py +++ b/ocp_resources/constants.py @@ -1,5 +1,5 @@ -from kubernetes.dynamic.exceptions import ForbiddenError -from openshift.dynamic.exceptions import ( +from kubernetes.dynamic.exceptions import ( + ForbiddenError, InternalServerError, NotFoundError, ServerTimeoutError, diff --git a/ocp_resources/data_source.py b/ocp_resources/data_source.py index 6c40f77842..6f45a686b7 100644 --- a/ocp_resources/data_source.py +++ b/ocp_resources/data_source.py @@ -1,4 +1,4 @@ -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.persistent_volume_claim import PersistentVolumeClaim diff --git a/ocp_resources/node_network_configuration_policy.py b/ocp_resources/node_network_configuration_policy.py index 4f9d9a1ef5..7f20d75ffa 100644 --- a/ocp_resources/node_network_configuration_policy.py +++ b/ocp_resources/node_network_configuration_policy.py @@ -1,6 +1,6 @@ import re -from openshift.dynamic.exceptions import ConflictError +from kubernetes.dynamic.exceptions import ConflictError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.node import Node diff --git a/ocp_resources/node_network_state.py b/ocp_resources/node_network_state.py index dd48a55f7b..d7c5bf14ee 100644 --- a/ocp_resources/node_network_state.py +++ b/ocp_resources/node_network_state.py @@ -1,6 +1,6 @@ import time -from openshift.dynamic.exceptions import ConflictError +from kubernetes.dynamic.exceptions import ConflictError from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.resource import Resource diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index c02a8ddc57..9d1517affb 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -10,10 +10,14 @@ import kubernetes import yaml from benedict import benedict -from kubernetes.dynamic.exceptions import ForbiddenError, MethodNotAllowedError -from openshift.dynamic import DynamicClient -from openshift.dynamic.exceptions import ConflictError, NotFoundError -from openshift.dynamic.resource import ResourceField +from kubernetes.dynamic import DynamicClient +from kubernetes.dynamic.exceptions import ( + ConflictError, + ForbiddenError, + MethodNotAllowedError, + NotFoundError, +) +from kubernetes.dynamic.resource import ResourceField from packaging.version import Version from simple_logger.logger import get_logger @@ -1106,8 +1110,8 @@ def get( dyn_client (DynamicClient): Open connection to remote cluster config_file (str): Path to config file for connecting to remote cluster. context (str): Context name for connecting to remote cluster. - singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource - raw (bool): If True return raw object from openshift-restclient-python + singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource. + raw (bool): If True return raw object. Returns: diff --git a/ocp_resources/virtual_machine_instance.py b/ocp_resources/virtual_machine_instance.py index 047543c17b..3fdd4f7359 100644 --- a/ocp_resources/virtual_machine_instance.py +++ b/ocp_resources/virtual_machine_instance.py @@ -1,7 +1,7 @@ import shlex import xmltodict -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.node import Node diff --git a/ocp_resources/virtual_machine_restore.py b/ocp_resources/virtual_machine_restore.py index 213c263a56..b8c378170e 100644 --- a/ocp_resources/virtual_machine_restore.py +++ b/ocp_resources/virtual_machine_restore.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.resource import NamespacedResource diff --git a/ocp_resources/virtual_machine_snapshot.py b/ocp_resources/virtual_machine_snapshot.py index c3dc7929ef..aaa2157666 100644 --- a/ocp_resources/virtual_machine_snapshot.py +++ b/ocp_resources/virtual_machine_snapshot.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openshift.dynamic.exceptions import ResourceNotFoundError +from kubernetes.dynamic.exceptions import ResourceNotFoundError from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES from ocp_resources.resource import NamespacedResource diff --git a/poetry.lock b/poetry.lock index a854e62d3f..01e33a2245 100644 --- a/poetry.lock +++ b/poetry.lock @@ -491,6 +491,20 @@ files = [ [package.dependencies] packaging = ">=20.9" +[[package]] +name = "exceptiongroup" +version = "1.1.2" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.1.2-py3-none-any.whl", hash = "sha256:e346e69d186172ca7cf029c8c1d16235aa0e04035e5750b4b95039e65204328f"}, + {file = "exceptiongroup-1.1.2.tar.gz", hash = "sha256:12c3e887d6485d16943a309616de20ae5582633e0a2eda17f4e10fd61c1e8af5"}, +] + +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "executing" version = "1.2.0" @@ -613,6 +627,17 @@ zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-ruff"] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + [[package]] name = "installer" version = "0.7.0" @@ -1019,22 +1044,6 @@ rsa = ["cryptography (>=3.0.0)"] signals = ["blinker (>=1.4.0)"] signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] -[[package]] -name = "openshift" -version = "0.13.2" -description = "OpenShift python client" -optional = false -python-versions = "*" -files = [ - {file = "openshift-0.13.2-py3-none-any.whl", hash = "sha256:f1459006fc7f96ff7d2f6c0c00bdef5cb2e75a1b466f601997d9084a816a8949"}, - {file = "openshift-0.13.2.tar.gz", hash = "sha256:f55789fce56fcbf7e2cd9377a68c4a99ab406074d3324b9abcca98477d101471"}, -] - -[package.dependencies] -kubernetes = ">=12.0" -python-string-utils = "*" -six = "*" - [[package]] name = "packaging" version = "23.1" @@ -1126,6 +1135,21 @@ files = [ docs = ["furo (>=2023.5.20)", "proselint (>=0.13)", "sphinx (>=7.0.1)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest-cov (>=4.1)", "pytest-mock (>=3.10)"] +[[package]] +name = "pluggy" +version = "1.2.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, + {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "poetry" version = "1.5.1" @@ -1316,6 +1340,28 @@ files = [ [package.dependencies] tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +[[package]] +name = "pytest" +version = "7.4.0" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.0-py3-none-any.whl", hash = "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32"}, + {file = "pytest-7.4.0.tar.gz", hash = "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + [[package]] name = "python-benedict" version = "0.32.0" @@ -1399,17 +1445,6 @@ text-unidecode = ">=1.3" [package.extras] unidecode = ["Unidecode (>=1.1.1)"] -[[package]] -name = "python-string-utils" -version = "1.0.0" -description = "Utility functions for strings validation and manipulation." -optional = false -python-versions = ">=3.5" -files = [ - {file = "python-string-utils-1.0.0.tar.gz", hash = "sha256:dcf9060b03f07647c0a603408dc8b03f807f3b54a05c6e19eb14460256fac0cb"}, - {file = "python_string_utils-1.0.0-py3-none-any.whl", hash = "sha256:f1a88700baf99db1a9b6953f44181ad9ca56623c81e257e6009707e2e7851fa4"}, -] - [[package]] name = "pywin32-ctypes" version = "0.2.2" @@ -2075,4 +2110,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "295eb7a1327ce130f120706df284b17d600c5f14a26246eee5e7fbc591686788" +content-hash = "106737b5f75bdb59c7ccaf6f5e2a8c6e0376fbfbfc4cc1e42fbeefc09f6bc19c" diff --git a/pyproject.toml b/pyproject.toml index 52f684f0e3..303e7d3c4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ profile = "black" [tool.poetry] name = "openshift-python-wrapper" version = "0.0.0" -description = "Wrapper around https://github.com/openshift/openshift-restclient-python" +description = "Wrapper around https://github.com/kubernetes-client/python" authors = ["Meni Yakove ", "Ruth Netser "] readme = "README.md" license = "Apache-2.0" @@ -39,6 +39,11 @@ Download = "https://pypi.org/project/openshift-python-wrapper/" [tool.poetry.group.dev.dependencies] ipdb = "^0.13.13" + +[tool.poetry.group.tests.dependencies] +pytest = "^7.4.0" +requests = "^2.31.0" + [tool.poetry-dynamic-versioning.substitution] files = ["VERSION"] @@ -52,7 +57,6 @@ build-backend = "poetry_dynamic_versioning.backend" [tool.poetry.dependencies] python = "^3.8" -openshift = "^0.13.2" xmltodict = "^0.13.0" colorlog = "^6.7.0" kubernetes = "^27.2.0" diff --git a/tests/test_resources.py b/tests/test_resources.py index 57d17c1ae1..721318ba68 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,6 +1,6 @@ import kubernetes import pytest -from openshift.dynamic import DynamicClient +from kubernetes.dynamic import DynamicClient from ocp_resources.namespace import Namespace from ocp_resources.pod import Pod diff --git a/tox.ini b/tox.ini index 888f3349fc..a6c29f572b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{38,39,310,311}, unittests, validate-resources +envlist = py{38,39,310,311}, unittests, validate-resources, tests skipsdist = True [flake8] @@ -16,24 +16,25 @@ setenv = PYTHONPATH = {toxinidir} passenv = KUBECONFIG -deps = - pytest commands = - pip install pip -U - pip install . - pip install jinja2 PyYaml - pytest -o log_cli=true tests/test_resources.py -k 'not kubevirt' + sh -c 'curl -sSL https://install.python-poetry.org | python3 -' + poetry install + poetry run pytest -o log_cli=true tests/test_resources.py -k 'not kubevirt' +allowlist_externals = + sh + poetry [testenv:unittests] basepython = python3 setenv = PYTHONPATH = {toxinidir} -deps = - pytest commands = - pip install pip -U - pip install . - pytest -o log_cli=true tests/unittests + sh -c 'curl -sSL https://install.python-poetry.org | python3 -' + poetry install + poetry run pytest -o log_cli=true tests/unittests +allowlist_externals = + sh + poetry [testenv:validate-resources] basepython = python3 @@ -41,10 +42,10 @@ setenv = PYTHONPATH = {toxinidir} passenv = KUBECONFIG -deps = - pytest - requests commands = - pip install pip -U - pip install . - pytest tests/test_validate_resources.py + sh -c 'curl -sSL https://install.python-poetry.org | python3 -' + poetry install + poetry run pytest tests/test_validate_resources.py +allowlist_externals = + sh + poetry