From 687628ab70bc7a63bd3b053e8c44de494d5ffc0a Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Tue, 7 Nov 2023 11:29:21 +0100 Subject: [PATCH] timezone: for kickstart allow also timezones not offered by GUI Resolves: RHEL-13151 For example Japan, which is linked to Asia/Tokyo in Olson tz database, and we offer only Asia/Tokyo in GUI. --- pyanaconda/modules/timezone/installation.py | 8 ++++++-- pyanaconda/timezone.py | 21 +++++++++++++++++++-- pyanaconda/ui/gui/spokes/datetime_spoke.py | 11 +++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/pyanaconda/modules/timezone/installation.py b/pyanaconda/modules/timezone/installation.py index 829748c11eb9..a766000ae6bd 100644 --- a/pyanaconda/modules/timezone/installation.py +++ b/pyanaconda/modules/timezone/installation.py @@ -24,7 +24,7 @@ from pyanaconda.anaconda_loggers import get_module_logger from pyanaconda.modules.common.errors.installation import TimezoneConfigurationError from pyanaconda.modules.common.task import Task -from pyanaconda.timezone import is_valid_timezone +from pyanaconda.timezone import is_valid_timezone, is_valid_ui_timezone from blivet import arch @@ -60,7 +60,11 @@ def run(self): def _correct_timezone(self): """Ensure the timezone is valid.""" - if not is_valid_timezone(self._timezone): + if is_valid_timezone(self._timezone): + if not is_valid_ui_timezone(self._timezone): + log.warning("Timezone specification %s set in kickstart is " + "not offered by installer GUI.", self._timezone) + else: # this should never happen, but for pity's sake log.warning("Timezone %s set in kickstart is not valid, " "falling back to default (America/New_York).", self._timezone) diff --git a/pyanaconda/timezone.py b/pyanaconda/timezone.py index e9aa826b1432..72374a033595 100644 --- a/pyanaconda/timezone.py +++ b/pyanaconda/timezone.py @@ -148,9 +148,9 @@ def get_all_regions_and_timezones(): return result -def is_valid_timezone(timezone): +def is_valid_ui_timezone(timezone): """ - Check if a given string is an existing timezone. + Check if a given string is a timezone specification offered by GUI. :type timezone: str :rtype: bool @@ -162,6 +162,23 @@ def is_valid_timezone(timezone): return timezone in pytz.common_timezones + etc_zones +def is_valid_timezone(timezone): + """ + Check if a given string is a valid timezone specification. + + This includes also deprecated/backward timezones linked to other timezones + in tz database (eg Japan -> Asia/Tokyo). Both the tzdata package (installed + system) and TimezoneMap widget (installer GUI) should support them and be + able link them to the correct timezone specification using the data from + "backward" file. + + :type timezone: str + :rtype: bool + """ + + return is_valid_ui_timezone(timezone) or timezone in pytz.all_timezones + + def get_timezone(timezone): """ Return a tzinfo object for a given timezone name. diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py index 50ae15684613..bf607502faef 100644 --- a/pyanaconda/ui/gui/spokes/datetime_spoke.py +++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py @@ -48,7 +48,8 @@ from pyanaconda.threading import threadMgr, AnacondaThread from pyanaconda.core.i18n import _, CN_ from pyanaconda.core.async_utils import async_action_wait, async_action_nowait -from pyanaconda.timezone import NTP_SERVICE, get_all_regions_and_timezones, get_timezone, is_valid_timezone +from pyanaconda.timezone import NTP_SERVICE, get_all_regions_and_timezones, get_timezone, \ + is_valid_timezone, is_valid_ui_timezone from pyanaconda.localization import get_xlated_timezone, resolve_date_format from pyanaconda.core.timer import Timer @@ -557,8 +558,14 @@ def _initialize(self): self._update_datetime_timer = None kickstart_timezone = self._timezone_module.Timezone - if is_valid_timezone(kickstart_timezone): + if is_valid_ui_timezone(kickstart_timezone): self._set_timezone(kickstart_timezone) + elif is_valid_timezone(kickstart_timezone): + log.warning("Timezone specification %s is not offered by installer GUI.", + kickstart_timezone) + # Try to get the correct linked timezone via TimezoneMap selection + self._tzmap.set_timezone(kickstart_timezone) + elif not flags.flags.automatedInstall: log.warning("%s is not a valid timezone, falling back to default (%s)", kickstart_timezone, DEFAULT_TZ)