def test_user_cfg_ntp_client_auto_uses_distro_clients(self, m_which): """Test user_cfg.ntp_client='auto' defaults to distro search""" # nothing is installed m_which.return_value = None for distro in cc_ntp.distros: mycloud = self._get_cloud(distro) distro_configs = cc_ntp.distro_ntp_client_configs(distro) expected_client = mycloud.distro.preferred_ntp_clients[0] expected_cfg = distro_configs[expected_client] expected_calls = [] for client in mycloud.distro.preferred_ntp_clients: cfg = distro_configs[client] expected_calls.append(mock.call(cfg['check_exe'])) cc_ntp.select_ntp_client('auto', mycloud.distro) m_which.assert_has_calls(expected_calls) self.assertEqual(sorted(expected_cfg), sorted(cfg))
def test_ntp_distro_searches_all_preferred_clients(self, m_which): """Test select_ntp_client search all distro perferred clients""" # nothing is installed m_which.return_value = None for distro in cc_ntp.distros: mycloud = self._get_cloud(distro) distro_configs = cc_ntp.distro_ntp_client_configs(distro) expected_client = mycloud.distro.preferred_ntp_clients[0] expected_cfg = distro_configs[expected_client] expected_calls = [] for client in mycloud.distro.preferred_ntp_clients: cfg = distro_configs[client] expected_calls.append(mock.call(cfg["check_exe"])) cc_ntp.select_ntp_client({}, mycloud.distro) m_which.assert_has_calls(expected_calls) self.assertEqual(sorted(expected_cfg), sorted(cfg))
def test_ntp_system_config_overrides_distro_builtin_clients(self, m_which): """Test distro system_config overrides builtin preferred ntp clients""" system_client = 'chrony' sys_cfg = {'ntp_client': system_client} # no clients installed m_which.return_value = None for distro in cc_ntp.distros: mycloud = self._get_cloud(distro, sys_cfg=sys_cfg) distro_configs = cc_ntp.distro_ntp_client_configs(distro) expected_cfg = distro_configs[system_client] result = cc_ntp.select_ntp_client(None, mycloud.distro) self.assertEqual(sorted(expected_cfg), sorted(result)) m_which.assert_has_calls([])
def test_ntp_user_config_overrides_system_cfg(self, m_which): """Test user-data overrides system_config ntp_client""" system_client = 'chrony' sys_cfg = {'ntp_client': system_client} user_client = 'systemd-timesyncd' # no clients installed m_which.return_value = None for distro in cc_ntp.distros: mycloud = self._get_cloud(distro, sys_cfg=sys_cfg) distro_configs = cc_ntp.distro_ntp_client_configs(distro) expected_cfg = distro_configs[user_client] result = cc_ntp.select_ntp_client(user_client, mycloud.distro) self.assertEqual(sorted(expected_cfg), sorted(result)) m_which.assert_has_calls([])
def test_snappy_system_picks_timesyncd(self, m_which): """Test snappy systems prefer installed clients""" # we are on ubuntu-core here self.m_snappy.return_value = True # ubuntu core systems will have timesyncd installed m_which.side_effect = iter( [None, '/lib/systemd/systemd-timesyncd', None, None, None]) distro = 'ubuntu' mycloud = self._get_cloud(distro) distro_configs = cc_ntp.distro_ntp_client_configs(distro) expected_client = 'systemd-timesyncd' expected_cfg = distro_configs[expected_client] expected_calls = [] # we only get to timesyncd for client in mycloud.distro.preferred_ntp_clients[0:2]: cfg = distro_configs[client] expected_calls.append(mock.call(cfg['check_exe'])) result = cc_ntp.select_ntp_client(None, mycloud.distro) m_which.assert_has_calls(expected_calls) self.assertEqual(sorted(expected_cfg), sorted(cfg)) self.assertEqual(sorted(expected_cfg), sorted(result))