From 4bbfe36a6e758d8817ab2d9ae61d71fe59200776 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 21 Oct 2016 12:46:27 +0200 Subject: [PATCH] Refactor some code in timezone module --- lib/ansible/modules/extras/system/timezone.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/extras/system/timezone.py b/lib/ansible/modules/extras/system/timezone.py index 2f04801790d..a6b74c570f5 100644 --- a/lib/ansible/modules/extras/system/timezone.py +++ b/lib/ansible/modules/extras/system/timezone.py @@ -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)