def sync_time(self, node_names=None, skip_sync=False): """Synchronize time on nodes param: node_names - list of devops node names param: skip_sync - only get the current time without sync return: dict{node_name: node_time, ...} """ if node_names is None: node_names = [node.name for node in self.get_active_nodes()] group = ntp.GroupNtpSync() for node_name in node_names: if node_name == 'admin': remote = self.get_admin_remote() else: remote = self.get_node_remote(node_name=node_name) group.add_node(remote, node_name) with group: if not skip_sync: group.sync_time('admin') group.sync_time('pacemaker') group.sync_time('other') return group.get_curr_time()
def test_add_node(self): pcs_cmd = "ps -C pacemakerd && crm_resource --resource p_ntp --locate" self.exec_results[pcs_cmd] = self.make_exec_result('') self.exec_results['date'] = self.make_exec_result( 'Fri Jul 22 12:45:42 MSK 2016') group = ntp.GroupNtpSync() group.add_node(self.remote_mock, 'node1') assert len(group.ntp_groups['admin']) == 0 assert len(group.ntp_groups['pacemaker']) == 1 assert len(group.ntp_groups['other']) == 0 group.add_node(self.remote_mock, 'admin') assert len(group.ntp_groups['admin']) == 1 assert len(group.ntp_groups['pacemaker']) == 1 assert len(group.ntp_groups['other']) == 0 chronyd_cmd = "systemctl is-active chronyd" del self.exec_results[pcs_cmd] self.exec_results[chronyd_cmd] = self.make_exec_result('') group.add_node(self.remote_mock, 'node2') assert len(group.ntp_groups['admin']) == 1 assert len(group.ntp_groups['pacemaker']) == 1 assert len(group.ntp_groups['other']) == 1 assert group.get_curr_time() == { 'admin': 'Fri Jul 22 12:45:42 MSK 2016', 'node1': 'Fri Jul 22 12:45:42 MSK 2016', 'node2': 'Fri Jul 22 12:45:42 MSK 2016' }
def sync_time(self, node_names=None, skip_sync=False): """Synchronize time on nodes param: node_names - list of devops node names param: skip_sync - only get the current time without sync return: dict{node_name: node_time, ...} """ if node_names is None: node_names = [node.name for node in self.get_active_nodes()] group = ntp.GroupNtpSync() if self.has_admin(): # Assume that the node with name 'admin' is a Fuel master node for node_name in node_names: if node_name == 'admin': remote = self.get_admin_remote() else: remote = self.get_node_remote(node_name=node_name) group.add_node(remote, node_name) else: # There is no FuelAdmin node, fallback to trying assigned # addresses. for node_name in node_names: remote = self.find_node_remote(node_name=node_name) group.add_node(remote, node_name) with group: if not skip_sync: group.sync_time('admin') group.sync_time('pacemaker') group.sync_time('other') return group.get_curr_time()
def test_get_curr_time(self): pcs_cmd = "ps -C pacemakerd && crm_resource --resource p_ntp --locate" self.exec_results[pcs_cmd] = self.make_exec_result('') self.exec_results['date'] = self.make_exec_result( 'Fri Jul 22 12:45:42 MSK 2016') group = ntp.GroupNtpSync() group.add_node(self.remote_mock, 'node1') assert len(group.ntp_groups['pacemaker']) == 1 assert group.get_curr_time() == { 'node1': 'Fri Jul 22 12:45:42 MSK 2016'}
def test_sync_time(self, get_ntp_mock): spec = mock.create_autospec(spec=ntp.NtpPacemaker, instance=True) admin_ntp_mock = mock.Mock(spec=spec) node1_ntp_mock = mock.Mock(spec=spec) node2_ntp_mock = mock.Mock(spec=spec) get_ntp_mock.side_effect = ( admin_ntp_mock, node1_ntp_mock, node2_ntp_mock) group = ntp.GroupNtpSync() group.sync_time('admin') group.add_node(self.remote_mock, 'admin') group.add_node(self.remote_mock, 'node1') group.add_node(self.remote_mock, 'node2') assert group.ntp_groups == { 'admin': [admin_ntp_mock], 'pacemaker': [node1_ntp_mock, node2_ntp_mock] } group.sync_time('admin') admin_ntp_mock.assert_has_calls(( mock.call.stop(), mock.call.set_actual_time(), mock.call.start(), mock.call.wait_peer() ), any_order=True) node1_ntp_mock.stop.assert_not_called() node1_ntp_mock.set_actual_time.assert_not_called() node1_ntp_mock.start.assert_not_called() node1_ntp_mock.wait_peer.assert_not_called() node2_ntp_mock.stop.assert_not_called() node2_ntp_mock.set_actual_time.assert_not_called() node2_ntp_mock.start.assert_not_called() node2_ntp_mock.wait_peer.assert_not_called() group.sync_time('pacemaker') node1_ntp_mock.assert_has_calls(( mock.call.stop(), mock.call.set_actual_time(), mock.call.start(), mock.call.wait_peer() )) node2_ntp_mock.assert_has_calls([ mock.call.stop(), mock.call.set_actual_time(), mock.call.start(), mock.call.wait_peer() ])