Refactor some code in timezone module

pull/18777/head
Michael Scherer 8 years ago committed by Matt Clay
parent be19af02f7
commit 4bbfe36a6e

@ -218,6 +218,12 @@ class Timezone(object):
"""
self.abort('set(key, value) is not implemented on target platform')
def _verify_timezone(self):
tz = self.value['name']['planned']
tzfile = '/usr/share/zoneinfo/%s' % tz
if not os.path.isfile(tzfile):
self.abort('given timezone "%s" is not available' % tz)
class SystemdTimezone(Timezone):
"""This is a Timezone manipulation class systemd-powered Linux.
@ -241,10 +247,7 @@ class SystemdTimezone(Timezone):
self.status = dict()
# Validate given timezone
if 'name' in self.value:
tz = self.value['name']['planned']
tzfile = '/usr/share/zoneinfo/%s' % tz
if not os.path.isfile(tzfile):
self.abort('given timezone "%s" is not available' % tz)
self._verify_timezone()
def _get_status(self, phase):
if phase not in self.status:
@ -298,10 +301,7 @@ class NosystemdTimezone(Timezone):
super(NosystemdTimezone, self).__init__(module)
# Validate given timezone
if 'name' in self.value:
tz = self.value['name']['planned']
tzfile = '/usr/share/zoneinfo/%s' % tz
if not os.path.isfile(tzfile):
self.abort('given timezone "%s" is not available' % tz)
self._verify_timezone()
self.update_timezone = self.module.get_bin_path('cp', required=True)
self.update_timezone += ' %s /etc/localtime' % tzfile
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)

Loading…
Cancel
Save