diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-01-10 11:11:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-10 11:11:46 -0800 |
commit | 6524041fb0ebfc35dafe3bb7bebbd4dfa27ba5e8 (patch) | |
tree | cf6e4191124ea1c44b9cadb504c0b2f5e6269a50 /contrib/python/podman/test/test_tunnel.py | |
parent | e4525cf844535014923a2253e8531d92d9e556e5 (diff) | |
parent | 45fb935fe44a383ae14f16ab533281687d642c5e (diff) | |
download | podman-6524041fb0ebfc35dafe3bb7bebbd4dfa27ba5e8.tar.gz podman-6524041fb0ebfc35dafe3bb7bebbd4dfa27ba5e8.tar.bz2 podman-6524041fb0ebfc35dafe3bb7bebbd4dfa27ba5e8.zip |
Merge pull request #2119 from jwhonce/wip/python_podman
Move python code from contrib to it's own repo python-podman
Diffstat (limited to 'contrib/python/podman/test/test_tunnel.py')
-rw-r--r-- | contrib/python/podman/test/test_tunnel.py | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/contrib/python/podman/test/test_tunnel.py b/contrib/python/podman/test/test_tunnel.py deleted file mode 100644 index 9a33e76cd..000000000 --- a/contrib/python/podman/test/test_tunnel.py +++ /dev/null @@ -1,86 +0,0 @@ -from __future__ import absolute_import - -import logging -import time -import unittest -from unittest.mock import MagicMock, patch - -from podman.libs.tunnel import Context, Portal, Tunnel - - -class TestTunnel(unittest.TestCase): - def setUp(self): - self.tunnel_01 = MagicMock(spec=Tunnel) - self.tunnel_02 = MagicMock(spec=Tunnel) - - def test_portal_ops(self): - portal = Portal(sweap=500) - portal['unix:/01'] = self.tunnel_01 - portal['unix:/02'] = self.tunnel_02 - - self.assertEqual(portal.get('unix:/01'), self.tunnel_01) - self.assertEqual(portal.get('unix:/02'), self.tunnel_02) - - del portal['unix:/02'] - with self.assertRaises(KeyError): - portal['unix:/02'] - self.assertEqual(len(portal), 1) - - def test_portal_reaping(self): - portal = Portal(sweap=0.5) - portal['unix:/01'] = self.tunnel_01 - portal['unix:/02'] = self.tunnel_02 - - self.assertEqual(len(portal), 2) - for entry in portal: - self.assertIn(entry, (self.tunnel_01, self.tunnel_02)) - - time.sleep(1) - portal.reap() - self.assertEqual(len(portal), 0) - - def test_portal_no_reaping(self): - portal = Portal(sweap=500) - portal['unix:/01'] = self.tunnel_01 - portal['unix:/02'] = self.tunnel_02 - - portal.reap() - self.assertEqual(len(portal), 2) - for entry in portal: - self.assertIn(entry, (self.tunnel_01, self.tunnel_02)) - - @patch('subprocess.Popen') - @patch('os.path.exists', return_value=True) - @patch('weakref.finalize') - def test_tunnel(self, mock_finalize, mock_exists, mock_Popen): - mock_Popen.return_value.returncode = 0 - - context = Context( - 'unix:/01', - 'io.podman', - '/tmp/user/socket', - '/run/podman/socket', - 'user', - 'hostname', - None, - '~/.ssh/id_rsa', - ) - tunnel = Tunnel(context).bore() - - cmd = ['ssh', '-fNT'] - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - cmd.append('-v') - else: - cmd.append('-q') - - cmd.extend(( - '-L', - '{}:{}'.format(context.local_socket, context.remote_socket), - '-i', - context.identity_file, - '{}@{}'.format(context.username, context.hostname), - )) - - mock_finalize.assert_called_once_with(tunnel, tunnel.close) - mock_exists.assert_called_once_with(context.local_socket) - mock_Popen.assert_called_once_with(cmd, close_fds=True) |