8000 Merge pull request #1529 from hedrox/bug-rc-delete · kubernetes-client/python@be51b01 · GitHub
[go: up one dir, main page]

Skip to content

Commit be51b01

Browse files
authored
Merge pull request #1529 from hedrox/bug-rc-delete
Fix replication controller pods delete in tests
2 parents 8a36dfb + 740cda6 commit be51b01

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

kubernetes/e2e_test/test_batch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class TestClientBatch(unittest.TestCase):
2626
def setUpClass(cls):
2727
cls.config = base.get_e2e_configuration()
2828

29-
3029
def test_job_apis(self):
3130
client = api_client.ApiClient(configuration=self.config)
3231
api = batch_v1_api.BatchV1Api(client)
@@ -56,4 +55,4 @@ def test_job_apis(self):
5655
self.assertEqual(name, resp.metadata.name)
5756

5857
resp = api.delete_namespaced_job(
59-
name=name, body={}, namespace='default')
58+
name=name, namespace='default', propagation_policy='Background')

kubernetes/e2e_test/test_client.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
else:
3636
import httplib
3737

38+
3839
def short_uuid():
3940
id = str(uuid.uuid4())
4041
return id[-12:]
@@ -60,6 +61,7 @@ def manifest_with_command(name, command):
6061
}
6162
}
6263

64+
6365
class TestClient(unittest.TestCase):
6466

6567
@classmethod
@@ -71,7 +73,8 @@ def test_pod_apis(self):
7173
api = core_v1_api.CoreV1Api(client)
7274

7375
name = 'busybox-test-' + short_uuid()
74-
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
76+
pod_manifest = manifest_with_command(
77+
name, "while true;do date;sleep 5; done")
7578

7679
# wait for the default service account to be created
7780
timeout = time.time() + 30
@@ -84,9 +87,10 @@ def test_pod_apis(self):
8487
namespace='default')
8588
except ApiException as e:
8689
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
87-
six.PY3 is False and e.status != httplib.NOT_FOUND):
90+
six.PY3 is False and e.status != httplib.NOT_FOUND):
8891
print('error: %s' % e)
89-
self.fail(msg="unexpected error getting default service account")
92+
self.fail(
93+
msg="unexpected error getting default service account")
9094
print('default service not found yet: %s' % e)
9195
time.sleep(1)
9296
continue
@@ -111,25 +115,25 @@ def test_pod_apis(self):
111115
'-c',
112116
'for i in $(seq 1 3); do date; done']
113117
resp = stream(api.connect_get_namespaced_pod_exec, name, 'default',
114-
command=exec_command,
115-
stderr=False, stdin=False,
116-
stdout=True, tty=False)
118+
command=exec_command,
119+
stderr=False, stdin=False,
120+
stdout=True, tty=False)
117121
print('EXEC response : %s' % resp)
118122
self.assertEqual(3, len(resp.splitlines()))
119123

120124
exec_command = 'uptime'
121125
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
122-
command=exec_command,
123-
stderr=False, stdin=False,
124-
stdout=True, tty=False)
126+
command=exec_command,
127+
stderr=False, stdin=False,
128+
stdout=True, tty=False)
125129
print('EXEC response : %s' % resp)
126130
self.assertEqual(1, len(resp.splitlines()))
127131

128132
resp = stream(api.connect_post_namespaced_pod_exec, name, 'default',
129-
command='/bin/sh',
130-
stderr=True, stdin=True,
131-
stdout=True, tty=False,
132-
_preload_content=False)
133+
command='/bin/sh',
134+
stderr=True, stdin=True,
135+
stdout=True, tty=False,
136+
_preload_content=False)
133137
resp.write_stdin("echo test string 1\n")
134138
line = resp.readline_stdout(timeout=5)
135139
self.assertFalse(resp.peek_stderr())
@@ -157,7 +161,8 @@ def test_exit_code(self):
157161
api = core_v1_api.CoreV1Api(client)
158162

159163
name = 'busybox-test-' + short_uuid()
160-
pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
164+
pod_manifest = manifest_with_command(
165+
name, "while true;do date;sleep 5; done")
161166

162167
# wait for the default service account to be created
163168
timeout = time.time() + 30
@@ -171,9 +176,10 @@ def test_exit_code(self):
171176
namespace='default')
172177
except ApiException as e:
173178
if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or (
174-
six.PY3 is False and e.status != httplib.NOT_FOUND):
179+
six.PY3 is False and e.status != httplib.NOT_FOUND):
175180
print('error: %s' % e)
176-
self.fail(msg="unexpected error getting default service account")
181+
self.fail(
182+
msg="unexpected error getting default service account")
177183
print('default service not found yet: %s' % e)
178184
time.sleep(1)
179185
continue
@@ -201,11 +207,16 @@ def test_exit_code(self):
201207
(["/bin/sh", "-c", "ls /"], 0)
202208
)
203209
for command, value in commands_expected_values:
204-
client = stream(api.connect_get_namespaced_pod_exec, name, 'default',
205-
command=command,
206-
stderr=True, stdin=False,
207-
stdout=True, tty=False,
208-
_preload_content=False)
210+
client = stream(
211+
api.connect_get_namespaced_pod_exec,
212+
name,
213+
'default',
214+
command=command,
215+
stderr=True,
216+
stdin=False,
217+
stdout=True,
218+
tty=False,
219+
_preload_content=False)
209220

