From 9e3641da11c7a7216b1d88fd147cfdd07b2f96e7 Mon Sep 17 00:00:00 2001 From: Haowei Cai Date: Mon, 16 Aug 2021 13:47:51 -0700 Subject: [PATCH] apply hotfixes --- kubernetes/client/api/custom_objects_api.py | 12 +++--- kubernetes/client/apis/__init__.py | 13 +++++++ .../models/v1_projected_volume_source.py | 3 -- kubernetes/test/test_api_client.py | 25 ++++++++++++ kubernetes/test/test_configuration.py | 39 +++++++++++++++++++ 5 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 kubernetes/client/apis/__init__.py create mode 100644 kubernetes/test/test_api_client.py create mode 100644 kubernetes/test/test_configuration.py diff --git a/kubernetes/client/api/custom_objects_api.py b/kubernetes/client/api/custom_objects_api.py index 613763b59..2e038a914 100644 --- a/kubernetes/client/api/custom_objects_api.py +++ b/kubernetes/client/api/custom_objects_api.py @@ -2425,7 +2425,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 @@ -2594,7 +2594,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 @@ -2763,7 +2763,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 @@ -2941,7 +2941,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 @@ -3119,7 +3119,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json', 'application/apply-patch+yaml']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 @@ -3297,7 +3297,7 @@ class CustomObjectsApi(object): # HTTP header `Content-Type` header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json-patch+json', 'application/merge-patch+json', 'application/apply-patch+yaml']) # noqa: E501 + ['application/merge-patch+json']) # noqa: E501 # Authentication setting auth_settings = ['BearerToken'] # noqa: E501 diff --git a/kubernetes/client/apis/__init__.py b/kubernetes/client/apis/__init__.py new file mode 100644 index 000000000..ca4b321de --- /dev/null +++ b/kubernetes/client/apis/__init__.py @@ -0,0 +1,13 @@ +from __future__ import absolute_import +import warnings + +# flake8: noqa + +# alias kubernetes.client.api package and print deprecation warning +from kubernetes.client.api import * + +warnings.filterwarnings('default', module='kubernetes.client.apis') +warnings.warn( + "The package kubernetes.client.apis is renamed and deprecated, use kubernetes.client.api instead (please note that the trailing s was removed).", + DeprecationWarning +) diff --git a/kubernetes/client/models/v1_projected_volume_source.py b/kubernetes/client/models/v1_projected_volume_source.py index a2f41d730..ab8c66a26 100644 --- a/kubernetes/client/models/v1_projected_volume_source.py +++ b/kubernetes/client/models/v1_projected_volume_source.py @@ -99,9 +99,6 @@ class V1ProjectedVolumeSource(object): :param sources: The sources of this V1ProjectedVolumeSource. # noqa: E501 :type: list[V1VolumeProjection] """ - if self.local_vars_configuration.client_side_validation and sources is None: # noqa: E501 - raise ValueError("Invalid value for `sources`, must not be `None`") # noqa: E501 - self._sources = sources def to_dict(self): diff --git a/kubernetes/test/test_api_client.py b/kubernetes/test/test_api_client.py new file mode 100644 index 000000000..f0a9416cf --- /dev/null +++ b/kubernetes/test/test_api_client.py @@ -0,0 +1,25 @@ +# coding: utf-8 + + +import atexit +import weakref +import unittest + +import kubernetes + + +class TestApiClient(unittest.TestCase): + + def test_context_manager_closes_threadpool(self): + with kubernetes.client.ApiClient() as client: + self.assertIsNotNone(client.pool) + pool_ref = weakref.ref(client._pool) + self.assertIsNotNone(pool_ref()) + self.assertIsNone(pool_ref()) + + def test_atexit_closes_threadpool(self): + client = kubernetes.client.ApiClient() + self.assertIsNotNone(client.pool) + self.assertIsNotNone(client._pool) + atexit._run_exitfuncs() + self.assertIsNone(client._pool) diff --git a/kubernetes/test/test_configuration.py b/kubernetes/test/test_configuration.py new file mode 100644 index 000000000..15e065090 --- /dev/null +++ b/kubernetes/test/test_configuration.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +import unittest + +from kubernetes.client import Configuration + +class TestConfiguration(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + # reset Configuration + Configuration.set_default(None) + + def testConfiguration(self): + # check that different instances use different dictionaries + c1 = Configuration() + c2 = Configuration() + self.assertNotEqual(id(c1.api_key), id(c2.api_key)) + self.assertNotEqual(id(c1.api_key_prefix), id(c2.api_key_prefix)) + + def testDefaultConfiguration(self): + # prepare default configuration + c1 = Configuration(host="example.com") + c1.debug = True + Configuration.set_default(c1) + + # get default configuration + c2 = Configuration.get_default_copy() + self.assertEqual(c2.host, "example.com") + self.assertTrue(c2.debug) + + self.assertNotEqual(id(c1.api_key), id(c2.api_key)) + self.assertNotEqual(id(c1.api_key_prefix), id(c2.api_key_prefix)) + + +if __name__ == '__main__': + unittest.main()