Skip to content

Commit

Permalink
timezone: for kickstart allow also timezones not offered by GUI
Browse files Browse the repository at this point in the history
Resolves: RHEL-13151

For example Japan, which is linked to Asia/Tokyo in Olson tz database,
and we offer only Asia/Tokyo in GUI.
  • Loading branch information
rvykydal committed Nov 27, 2023
1 parent 7548393 commit 687628a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pyanaconda/modules/timezone/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions pyanaconda/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions pyanaconda/ui/gui/spokes/datetime_spoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 687628a

Please sign in to comment.