Skip to content

Commit

Permalink
Implement back end raw port test container using python.
Browse files Browse the repository at this point in the history
  • Loading branch information
iciclespider committed Nov 22, 2020
1 parent eb9b6d6 commit bcdd656
Showing 1 changed file with 60 additions and 11 deletions.
71 changes: 60 additions & 11 deletions kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.

import json
import os
import select
import socket
import time
Expand Down Expand Up @@ -167,17 +168,64 @@ def test_portforward_raw(self):
client = api_client.ApiClient(configuration=self.config)
api = core_v1_api.CoreV1Api(client)

with open(os.path.join(os.path.dirname(__file__), 'port_server.py')) as fh:
port_server_py = fh.read()
name = 'portforward-raw-' + short_uuid()
pod_manifest = manifest_with_command(
name,
' '.join((
'((while true;do nc -l -p 1234 -e /bin/cat; done)&);',
'((while true;do nc -l -p 1235 -e /bin/cat; done)&);',
'sleep 60',
))
resp = api.create_namespaced_config_map(
body={
'apiVersion': 'v1',
'kind': 'ConfigMap',
'metadata': {
'name': name,
},
'data': {
'port-server.py': port_server_py,
}
},
namespace='default',
)
resp = api.create_namespaced_pod(
body={
'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {
'name': name
},
'spec': {
'containers': [
{
'name': 'port-server',
'image': 'python',
'command': [
'/opt/port-server.py', '1234', '1235',
],
'volumeMounts': [
{
'name': 'port-server',
'mountPath': '/opt',
'readOnly': True,
},
],
'startupProbe': {
'tcpSocket': {
'port': 1234,
},
},
},
],
'volumes': [
{
'name': 'port-server',
'configMap': {
'name': name,
'defaultMode': 0o777,
},
},
],
},
},
namespace='default',
)
resp = api.create_namespaced_pod(body=pod_manifest,
namespace='default')
self.assertEqual(name, resp.metadata.name)
self.assertTrue(resp.status.phase)

Expand All @@ -189,6 +237,7 @@ def test_portforward_raw(self):
if resp.status.phase != 'Pending':
break
time.sleep(1)
self.assertEqual(resp.status.phase, 'Running')

pf = portforward(api.connect_get_namespaced_pod_portforward,
name, 'default',
Expand Down Expand Up @@ -251,8 +300,8 @@ def test_portforward_raw(self):
self.assertIsNone(pf.error(1234))
self.assertIsNone(pf.error(1235))

resp = api.delete_namespaced_pod(name=name, body={},
namespace='default')
resp = api.delete_namespaced_pod(name=name, namespace='default')
resp = api.delete_namespaced_config_map(name=name, namespace='default')

def test_portforward_http(self):
client = api_client.ApiClient(configuration=self.config)
Expand Down

0 comments on commit bcdd656

Please sign in to comment.