From d1f69175cf3452b3b4157e526e716834ea75a758 Mon Sep 17 00:00:00 2001 From: Randy Frank Date: Mon, 21 Aug 2023 10:10:12 -0400 Subject: [PATCH 1/3] Workaround a Linux TZ issue If Linux timezone settings are misconfigured, it can cause adr database creation and nexus server launching to fail. --- .../core/utils/report_remote_server.py | 6 +++++ .../core/utils/report_utils.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index 02ab5fd72..dc5ba03fa 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -1005,6 +1005,9 @@ def create_new_local_database( return False + # Check for Linux TZ issue + report_utils.apply_timezone_workaround() + try: if run_local: # Make a random string that could be used as a secret key for the database @@ -1348,6 +1351,9 @@ def launch_local_database_server( if return_info is None: return_info = dict() + # Check for Linux TZ issue + report_utils.apply_timezone_workaround() + # Try to use a lock file to prevent port scanning collisions # We create a lockfiles in the user's home directory. Under windows, we use LOCALAPPDATA to avoid # the case where a home dir may be mounted remotely, potentially causing permission issues when writing. diff --git a/src/ansys/dynamicreporting/core/utils/report_utils.py b/src/ansys/dynamicreporting/core/utils/report_utils.py index 2d137f955..6d8616572 100644 --- a/src/ansys/dynamicreporting/core/utils/report_utils.py +++ b/src/ansys/dynamicreporting/core/utils/report_utils.py @@ -739,3 +739,30 @@ def get_links_from_html(html): parser = HTMLParser() parser.feed(html) return parser.links + + +def apply_timezone_workaround() -> None: + """Apply a workaround for known Linux system misconfigurations + + There is a known issue on some Linux systems where the timezone configuration is incorrect. + On these systems, the get_localzone_name() call will raise an exception that prevents a + Django instance from starting. This effects the Nexus server as well as the adr API for + doing things like creating a database. + + The work-around is to try to trigger the exception early and (on failure) set the TZ + environmental variable to a known value and warn the user that this has been done. + If the user sets TZ or corrects the system misconfiguration, that will also fix the + issue. + + """ + try: + # Attempt to trigger the misconfiguration issue. + import tzlocal + _ = tzlocal.get_localzone_name() + except KeyError as e: + # Issue a warning + import warnings + msg = "The timezone of this session is not configured correctly, trying 'US/Eastern' : " + warnings.warn(msg + str(e)) + # Try a relatively well known TZ + os.environ["TZ"] = "US/Eastern" From 1652dc761502be4641e01b7c8930b5475d8b7396 Mon Sep 17 00:00:00 2001 From: Randy Frank Date: Mon, 21 Aug 2023 10:17:45 -0400 Subject: [PATCH 2/3] precommit changes Update docs. --- .../dynamicreporting/core/utils/report_utils.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_utils.py b/src/ansys/dynamicreporting/core/utils/report_utils.py index 6d8616572..c241636fa 100644 --- a/src/ansys/dynamicreporting/core/utils/report_utils.py +++ b/src/ansys/dynamicreporting/core/utils/report_utils.py @@ -742,26 +742,28 @@ def get_links_from_html(html): def apply_timezone_workaround() -> None: - """Apply a workaround for known Linux system misconfigurations + """ + Apply a workaround for known Linux system misconfigurations. - There is a known issue on some Linux systems where the timezone configuration is incorrect. - On these systems, the get_localzone_name() call will raise an exception that prevents a - Django instance from starting. This effects the Nexus server as well as the adr API for - doing things like creating a database. + There is a known issue on some Linux systems where the timezone configuration is + incorrect. On these systems, the get_localzone_name() call will raise an exception + that prevents a Django instance from starting. This effects the Nexus server as + well as the adr API for doing things like creating a database. The work-around is to try to trigger the exception early and (on failure) set the TZ environmental variable to a known value and warn the user that this has been done. If the user sets TZ or corrects the system misconfiguration, that will also fix the issue. - """ try: # Attempt to trigger the misconfiguration issue. import tzlocal + _ = tzlocal.get_localzone_name() except KeyError as e: # Issue a warning import warnings + msg = "The timezone of this session is not configured correctly, trying 'US/Eastern' : " warnings.warn(msg + str(e)) # Try a relatively well known TZ From 1ae6a98e40558bc097d6c800c109101058b56b52 Mon Sep 17 00:00:00 2001 From: Randy Frank Date: Mon, 21 Aug 2023 12:14:00 -0400 Subject: [PATCH 3/3] tzlocal is ok to be missing It is possible that the target system cannot support django. This is not an error. --- src/ansys/dynamicreporting/core/utils/report_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ansys/dynamicreporting/core/utils/report_utils.py b/src/ansys/dynamicreporting/core/utils/report_utils.py index c241636fa..2defa79f5 100644 --- a/src/ansys/dynamicreporting/core/utils/report_utils.py +++ b/src/ansys/dynamicreporting/core/utils/report_utils.py @@ -760,6 +760,9 @@ def apply_timezone_workaround() -> None: import tzlocal _ = tzlocal.get_localzone_name() + except ModuleNotFoundError: + # tzlocal is only used by the Django code, so if it is not present, + return except KeyError as e: # Issue a warning import warnings