Remove duplicate timezone file finding and error raising.

This commit is contained in:
Joshua Harlow 2013-07-24 22:12:33 -07:00
parent a8b94a575f
commit 418109cea5
4 changed files with 12 additions and 21 deletions

View File

@ -47,9 +47,11 @@ LOG = logging.getLogger(__name__)
class Distro(object):
__metaclass__ = abc.ABCMeta
hosts_fn = "/etc/hosts"
ci_sudoers_fn = "/etc/sudoers.d/90-cloud-init-users"
hostname_conf_fn = "/etc/hostname"
tz_zone_dir = "/usr/share/zoneinfo"
def __init__(self, name, cfg, paths):
self._paths = paths
@ -66,6 +68,13 @@ class Distro(object):
# to write this blob out in a distro format
raise NotImplementedError()
def _find_tz_file(self, tz):
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
raise IOError(("Invalid timezone %s,"
" no file found at %s") % (tz, tz_file))
return tz_file
def get_option(self, opt_name, default=None):
return self._cfg.get(opt_name, default)

View File

@ -44,7 +44,6 @@ class Distro(distros.Distro):
network_conf_fn = "/etc/network/interfaces"
tz_conf_fn = "/etc/timezone"
tz_local_fn = "/etc/localtime"
tz_zone_dir = "/usr/share/zoneinfo"
def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
@ -130,12 +129,7 @@ class Distro(distros.Distro):
return "127.0.1.1"
def set_timezone(self, tz):
# TODO(harlowja): move this code into
# the parent distro...
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
raise RuntimeError(("Invalid timezone %s,"
" no file found at %s") % (tz, tz_file))
tz_file = self._find_tz_file(tz)
# Note: "" provides trailing newline during join
tz_lines = [
util.make_header(),

View File

@ -51,7 +51,6 @@ class Distro(distros.Distro):
network_script_tpl = '/etc/sysconfig/network-scripts/ifcfg-%s'
resolve_conf_fn = "/etc/resolv.conf"
tz_local_fn = "/etc/localtime"
tz_zone_dir = "/usr/share/zoneinfo"
def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
@ -164,12 +163,7 @@ class Distro(distros.Distro):
return distros.Distro._bring_up_interfaces(self, device_names)
def set_timezone(self, tz):
# TODO(harlowja): move this code into
# the parent distro...
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
raise RuntimeError(("Invalid timezone %s,"
" no file found at %s") % (tz, tz_file))
tz_file = self._find_tz_file(tz)
if self._dist_uses_systemd():
# Currently, timedatectl complains if invoked during startup
# so for compatibility, create the link manually.

View File

@ -42,7 +42,6 @@ class Distro(distros.Distro):
network_script_tpl = '/etc/sysconfig/network/ifcfg-%s'
resolve_conf_fn = '/etc/resolv.conf'
tz_local_fn = '/etc/localtime'
tz_zone_dir = '/usr/share/zoneinfo'
def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
@ -151,12 +150,7 @@ class Distro(distros.Distro):
return distros.Distro._bring_up_interfaces(self, device_names)
def set_timezone(self, tz):
# TODO(harlowja): move this code into
# the parent distro...
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
raise RuntimeError(("Invalid timezone %s,"
" no file found at %s") % (tz, tz_file))
tz_file = self._find_tz_file(tz)
# Adjust the sysconfig clock zone setting
clock_cfg = {
'TIMEZONE': str(tz),