Esempio n. 1
0
def _set_ntp_servers_from_dhcp():
    """Set NTP servers of timezone module from dhcp if not set by kickstart."""
    # FIXME - do it only if they will be applied (the guard at the end of the function)
    timezone_proxy = TIMEZONE.get_proxy()
    ntp_servers = get_ntp_servers_from_dhcp(get_nm_client())
    log.info("got %d NTP servers from DHCP", len(ntp_servers))
    hostnames = []
    for server_address in ntp_servers:
        try:
            hostname = socket.gethostbyaddr(server_address)[0]
        except socket.error:
            # getting hostname failed, just use the address returned from DHCP
            log.debug("getting NTP server host name failed for address: %s",
                      server_address)
            hostname = server_address
        hostnames.append(hostname)

    # check if some NTP servers were specified from kickstart
    if not timezone_proxy.TimeSources and conf.target.is_hardware:
        # no NTP servers were specified, add those from DHCP
        servers = []

        for hostname in hostnames:
            server = TimeSourceData()
            server.type = TIME_SOURCE_SERVER
            server.hostname = hostname
            server.options = ["iburst"]
            servers.append(server)

        timezone_proxy.SetTimeSources(
            TimeSourceData.to_structure_list(servers))
    def TimeSources(self) -> List[Structure]:
        """A list of time sources.

        :return: a list of time source data
        :rtype: a list of structures of the type TimeSourceData
        """
        return TimeSourceData.to_structure_list(
            self.implementation.time_sources)
    def test_install_with_tasks_configured(self, publisher):
        """Test install tasks - module in configured state."""

        self.timezone_interface.SetIsUTC(True)
        self.timezone_interface.SetTimezone("Asia/Tokyo")
        self.timezone_interface.SetNTPEnabled(False)
        # --nontp and --ntpservers are mutually exclusive in kicstart but
        # there is no such enforcement in the module so for testing this is ok

        server = TimeSourceData()
        server.type = TIME_SOURCE_SERVER
        server.hostname = "clock1.example.com"
        server.options = ["iburst"]

        pool = TimeSourceData()
        pool.type = TIME_SOURCE_POOL
        pool.hostname = "clock2.example.com"

        self.timezone_interface.SetTimeSources(
            TimeSourceData.to_structure_list([server, pool])
        )

        task_classes = [
            ConfigureHardwareClockTask,
            ConfigureTimezoneTask,
            ConfigureNTPTask,
        ]
        task_paths = self.timezone_interface.InstallWithTasks()
        task_objs = check_task_creation_list(task_paths, publisher, task_classes)

        # ConfigureHardwareClockTask
        obj = task_objs[0]
        assert obj.implementation._is_utc is True

        # ConfigureTimezoneTask
        obj = task_objs[1]
        assert obj.implementation._timezone == "Asia/Tokyo"
        assert obj.implementation._is_utc is True

        # ConfigureNTPTask
        obj = task_objs[2]
        assert obj.implementation._ntp_enabled is False
        assert len(obj.implementation._ntp_servers) == 2
        assert compare_data(obj.implementation._ntp_servers[0], server)
        assert compare_data(obj.implementation._ntp_servers[1], pool)
Esempio n. 4
0
    def on_ntp_config_clicked(self, *args):
        servers = copy.deepcopy(self._ntp_servers)
        states = self._ntp_servers_states

        dialog = NTPConfigDialog(self.data, servers, states)
        dialog.refresh()

        with self.main_window.enlightbox(dialog.window):
            response = dialog.run()

        if response == 1:
            self._timezone_module.SetTimeSources(
                TimeSourceData.to_structure_list(servers))

            self._ntp_servers = servers
            working_server = self._get_working_server()

            if working_server is None:
                self._show_no_ntp_server_warning()
            else:
                self.clear_info()
Esempio n. 5
0
    def on_ntp_config_clicked(self, *args):
        servers = copy.deepcopy(self._ntp_servers)
        states = self._ntp_servers_states

        # Temporarily disconnect the update callback.
        states.changed.disconnect(self._update_ntp_server_warning)

        dialog = NTPConfigDialog(self.data, servers, states)
        dialog.refresh()

        with self.main_window.enlightbox(dialog.window):
            response = dialog.run()

        # Connect the update callback again.
        states.changed.connect(self._update_ntp_server_warning)

        if response == 1:
            self._timezone_module.TimeSources = \
                TimeSourceData.to_structure_list(servers)

            self._ntp_servers = servers
            self._update_ntp_server_warning()
Esempio n. 6
0
 def apply(self):
     # update the NTP server list in kickstart
     self._timezone_module.SetTimeSources(
         TimeSourceData.to_structure_list(self._ntp_servers))