Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guillaume Hervier
slapos.core
Commits
8c55938f
Commit
8c55938f
authored
Jun 26, 2018
by
Guillaume Hervier
Committed by
Rafael Monnerat
Jul 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapgrid_test[portredir]: Add test for UDP tunnel
parent
6ba97a5c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
46 deletions
+52
-46
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+52
-46
No files found.
slapos/tests/slapgrid.py
View file @
8c55938f
...
@@ -2745,6 +2745,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -2745,6 +2745,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.instance_supervisord_config_path = os.path.join(
self.instance_supervisord_config_path = os.path.join(
self.instance_root, 'etc/supervisord.conf.d/0.conf')
self.instance_root, 'etc/supervisord.conf.d/0.conf')
self.port_redirect_path = os.path.join(self.partition.partition_path,
slapmanager.portredir.Manager.port_redirect_filename)
def _mock_requests(self):
def _mock_requests(self):
return httmock.HTTMock(self.computer.request_handler)
return httmock.HTTMock(self.computer.request_handler)
...
@@ -2752,19 +2755,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -2752,19 +2755,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
with open(self.instance_supervisord_config_path) as f:
with open(self.instance_supervisord_config_path) as f:
return f.read()
return f.read()
def test_partition_instance_with_port_redirection(self):
def _setup_instance(self, config):
with self._mock_requests():
with open(self.port_redirect_path, 'w+') as f:
port_redirect_path = os.path.join(self.partition.partition_path,
json.dump(config, f)
slapmanager.portredir.Manager.port_redirect_filename)
with open(port_redirect_path, 'w+') as f:
port_redirects = [
{
'srcPort': 1234,
'destPort': 4321,
'destAddress': '127.0.0.1',
},
]
json.dump(port_redirects, f)
self.partition.requested_state = 'started'
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.partition.software.setBuildout(WRAPPER_CONTENT)
...
@@ -2775,44 +2768,57 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -2775,44 +2768,57 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
'/startedComputerPartition'])
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
self.assertEqual(self.partition.state, 'started')
def test_simple_port_redirection(self):
with self._mock_requests():
self._setup_instance([
{
'srcPort': 1234,
'destPort': 4321,
'destAddress': '127.0.0.1',
}
])
# Check the socat command
# Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config()
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertIn('socat-{}'.format(1234), partition_supervisord_config)
self.assertIn('socat-
tcp-
{}'.format(1234), partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
def test_partition_instance_change_portredir_config(self):
def test_udp_port_redirection(self):
with self._mock_requests():
self._setup_instance([
{
'type': 'udp',
'srcPort': 1234,
'destPort': 4321,
'destAddress': '127.0.0.1',
}
])
# Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertIn('socat-udp-{}'.format(1234), partition_supervisord_config)
self.assertIn('socat UDP4-LISTEN:1234,fork UDP4:127.0.0.1:4321', partition_supervisord_config)
def test_portredir_config_change(self):
# We want the partition to just get updated, not recreated
# We want the partition to just get updated, not recreated
self.partition.timestamp = str(int(time.time()))
self.partition.timestamp = str(int(time.time()))
with self._mock_requests():
with self._mock_requests():
port_redirect_path = os.path.join(self.partition.partition_path,
self._setup_instance([
slapmanager.portredir.Manager.port_redirect_filename)
with open(port_redirect_path, 'w+') as f:
port_redirects = [
{
{
'srcPort': 1234,
'srcPort': 1234,
'destPort': 4321,
'destPort': 4321,
'destAddress': '127.0.0.1',
'destAddress': '127.0.0.1',
},
},
]
])
json.dump(port_redirects, f)
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation', '/availableComputerPartition',
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
# Check the socat command
# Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config()
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertIn('socat-{}'.format(1234), partition_supervisord_config)
self.assertIn('socat-
tcp-
{}'.format(1234), partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
# Remove the port binding from config
# Remove the port binding from config
with open(port_redirect_path, 'w+') as f:
with open(
self.
port_redirect_path, 'w+') as f:
json.dump([], f)
json.dump([], f)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
...
@@ -2824,5 +2830,5 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -2824,5 +2830,5 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
# Check the socat command
# Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config()
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertNotIn('socat-{}'.format(1234), partition_supervisord_config)
self.assertNotIn('socat-
tcp-
{}'.format(1234), partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment