Commit 2c594b7d authored by Jérome Perrin's avatar Jérome Perrin

software/theia: parameter to disable forwarded frontend requests

In some cases, for example when the instance does not have internet
access, or to speed up slapos node instance, it's better not to have
frontend requests in the embedded slapos. In this case, the default
slapos proxy behavior of returning a "fake frontend" [1] will apply
and promises checking frontend status will pass anyway.

[1]: see slapos.core commit 2a53efca2 (proxy: bypass simple fronten
requests by returning URL, 2019-03-25)
parent c8845442
......@@ -15,11 +15,11 @@
[instance-theia]
_update_hash_filename_ = instance-theia.cfg.jinja.in
md5sum = 153be75bad8e1f38fbf05fedbf99650d
md5sum = 3d00572afdd311ba8b4fc8b6ad0ac4b6
[instance]
_update_hash_filename_ = instance.cfg.in
md5sum = e211c439571e2900f9f35482c9638d06
md5sum = 08b8aa2b7f59ac0e4e5d4ca180054937
[instance-import]
_update_hash_filename_ = instance-import.cfg.jinja.in
......
......@@ -25,6 +25,16 @@
"{\"software-url\": \"~/srv/project/slapos/software/html5as/software.cfg\", \"software-type\": \"replicate\", \"instance-parameters\": {\"replicate-quantity\": 3}}"
]
},
"forward-slapos-frontend-requests": {
"title": "Forward Frontend Requests in the Embedded SlapOS",
"description": "Embedded SlapOS instance by default forwards frontend requests as shared instances attached to the Theia instance, so that HTTP frontends can be allocated for services. This behavior can be disabled, in that case frontends will not be allocated.",
"type": "string",
"enum": [
"enabled",
"disabled"
],
"default": "enabled"
},
"frontend-guid": {
"title": "Frontend Instance ID",
"description": "Unique identifier of the frontend instance, like \"SOFTINST-11031\".",
......
......@@ -535,7 +535,7 @@ context =
key forward_frontend_requests :forward-frontend-requests
section slap_connection slap-connection
section slapos_standalone_config slapos-standalone-config
forward-frontend-requests = enabled
forward-frontend-requests = {{ parameter_dict['forward-slapos-frontend-requests'] }}
url = ${slapos-standalone-script:output}
[slapos-standalone]
......
......@@ -45,6 +45,7 @@ default-parameters =
{
"autorun": "running",
"initial-embedded-instance": null,
"forward-slapos-frontend-requests": "enabled",
"frontend-name": "Theia Frontend",
"frontend-sr": "$${:frontend-sr}",
"frontend-sr-type": "RootSoftwareInstance",
......
......@@ -31,6 +31,7 @@ import logging
import os
import re
import subprocess
import sqlite3
import time
import pexpect
......@@ -42,6 +43,7 @@ from six.moves.urllib.parse import urlparse, urljoin
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass, SlapOSNodeCommandError
from slapos.grid.svcbackend import getSupervisorRPC, _getSupervisordSocketPath
from slapos.proxy.db_version import DB_VERSION
theia_software_release_url = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))
......@@ -356,6 +358,60 @@ class TestTheiaFrontend(TheiaTestCase):
self.assertEqual(requests.codes.unauthorized, resp.status_code)
class TestTheiaForwardFrontendRequestsEnabled(TheiaTestCase):
@classmethod
def getInstanceParameterDict(cls):
return {"autorun": "user-controlled"} # we interact with slapos in this test
def _getRequestedInstanceList(self, query):
with sqlite3.connect(os.path.join(
self.computer_partition_root_path,
'srv/runner/var/proxy.db',
)) as db:
return [row[0] for row in db.execute(query).fetchall()]
def getRequestedInstanceList(self):
return self._getRequestedInstanceList(
f"SELECT partition_reference FROM partition{DB_VERSION} where slap_state='busy'"
)
def getForwardedInstanceList(self):
return self._getRequestedInstanceList(
f"SELECT partition_reference FROM forwarded_partition_request{DB_VERSION}"
)
def requestEmbeddedFrontendInstance(self, state='available'):
self.checkSlapos(
'request',
'--state',
state,
'frontend',
'http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg',
)
def test(self):
self.requestEmbeddedFrontendInstance()
# partition requested directly by user are forwarded with user_ prefix
self.assertEqual(self.getForwardedInstanceList(), ['user_frontend'])
self.assertEqual(self.getRequestedInstanceList(), [])
self.requestEmbeddedFrontendInstance(state='destroyed')
self.requestInstance({'forward-slapos-frontend-requests': 'disabled'})
self.waitForInstance()
self.requestEmbeddedFrontendInstance()
self.assertEqual(self.getForwardedInstanceList(), [])
self.assertEqual(self.getRequestedInstanceList(), ['frontend'])
self.requestEmbeddedFrontendInstance(state='destroyed')
self.checkSlapos('node', 'report')
self.requestInstance({'forward-slapos-frontend-requests': 'enabled'})
self.waitForInstance()
self.requestEmbeddedFrontendInstance()
self.assertEqual(self.getForwardedInstanceList(), ['user_frontend'])
self.assertEqual(self.getRequestedInstanceList(), [])
class TestTheiaEnv(TheiaTestCase):
dummy_software_path = os.path.abspath('dummy/software.cfg')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment