integ/python/python-kubernetes/centos/patches/0009-Fix-a-Python-2-compatibility-issue.patch
Kyle MacLeod e2ab5cc2c8 Patch watch.py in python-kubernetes package
Patch the python2-kubernetes-8.0.0-8.el7.noarch.rpm with recent
bug fix commits required for proper kubernetes watch functionality.

Patches watch.py up to commit 10ae476 in the 'base' repo
(kubernetes-client/python-base).

Commits are taken from the cloned github repo, saved in patch format,
and applied as a patch to the source RPM.

Reference:
https://github.com/kubernetes-client/python-base/commits/master/watch/watch.py

This patch includes commits beginning with d56fdbc, up to and including 10ae476

Testing:
- Built and testing on local distributed cloud system
- Similar testing to this patch but  ased on locally modified package
  has been done on 1000 subcloud system
- Examine/compare contents of installed package vs. expected
- Generating events which trigger the watch conditions
- Monitor watches for proper behaviour on expiry

Story: 2008960
Task: 43053

Signed-off-by: Kyle MacLeod <kyle.macleod@windriver.com>
Change-Id: I7ad78957b6ef61e7204c45f482f201d5c281385b
2021-08-25 17:05:03 -04:00

61 lines
1.8 KiB
Diff

From a54f404366c0800497f8b62122d7be77c143297f Mon Sep 17 00:00:00 2001
From: Nabarun Pal <pal.nabarun95@gmail.com>
Date: Thu, 16 Jul 2020 14:02:12 +0530
Subject: [PATCH 09/13] Fix a Python 2 compatibility issue
PR #133 introduces the usage of `http` module for checking the status
code for `GONE` HTTP status. However, this doesn't work in Python 2.7.
This commit checks if the interpreter is Python 2 and imports the
status code from `httplib` module instead and unifies the approach
to the checks.
Signed-off-by: Nabarun Pal <pal.nabarun95@gmail.com>
---
watch/watch.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/watch/watch.py b/watch/watch.py
index f67dbe4..6410dfa 100644
--- a/watch/watch.py
+++ b/watch/watch.py
@@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import http
import json
import pydoc
+import sys
from kubernetes import client
@@ -29,6 +29,15 @@ PYDOC_FOLLOW_PARAM = ":param bool follow:"
TYPE_LIST_SUFFIX = "List"
+PY2 = sys.version_info[0] == 2
+if PY2:
+ import httplib
+ HTTP_STATUS_GONE = httplib.GONE
+else:
+ import http
+ HTTP_STATUS_GONE = http.HTTPStatus.GONE
+
+
class SimpleNamespace:
def __init__(self, **kwargs):
@@ -158,7 +167,7 @@ class Watch(object):
# Current request expired, let's retry,
# but only if we have not already retried.
if not retry_after_410 and \
- obj['code'] == http.HTTPStatus.GONE:
+ obj['code'] == HTTP_STATUS_GONE:
retry_after_410 = True
break
else:
--
2.25.1