Commit 27062418 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.

This change does not apply automatically after updating existing
instances, it is necessary to restart the embedded slapos proxy after
update, by running:

    supervisorctl -c ~/srv/runner/etc/supervisord.conf restart slapos-proxy

[1]: see slapos.core commit 2a53efca2 (proxy: bypass simple fronten
requests by returning URL, 2019-03-25)
parent db61f30e
......@@ -15,7 +15,7 @@
[instance-theia]
_update_hash_filename_ = instance-theia.cfg.jinja.in
md5sum = 153be75bad8e1f38fbf05fedbf99650d
md5sum = 3d00572afdd311ba8b4fc8b6ad0ac4b6
[instance]
_update_hash_filename_ = instance.cfg.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": true,
"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,67 @@ class TestTheiaFrontend(TheiaTestCase):
self.assertEqual(requests.codes.unauthorized, resp.status_code)
class TheiaForwardFrontendRequestsTestCase(TheiaTestCase):
forward_slapos_frontend_request = None
@classmethod
def getInstanceParameterDict(cls):
return {
'forward-slapos-frontend-requests': cls.forward_slapos_frontend_request
}
def setUp(self):
self.captureSlapos(
'request',
self.id(),
'http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg',
)
def tearDown(self):
self.captureSlapos(
'request',
'--state',
'destroyed',
self.id(),
'http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg', )
def getRequestedInstanceList(self):
with sqlite3.connect(os.path.join(
self.computer_partition_root_path,
'srv/runner/var/proxy.db',
)) as db:
query = "SELECT partition_reference FROM partition%s where slap_state='busy'" % DB_VERSION
return db.execute(query).fetchall()
def getForwardedInstanceList(self):
with sqlite3.connect(os.path.join(
self.computer_partition_root_path,
'srv/runner/var/proxy.db',
)) as db:
query = "SELECT partition_reference FROM forwarded_partition_request%s" % DB_VERSION
return db.execute(query).fetchall()
class TestTheiaForwardFrontendRequestsEnabled(
TheiaForwardFrontendRequestsTestCase):
forward_slapos_frontend_request = 'enabled'
def test(self):
self.assertEqual(
self.getForwardedInstanceList(),
# partition requested directly by user are forwarded with user_ prefix
[('user_' + self.id(), )])
self.assertEqual(self.getRequestedInstanceList(), [])
class TestTheiaForwardFrontendRequestsDisabled(
TheiaForwardFrontendRequestsTestCase):
forward_slapos_frontend_request = 'disabled'
def test(self):
self.assertEqual(self.getForwardedInstanceList(), [])
self.assertEqual(self.getRequestedInstanceList(), [(self.id(), )])
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