210221
self.assertIsNone(client.returncode)
211222
client.run_forever(timeout=10)
@@ -337,7 +348,8 @@ def test_portforward_raw(self):
337348

338349
for sock in (sock1234, sock1235):
339350
self.assertTrue(pf.connected)
340-
sent = b'Another test using fileno %s' % str(sock.fileno()).encode()
351+
sent = b'Another test using fileno %s' % str(
352+
sock.fileno()).encode()
341353
sock.sendall(sent)
342354
reply = b''
343355
while True:
@@ -361,7 +373,7 @@ def test_portforward_http(self):
361373
client = api_client.ApiClient(configuration=self.config)
362374
api = core_v1_api.CoreV1Api(client)
363375

364-
name = 'portforward-http-' + short_uuid()
376+
name = 'portforward-http-' + short_uuid()
365377
pod_manifest = {
366378
'apiVersion': 'v1',
367379
'kind': 'Pod',
@@ -404,7 +416,8 @@ def kubernetes_create_connection(address, *args, **kwargs):
404416
socket_create_connection = socket.create_connection
405417
try:
406418
socket.create_connection = kubernetes_create_connection
407-
response = urllib_request.urlopen('http://%s.default.kubernetes/' % name)
419+
response = urllib_request.urlopen(
420+
'http://%s.default.kubernetes/' % name)
408421
html = response.read().decode('utf-8')
409422
finally:
410423
socket.create_connection = socket_create_connection
@@ -485,7 +498,7 @@ def test_replication_controller_apis(self):
485498
self.assertEqual(2, resp.spec.replicas)
486499

487500
resp = api.delete_namespaced_replication_controller(
488-
name=name, body={}, namespace='default')
501+
name=name, namespace='default', propagation_policy='Background')
489502

490503
def test_configmap_apis(self):
491504
client = api_client.ApiClient(configuration=self.config)
@@ -521,7 +534,8 @@ def test_configmap_apis(self):
521534
resp = api.delete_namespaced_config_map(
522535
name=name, body={}, namespace='default')
523536

524-
resp = api.list_namespaced_config_map('default', pretty=True, label_selector="e2e-tests=true")
537+
resp = api.list_namespaced_config_map(
538+
'default', pretty=True, label_selector="e2e-tests=true")
525539
self.assertEqual([], resp.items)
526540

527541
def test_node_apis(self):

kubernetes/e2e_test/test_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def setUpClass(cls):
3131
cls.test_namespace = "e2e-test-utils"
3232
k8s_client = client.api_client.ApiClient(configuration=cls.config)
3333
core_v1 = client.CoreV1Api(api_client=k8s_client)
34-
body = client.V1Namespace(metadata=client.V1ObjectMeta(name=cls.test_namespace))
34+
body = client.V1Namespace(
35+
metadata=client.V1ObjectMeta(
36+
name=cls.test_namespace))
3537
core_v1.create_namespace(body=body)
3638

3739
@classmethod
@@ -304,7 +306,7 @@ def test_create_from_multi_resource_yaml(self):
304306
name="mock", namespace="default")
305307
self.assertIsNotNone(ctr)
306308
core_api.delete_namespaced_replication_controller(
307-
name="mock", namespace="default", body={})
309+
name="mock", namespace="default", propagation_policy="Background")
308310
core_api.delete_namespaced_service(name="mock",
309311
namespace="default", body={})
310312

@@ -362,7 +364,7 @@ def test_create_from_multi_resource_yaml_with_conflict(self):
362364
name="mock-2", namespace="default")
363365
self.assertIsNotNone(ctr)
364366
core_api.delete_namespaced_replication_controller(
365-
name="mock-2", namespace="default", body={})
367+
name="mock-2", namespace="default", propagation_policy="Background")
366368
core_api.delete_namespaced_service(name="mock-2",
367369
namespace="default", body={})
368370

@@ -396,7 +398,7 @@ def test_create_from_multi_resource_yaml_with_multi_conflicts(self):
396398
def test_create_namespaced_apps_deployment_from_yaml(self):
397399
"""
398400
Should be able to create an apps/v1beta1 deployment
399-
in a test namespace.
401+
in a test namespace.
400402
"""
401403
k8s_client = client.api_client.ApiClient(configuration=self.config)
402404
utils.create_from_yaml(

0 commit comments

Comments
 (0)
0