GET /timezone no longer sets to system

The original design for timezone intentionally set the system timezone
based on geoip results, before a POST /timezone.  After the feedback on
LP: #1936310 I'm having second thoughts on that and wish for GET to be
a simple informational query with no such side effects.
This commit is contained in:
Dan Bungert 2021-07-15 11:07:53 -06:00
parent c79aa602dc
commit 7808ccac84
2 changed files with 13 additions and 7 deletions

View File

@ -108,16 +108,17 @@ class TimeZoneController(SubiquityController):
timedatectl_settz(self.app, self.model.timezone)
async def GET(self) -> TimeZoneInfo:
# if someone POSTed before, return that
if self.model.timezone:
return TimeZoneInfo(self.model.timezone,
self.model.got_from_geoip)
# a bare call to GET() is equivalent to autoinstall "timezone: geoip"
self.deserialize('geoip')
tz = self.model.timezone
if not tz:
tz = timedatectl_gettz()
return TimeZoneInfo(tz, self.model.got_from_geoip)
# GET requests geoip results
if self.app.geoip.timezone:
return TimeZoneInfo(self.app.geoip.timezone, True)
# geoip wasn't ready for some reason, so ask the system
return TimeZoneInfo(timedatectl_gettz(), False)
async def POST(self, tz: str):
self.deserialize(tz)

View File

@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import mock
import subprocess
from subiquity.common.types import TimeZoneInfo
from subiquity.models.timezone import TimeZoneModel
@ -102,3 +101,9 @@ class TestTimeZoneController(SubiTestCase):
self.tzc.app.dry_run = True
self.tzc.deserialize('geoip')
self.assertEqual('sleep', subprocess_run.call_args.args[0][0])
@mock.patch('subiquity.server.controllers.timezone.timedatectl_settz')
def test_get_tz_should_not_set(self, tdc_settz):
run_coro(self.tzc.GET())
self.assertFalse(self.tzc.model.should_set_tz)
tdc_settz.assert_not_called()