diff --git a/subiquity/server/controllers/timezone.py b/subiquity/server/controllers/timezone.py index b100fd64..27665ddd 100644 --- a/subiquity/server/controllers/timezone.py +++ b/subiquity/server/controllers/timezone.py @@ -78,16 +78,22 @@ class TimeZoneController(SubiquityController): endpoint = API.timezone - possible = generate_possible_tzs() - autoinstall_key = model_name = 'timezone' autoinstall_schema = { 'type': 'string', - 'enum': possible } autoinstall_default = '' + def __init__(self, *args, **kwargs): + self.possible = None + super().__init__(*args, **kwargs) + + def get_possible_tzs(self): + if self.possible is None: + self.possible = generate_possible_tzs() + return self.possible + def load_autoinstall_data(self, data): self.deserialize(data) @@ -100,7 +106,7 @@ class TimeZoneController(SubiquityController): def deserialize(self, data): if data is None: return - if data not in self.possible: + if data not in self.get_possible_tzs(): raise ValueError(f'Unrecognized time zone request "{data}"') self.model.set(data) if self.model.detect_with_geoip and self.app.geoip.timezone: diff --git a/subiquity/tests/test_timezonecontroller.py b/subiquity/tests/test_timezonecontroller.py index 5fba2a47..db1fe706 100644 --- a/subiquity/tests/test_timezonecontroller.py +++ b/subiquity/tests/test_timezonecontroller.py @@ -99,6 +99,7 @@ class TestTimeZoneController(SubiTestCase): def test_set_tz_escape_dryrun(self, tdc_gettz, subprocess_run): tdc_gettz.return_value = tz_utc self.tzc.app.dry_run = True + self.tzc.possible = ['geoip'] self.tzc.deserialize('geoip') self.assertEqual('sleep', subprocess_run.call_args.args[0][0])