Proper fix for setting timezone inappropriately in dryrun

Reenable integration test for set of timezone.
Don't set it while in dryrun.
This commit is contained in:
Dan Bungert 2021-07-15 07:30:22 -06:00
parent 545d77eeab
commit c79aa602dc
5 changed files with 21 additions and 6 deletions

View File

@ -41,7 +41,7 @@ snaps:
- name: etcd
channel: 3.2/stable
updates: all
# timezone: Pacific/Guam
timezone: Pacific/Guam
storage:
config:
- {type: disk, ptable: gpt, path: /dev/vdb, wipe: superblock, preserve: false, grub_device: true, id: disk-1}

View File

@ -55,8 +55,8 @@ python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \
storage.config[-1].options='"errors=remount-ro"'
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \
locale='"en_GB.UTF-8"' \
timezone='"Pacific/Guam"' \
'snap.commands=[snap install --channel=3.2/stable etcd]'
# timezone='"Pacific/Guam"'
grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \
.subiquity/subiquity-server-debug.log
grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \

View File

@ -31,8 +31,11 @@ def generate_possible_tzs():
return special_keys + real_tzs
def timedatectl_settz(tz):
def timedatectl_settz(app, tz):
tzcmd = ['timedatectl', 'set-timezone', tz]
if app.opts.dry_run:
tzcmd = ['sleep', str(1/app.scale_factor)]
try:
subprocess.run(tzcmd, universal_newlines=True)
except subprocess.CalledProcessError as cpe:
@ -59,7 +62,7 @@ def timedatectl_gettz():
log.error('Failed to get live system timezone: %r', cpe)
except IndexError:
log.error('Failed to acquire system time zone')
log.debug('Failed to fine Time zone in timedatectl output')
log.debug('Failed to find Time zone in timedatectl output')
return 'Etc/UTC'
@ -102,7 +105,7 @@ class TimeZoneController(SubiquityController):
def set_system_timezone(self):
if self.model.should_set_tz:
timedatectl_settz(self.model.timezone)
timedatectl_settz(self.app, self.model.timezone)
async def GET(self) -> TimeZoneInfo:
if self.model.timezone:

View File

@ -14,6 +14,7 @@
# 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
@ -81,7 +82,7 @@ class TestTimeZoneController(SubiTestCase):
cloudconfig = {}
if self.tzc.model.should_set_tz:
cloudconfig = {'timezone': tz.timezone}
tdc_settz.assert_called_with(tz.timezone)
tdc_settz.assert_called_with(self.tzc.app, tz.timezone)
self.assertEqual(cloudconfig, self.tzc.model.make_cloudconfig(),
self.tzc.model)
@ -93,3 +94,11 @@ class TestTimeZoneController(SubiTestCase):
for b in bads:
with self.assertRaises(ValueError):
self.tzc.deserialize(b)
@mock.patch('subprocess.run')
@mock.patch('subiquity.server.controllers.timezone.timedatectl_gettz')
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.deserialize('geoip')
self.assertEqual('sleep', subprocess_run.call_args.args[0][0])

View File

@ -39,4 +39,7 @@ def make_app(model=None):
app.next_screen = mock.Mock()
app.prev_screen = mock.Mock()
app.hub = MessageHub()
app.opts = mock.Mock()
app.opts.dry_run = True
app.scale_factor = 1000
return app