Skip to content
Snippets Groups Projects
Commit c5ba3df4 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS: added 'host' option to tmss_test_environment

parent 4f6e4ef6
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ services: ...@@ -6,7 +6,7 @@ services:
restart: on-failure restart: on-failure
env_file: env_file:
- ./.env - ./.env
command: bash -c 'source /opt/lofar/lofarinit.sh && tmss_test_environment -p 8008' command: bash -c 'source /opt/lofar/lofarinit.sh && ALLOWED_HOSTS=* tmss_test_environment -H 0.0.0.0 -p 8008'
ports: ports:
- "8008:8008" - "8008:8008"
testprovider: testprovider:
......
...@@ -113,16 +113,17 @@ class TMSSPostgresTestMixin(PostgresTestMixin): ...@@ -113,16 +113,17 @@ class TMSSPostgresTestMixin(PostgresTestMixin):
class TMSSDjangoServerInstance(): class TMSSDjangoServerInstance():
''' Creates a running django TMSS server at the requested port with the requested database credentials. ''' Creates a running django TMSS server at the requested port with the requested database credentials.
''' '''
def __init__(self, db_dbcreds_id: str="TMSS", ldap_dbcreds_id: str="TMSS_LDAP", port: int=8000): def __init__(self, db_dbcreds_id: str="TMSS", ldap_dbcreds_id: str="TMSS_LDAP", host: str='127.0.0.1', port: int=8000):
self._db_dbcreds_id = db_dbcreds_id self._db_dbcreds_id = db_dbcreds_id
self._ldap_dbcreds_id = ldap_dbcreds_id self._ldap_dbcreds_id = ldap_dbcreds_id
self.host = host
self.port = port self.port = port
self._server_process = None self._server_process = None
@property @property
def address(self): def address(self):
''':returns the address and port of the django server''' ''':returns the address and port of the django server'''
return "127.0.0.1:%d" % self.port return "%s:%d" % (self.host, self.port)
@property @property
def url(self): def url(self):
...@@ -240,11 +241,12 @@ class TMSSDjangoServerInstance(): ...@@ -240,11 +241,12 @@ class TMSSDjangoServerInstance():
class TMSSTestEnvironment: class TMSSTestEnvironment:
'''Create and run a test django TMSS server against a newly created test database and a test ldap server (and cleanup automagically)''' '''Create and run a test django TMSS server against a newly created test database and a test ldap server (and cleanup automagically)'''
def __init__(self, preferred_django_port: int=8000): def __init__(self, host: str='127.0.0.1', preferred_django_port: int=8000):
self.ldap_server = TestLDAPServer(user='test', password='test') self.ldap_server = TestLDAPServer(user='test', password='test')
self.database = TMSSTestDatabaseInstance() self.database = TMSSTestDatabaseInstance()
self.django_server = TMSSDjangoServerInstance(db_dbcreds_id=self.database.dbcreds_id, self.django_server = TMSSDjangoServerInstance(db_dbcreds_id=self.database.dbcreds_id,
ldap_dbcreds_id=self.ldap_server.dbcreds_id, ldap_dbcreds_id=self.ldap_server.dbcreds_id,
host=host,
port=find_free_port(preferred_django_port)) port=find_free_port(preferred_django_port))
def start(self): def start(self):
...@@ -310,13 +312,15 @@ def main_test_environment(): ...@@ -310,13 +312,15 @@ def main_test_environment():
parser = OptionParser('%prog [options]', parser = OptionParser('%prog [options]',
description='setup/run/teardown a full TMSS test environment including a fresh and isolated database, LDAP server and DJANGO REST server.') description='setup/run/teardown a full TMSS test environment including a fresh and isolated database, LDAP server and DJANGO REST server.')
parser.add_option("-H", "--host", dest="host", type="string", default='127.0.0.1',
help="expose the TMSS Django REST API via this host. [default=%default]")
parser.add_option("-p", "--port", dest="port", type="int", default=find_free_port(8000), parser.add_option("-p", "--port", dest="port", type="int", default=find_free_port(8000),
help="try to use this port for the DJANGO REST API. If not available, then a random free port is used and logged. [default=%default]") help="try to use this port for the DJANGO REST API. If not available, then a random free port is used and logged. [default=%default]")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
logging.basicConfig(format = '%(asctime)s %(levelname)s %(message)s', level = logging.INFO) logging.basicConfig(format = '%(asctime)s %(levelname)s %(message)s', level = logging.INFO)
with TMSSTestEnvironment(preferred_django_port=options.port) as instance: with TMSSTestEnvironment(host=options.host, preferred_django_port=options.port) as instance:
# print some nice info for the user to use the test servers... # print some nice info for the user to use the test servers...
# use print instead of log for clean lines. # use print instead of log for clean lines.
for h in logging.root.handlers: for h in logging.root.handlers:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment