← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/no-dup-tz-find into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/no-dup-tz-find into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/no-dup-tz-find/+merge/176861

Remove duplicate tz file finding and checking.
-- 
https://code.launchpad.net/~harlowja/cloud-init/no-dup-tz-find/+merge/176861
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/no-dup-tz-find into lp:cloud-init.
=== modified file 'cloudinit/distros/__init__.py'
--- cloudinit/distros/__init__.py	2013-07-17 19:35:01 +0000
+++ cloudinit/distros/__init__.py	2013-07-25 05:14:38 +0000
@@ -47,9 +47,11 @@
 
 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 @@
         # 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)
 

=== modified file 'cloudinit/distros/debian.py'
--- cloudinit/distros/debian.py	2013-04-03 22:29:32 +0000
+++ cloudinit/distros/debian.py	2013-07-25 05:14:38 +0000
@@ -44,7 +44,6 @@
     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 @@
         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(),

=== modified file 'cloudinit/distros/rhel.py'
--- cloudinit/distros/rhel.py	2013-06-27 11:50:33 +0000
+++ cloudinit/distros/rhel.py	2013-07-25 05:14:38 +0000
@@ -51,7 +51,6 @@
     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 @@
         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.

=== modified file 'cloudinit/distros/sles.py'
--- cloudinit/distros/sles.py	2013-06-27 12:14:51 +0000
+++ cloudinit/distros/sles.py	2013-07-25 05:14:38 +0000
@@ -42,7 +42,6 @@
     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 @@
         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),


Follow ups