diff --git a/LCS/PyCommon/test/dbcredentials.py b/LCS/PyCommon/test/dbcredentials.py index 272b7b1f56d435101bcadf00c3332c4df40756af..e952e245cb1dc7af834d59014c8c6b0a4b4ba3ea 100755 --- a/LCS/PyCommon/test/dbcredentials.py +++ b/LCS/PyCommon/test/dbcredentials.py @@ -31,8 +31,8 @@ class TemporaryCredentials(): ''' A helper class which creates/destroys dbcredentials automatically. Best used in a 'with'-context so the server is destroyed automagically. ''' - def __init__(self, user: str = 'test', password: str='test') -> None: - self.dbcreds_id = str(uuid.uuid4()) + def __init__(self, user: str = 'test', password: str='test', dbcreds_id: str=None) -> None: + self.dbcreds_id = dbcreds_id or str(uuid.uuid4()) self.dbcreds = Credentials() self.dbcreds.user = user self.dbcreds.password = password diff --git a/LCS/PyCommon/test/postgres.py b/LCS/PyCommon/test/postgres.py index 0d49da62e4689cfd660313d954f3e3a194885443..f6702594972e8018653c98cb320e817bbc7295e2 100755 --- a/LCS/PyCommon/test/postgres.py +++ b/LCS/PyCommon/test/postgres.py @@ -41,9 +41,9 @@ class PostgresTestDatabaseInstance(): ''' _named_lock = NamedAtomicLock('PostgresTestDatabaseInstance') - def __init__(self, user: str = 'test_user', preferred_port: int=5444) -> None: + def __init__(self, user: str = 'test_user', dbcreds_id: str=None, preferred_port: int=5444) -> None: self._postgresql = None - self.tmp_creds = TemporaryCredentials(user=user) + self.tmp_creds = TemporaryCredentials(user=user, dbcreds_id=dbcreds_id) self.tmp_creds.dbcreds.port = preferred_port def __enter__(self): diff --git a/SAS/TMSS/services/tmss_postgres_listener/bin/tmss_postgres_listener_service b/SAS/TMSS/services/tmss_postgres_listener/bin/tmss_postgres_listener_service old mode 100644 new mode 100755 diff --git a/SAS/TMSS/services/tmss_postgres_listener/lib/tmss_postgres_listener.py b/SAS/TMSS/services/tmss_postgres_listener/lib/tmss_postgres_listener.py index 07ca7801b97003d1756307f90fa10c40a61ad67b..0ebcb70ac5866bf8682633730ecb7a99682f4c3c 100644 --- a/SAS/TMSS/services/tmss_postgres_listener/lib/tmss_postgres_listener.py +++ b/SAS/TMSS/services/tmss_postgres_listener/lib/tmss_postgres_listener.py @@ -28,13 +28,13 @@ from lofar.messaging.messagebus import ToBus from lofar.sas.tmss.client.tmssbuslistener import * from lofar.common import dbcredentials from lofar.common.util import single_line_with_single_spaces -from lofar.sas.tmss.tmss.tmssapp.models import Subtask, SchedulingUnitBlueprint class TMSSPGListener(PostgresListener): '''This class subscribes to the Subtask, TaskDraft/Blueprint & SchedulingUnitDraft/Blueprint tables in the TMSS database and send EventMessages upon each table row action, *Created, *Updated, *Deleted, and for each status update. See lofar.sas.tmss.client.tmssbuslistener.TMSSBusListener for the receiving BusListener''' + def __init__(self, dbcreds, exchange=DEFAULT_BUSNAME, @@ -148,6 +148,7 @@ class TMSSPGListener(PostgresListener): def onSubTaskStateUpdated(self, payload = None): payload_dict = json.loads(payload) # send notification for this subtask... + from lofar.sas.tmss.tmss.tmssapp.models import Subtask subtask = Subtask.objects.get(id=payload_dict['id']) self._sendNotification(TMSS_SUBTASK_STATUS_EVENT_PREFIX+'.'+subtask.state.value.capitalize(), {'id': subtask.id, 'status': subtask.state.value}) @@ -187,7 +188,8 @@ class TMSSPGListener(PostgresListener): def onSchedulingUnitBlueprintUpdated(self, payload = None): self._sendNotification(TMSS_SCHEDULINGUNITBLUEPRINT_OBJECT_EVENT_PREFIX+'.Updated', payload) - + + from lofar.sas.tmss.tmss.tmssapp.models import SchedulingUnitBlueprint scheduling_unit_blueprint = SchedulingUnitBlueprint.objects.get(id=payload['id']) if not scheduling_unit_blueprint.can_proceed: diff --git a/SAS/TMSS/test/ldap_test_service.py b/SAS/TMSS/test/ldap_test_service.py index 48dcc25102d302e29dc1a205e8670c9dbad69498..b80e419adbafed123862950c1a3a691e2ccd1807 100644 --- a/SAS/TMSS/test/ldap_test_service.py +++ b/SAS/TMSS/test/ldap_test_service.py @@ -29,8 +29,8 @@ class TestLDAPServer(): ''' _named_lock = NamedAtomicLock('TestLDAPServer') - def __init__(self, user: str = 'test', password: str = 'test') -> None: - self._tmp_creds = TemporaryCredentials(user=user, password=password) + def __init__(self, user: str = 'test', password: str = 'test', dbcreds_id: str=None) -> None: + self._tmp_creds = TemporaryCredentials(user=user, password=password, dbcreds_id=dbcreds_id) self._server = None def __enter__(self): diff --git a/SAS/TMSS/test/test_utils.py b/SAS/TMSS/test/test_utils.py index c50573b71fd9540387d3aca8392ae76c84566490..08aa6b7517c801769785cdbbab1c40f9497ab74f 100644 --- a/SAS/TMSS/test/test_utils.py +++ b/SAS/TMSS/test/test_utils.py @@ -86,8 +86,8 @@ class TMSSTestDatabaseInstance(PostgresTestDatabaseInstance): Creates an isolated postgres database instance and initializes the database with a django tmss migration. Destroys the isolated postgres database instance upon exit automagically. ''' - def __init__(self) -> None: - super().__init__(user='test_tmss_user') + def __init__(self, dbcreds_id: str=None) -> None: + super().__init__(user='test_tmss_user', dbcreds_id=dbcreds_id) def apply_database_schema(self): logger.info('applying TMSS sql schema to %s', self.dbcreds) @@ -285,13 +285,14 @@ class TMSSTestEnvironment: start_subtask_scheduler: bool=False, start_dynamic_scheduler: bool=False, start_pipeline_control: bool=False, start_websocket: bool=False, start_feedback_service: bool=False, - start_workflow_service: bool=False, enable_viewflow: bool=False): + start_workflow_service: bool=False, enable_viewflow: bool=False, + ldap_dbcreds_id: str=None, db_dbcreds_id: str=None): self._exchange = exchange self._broker = broker self._populate_schemas = populate_schemas or populate_test_data self._populate_test_data = populate_test_data - self.ldap_server = TestLDAPServer(user='test', password='test') - self.database = TMSSTestDatabaseInstance() + self.ldap_server = TestLDAPServer(user='test', password='test', dbcreds_id=ldap_dbcreds_id) + self.database = TMSSTestDatabaseInstance(dbcreds_id=db_dbcreds_id) self.django_server = TMSSDjangoServerInstance(db_dbcreds_id=self.database.dbcreds_id, ldap_dbcreds_id=self.ldap_server.dbcreds_id, host=host, @@ -568,6 +569,13 @@ def main_test_environment(): group.add_option('-b', '--broker', dest='broker', type='string', default=DEFAULT_BROKER, help='Address of the message broker, default: %default') group.add_option('-e', "--exchange", dest="exchange", type="string", default=DEFAULT_BUSNAME, help="Bus or queue where the TMSS messages are published. [default: %default]") + group = OptionGroup(parser, 'Credentials options', description="By default a unique ID is created for the LDAP and Postgres DB credentials to ensure that this TMSSTestEnvironment is isolated and unique." \ + "There are however also some use cases where we want to refer to a constant ID. These options enable that." \ + "Please mind that these given credentials are still stored in a temporary credentials file which are deleted upon exit.") + parser.add_option_group(group) + group.add_option('-L', '--LDAP_ID', dest='LDAP_ID', type='string', default=None, help='Use this ID for the LDAP service instead of a generated unique id if None given. default: %default') + group.add_option('-D', '--DB_ID', dest='DB_ID', type='string', default=None, help='Use this ID for the Postgres database instead of a generated unique id if None given. default: %default') + (options, args) = parser.parse_args() if options.simulate: @@ -589,7 +597,8 @@ def main_test_environment(): start_websocket=options.websockets or options.all, start_feedback_service=options.feedbackservice or options.all, start_workflow_service=options.viewflow or options.all, - enable_viewflow=options.viewflow or options.all) as tmss_test_env: + enable_viewflow=options.viewflow or options.all, + ldap_dbcreds_id=options.LDAP_ID, db_dbcreds_id=options.DB_ID) as tmss_test_env: # print some nice info for the user to use the test servers... # use print instead of log for clean lines.