Exemplo n.º 1
0
    def configure_timezone(self, tz=None):
        """
        Configure the system timezone

        :type tz: string
        :param tz: the name of timezone, like "Asia/Shanghai"
        """
        if tz is None:
            timezone = self.get_timezone()

        if timezone is None:
            log.info("No timezone specified"
                     "in the user data,"
                     " skipped...")
        else:
            set_timezone(timezone)
Exemplo n.º 2
0
    def test_set_timezone_sles(self):

        cfg = {"timezone": "Tatooine/Bestine"}

        # Create a dummy timezone file
        dummy_contents = "0123456789abcdefgh"
        zone_file = "/".join([self.new_root, cfg["timezone"]])
        utils.write_file(zone_file, dummy_contents)

        clock_conf = self.new_root + "/etc/sysconfig/clock"
        local_tz = self.new_root + "/etc/localtime"
        utils.set_timezone(
            tz=cfg["timezone"], tz_zone_dir=self.new_root, clock_conf_fn=clock_conf, tz_local_fn=local_tz
        )

        contents = utils.load_file(clock_conf)
        n_cfg = ConfigObj(StringIO(contents))
        self.assertEquals({"ZONE": cfg["timezone"]}, dict(n_cfg))

        contents = utils.load_file(local_tz)
        self.assertEquals(dummy_contents, contents.strip())
Exemplo n.º 3
0
    def test_set_timezone_sles(self):

        cfg = {
            'timezone': 'Tatooine/Bestine',
        }

        # Create a dummy timezone file
        dummy_contents = '0123456789abcdefgh'
        zone_file = "/".join([self.new_root, cfg['timezone']])
        utils.write_file(zone_file, dummy_contents)

        clock_conf = self.new_root + "/etc/sysconfig/clock"
        local_tz = self.new_root + "/etc/localtime"
        utils.set_timezone(tz=cfg['timezone'],
                           tz_zone_dir=self.new_root,
                           clock_conf_fn=clock_conf,
                           tz_local_fn=local_tz)

        contents = utils.load_file(clock_conf)
        n_cfg = ConfigObj(StringIO(contents))
        self.assertEquals({'ZONE': cfg['timezone']}, dict(n_cfg))

        contents = utils.load_file(local_tz)
        self.assertEquals(dummy_contents, contents.strip())