diff options
author | Jonathan Weth <git@jonathanweth.de> | 2021-07-01 19:14:02 +0200 |
---|---|---|
committer | Jonathan Weth <git@jonathanweth.de> | 2021-07-01 19:14:02 +0200 |
commit | 841fb9e6193d8429a4831fde8e06a504abedd2dc (patch) | |
tree | f64ba36325bbfcfd8f4edc79a454c7485183b2b0 | |
parent | ea0e73fbcd1f13b4c0c72c732d9eead6f9af0e81 (diff) | |
parent | 7bd7f73994db1fa2169ff435a41f7fb4c2313058 (diff) | |
download | RWA.Support.SessionService-841fb9e6193d8429a4831fde8e06a504abedd2dc.tar.gz RWA.Support.SessionService-841fb9e6193d8429a4831fde8e06a504abedd2dc.tar.bz2 RWA.Support.SessionService-841fb9e6193d8429a4831fde8e06a504abedd2dc.zip |
Merge branch 'master' into refactor/id-system
-rwxr-xr-x | rwa/support/sessionservice/service.py | 48 | ||||
-rw-r--r-- | rwa/support/sessionservice/session.py | 2 | ||||
-rw-r--r-- | rwa/support/sessionservice/vnc.py | 4 |
3 files changed, 32 insertions, 22 deletions
diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 9a843ae..ecc465c 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -127,8 +127,9 @@ class RWASupportSessionService(dbus.service.Object): """ logging.info("D-Bus method call: %s()", "get_web_app_hosts") - logging.debug('Return to D-Bus caller: "%s"', self._get_web_app_hosts()) - return self._get_web_app_hosts() + response = self._get_web_app_hosts() + logging.debug('The response to D-Bus caller: "%s"', response) + return response def _do_api_handshake(self, host: str) -> Dict[str, str]: """Contact a RWA.Support.WebApp host and find out API version. @@ -235,7 +236,9 @@ class RWASupportSessionService(dbus.service.Object): logging.debug('Added "%s" to "web_app_hosts" in user_settings', host) - return json.dumps(self._build_host_dict(host_id, host_object)) + response = json.dumps(self._build_host_dict(host_id, host_object)) + logging.debug('The response to D-Bus caller: "%s"', response) + return response @dbus.service.method( "org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s" @@ -266,7 +269,9 @@ class RWASupportSessionService(dbus.service.Object): ) return json.dumps({"status": "error", "type": "host_not_found"}) - return self._get_web_app_hosts() + response = self._get_web_app_hosts() + logging.debug('The response to D-Bus caller: "%s"', response) + return response @dbus.service.method( "org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s" @@ -312,7 +317,7 @@ class RWASupportSessionService(dbus.service.Object): "session, so this session won't be started." ) response = json.dumps({"status": "error", "type": "multiple"}) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response try: @@ -322,7 +327,7 @@ class RWASupportSessionService(dbus.service.Object): except IndexError: logging.error("web_app_hosts[%s] does not exist!", host_id) response = json.dumps({"status": "error", "type": "host_not_found"}) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response # Check host by doing a handshake @@ -343,10 +348,10 @@ class RWASupportSessionService(dbus.service.Object): return_json = session.client_meta return_json["status"] = "success" - logging.info(f"New session #{session.pid} was started with meta {return_json}.") + logging.info(f"New session #{session.pid} was started.") response = json.dumps(return_json) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response except ConnectionError: logging.error( @@ -355,7 +360,7 @@ class RWASupportSessionService(dbus.service.Object): ) response = json.dumps({"status": "error", "type": "connection"}) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response @dbus.service.method( @@ -390,7 +395,7 @@ class RWASupportSessionService(dbus.service.Object): """ logging.info("D-Bus method call: %s(%s, %d)", "status", host_id, session_id) response = self._get_status(host_id, session_id) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response @dbus.service.method( @@ -402,7 +407,7 @@ class RWASupportSessionService(dbus.service.Object): self._update_session(host_id, session_id) response = self._get_status(host_id, session_id) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response @dbus.service.method( @@ -427,16 +432,17 @@ class RWASupportSessionService(dbus.service.Object): try: session = self.sessions[combined_id] except KeyError: + logging.debug("D-Bus method stop(): sessions[%s] does not exist.", combined_id) response = json.dumps( {"host_id": host_id, "session_id": session_id, "status": "stopped"}, sort_keys=True ) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response session.stop() response = json.dumps( {"host_id": host_id, "session_id": session_id, "status": "stopped"}, sort_keys=True ) - logging.debug("The response to the D-Bus caller: '%s'", response) + logging.info("The response to the D-Bus caller: '%s'", response) return response def _get_status(self, host_id: str, session_id: int) -> str: @@ -444,6 +450,7 @@ class RWASupportSessionService(dbus.service.Object): try: session = self.sessions[combined_id] except KeyError: + logging.debug("_get_status(): self.sessions[%s] does not exist.", combined_id) return json.dumps( {"host_id": host_id, "session_id": session_id, "status": "dead"}, sort_keys=True ) @@ -462,7 +469,7 @@ class RWASupportSessionService(dbus.service.Object): session = self.sessions[combined_id] except KeyError: logging.info(f"Update status for session #{session_id} on host {host_id} …") - logging.warning(" Session is dead.") + logging.warning("Session %s is dead.", combined_id) return # Check if VNC process is still running @@ -471,12 +478,12 @@ class RWASupportSessionService(dbus.service.Object): pass elif session.status_text == "stopped" and session.pid in self.sessions: logging.info(f"Update status for session #{session_id} on host {host_id} …") - logging.warning(" Session is dead.") + logging.warning("Session %s is dead.", combined_id) del self.sessions[combined_id] else: logging.info(f"Update status for session #{session_id} on host {host_id} …") - logging.warning(" VNC was stopped, so session is dead.") + logging.warning("VNC was stopped, so session %s is dead.", session.combined_id) session.stop() del self.sessions[combined_id] @@ -497,17 +504,17 @@ class RWASupportSessionService(dbus.service.Object): def _trigger(self, session_id: int, data: dict, method: str = "trigger") -> Union[dict, bool]: """Trigger a specific session via trigger token.""" - logging.info(f"Triggered with session ID {session_id} and {data}") + logging.info(f"Event triggered from Django with session ID {session_id} and {data}") for session in self.sessions.values(): if session.session_id == session_id: r = session.trigger(data, method) logging.info( - f"Session #{session.session_id} on host {session.host_id} matches the ID: {r}" + f"Found matching session #{session.session_id} on host {session.host_id}: {r}" ) return r - logging.warning(" No matching session found for this ID.") + logging.warning("Given session ID does not exist!") return False def _stop_all(self): @@ -560,7 +567,8 @@ def main(mockup, once): lock() if mockup: - logging.warning("All API responses are faked and should NOT BE USED IN PRODUCTION!") + logging.warning("The mockup mode should NOT BE USED IN PRODUCTION!") + logging.warning("API responses can be faked and deliver dummy values.") dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) diff --git a/rwa/support/sessionservice/session.py b/rwa/support/sessionservice/session.py index 52f6471..53bde2d 100644 --- a/rwa/support/sessionservice/session.py +++ b/rwa/support/sessionservice/session.py @@ -207,7 +207,7 @@ class Session: pass if r.status_code in (401, 402, 403, 404, 405): - # Session doesn't exist anymore, so stop it local + # Session doesn't exist anymore, so stop it localy too self.stop(triggered=True) else: self.status_text = r.json()["status"] diff --git a/rwa/support/sessionservice/vnc.py b/rwa/support/sessionservice/vnc.py index f41efce..be33b35 100644 --- a/rwa/support/sessionservice/vnc.py +++ b/rwa/support/sessionservice/vnc.py @@ -48,7 +48,9 @@ def run_vnc(pw_filename: str) -> Dict[str, Dict[str, int]]: port_vnc = port_for.select_random() # Start VNC process - p = subprocess.Popen(["x11vnc", "-rfbauth", pw_filename, "-rfbport", f"{port_vnc}"]) # noqa + p = subprocess.Popen( # noqa + ["x11vnc", "-forever", "-rfbauth", pw_filename, "-rfbport", f"{port_vnc}"] # noqa + ) # Start websockify p2 = subprocess.Popen(["websockify", str(port), f"127.0.0.1:{port_vnc}"]) # noqa |