Esempio n. 1
0
    def test_ntp_pacemaker(self):
        remote = Remote()
        ntp_pcm = ntp.NtpPacemaker(remote)

        self.check_shared(ntp_obj=ntp_pcm, remote=remote, pacemaker=True)

        remote.execute.assert_called_once_with(
            "awk '/^server/ && $2 !~ /127.*/ {print $2}' /etc/ntp.conf")
        self.assertEqual(
            str(ntp_pcm),
            'NtpPacemaker(remote=Remote, node_name=node, admin_ip=None)')

        remote.reset_mock()

        ntp_pcm.start()
        self.assertFalse(ntp_pcm.is_connected)
        remote.execute.assert_has_calls((
            mock.call('ip netns exec vrouter ip l set dev lo up'),
            mock.call('crm resource start p_ntp')
        ))

        remote.reset_mock()

        ntp_pcm.stop()
        self.assertFalse(ntp_pcm.is_connected)
        remote.execute.assert_called_once_with(
            'crm resource stop p_ntp; killall ntpd')

        remote.reset_mock()

        result = ntp_pcm.get_peers()
        self.assertEqual(result, return_value['stdout'])
        remote.execute.assert_called_once_with(
            'ip netns exec vrouter ntpq -pn 127.0.0.1')
Esempio n. 2
0
    def test_start(self):
        ntp_pcm = ntp.NtpPacemaker(self.remote_mock, 'node')
        ntp_pcm.start()

        self.remote_mock.execute.assert_has_calls((
            mock.call('ip netns exec vrouter ip l set dev lo up'),
            mock.call('crm resource start p_ntp'),
        ))
Esempio n. 3
0
    def test_get_ntpq(self):
        self.remote_mock.execute.return_value = self.make_exec_result(
            'Line1\nLine2\nLine3\nLine4\n')

        ntp_pcm = ntp.NtpPacemaker(self.remote_mock, 'node')
        peers = ntp_pcm._get_ntpq()

        self.remote_mock.execute.assert_called_once_with(
            'ip netns exec vrouter ntpq -pn 127.0.0.1')
        assert peers == ['Line3\n', 'Line4\n']
Esempio n. 4
0
    def test_stop(self):
        ntp_pcm = ntp.NtpPacemaker(self.remote_mock, 'node')
        ntp_pcm.stop()

        self.remote_mock.execute.assert_called_once_with(
            'crm resource stop p_ntp; killall ntpd')
Esempio n. 5
0
 def test_init(self):
     ntp_pcm = ntp.NtpPacemaker(self.remote_mock, 'node')
     assert ntp_pcm.remote is self.remote_mock
     assert ntp_pcm.node_name == 'node'
     assert repr(ntp_pcm) == \
         "NtpPacemaker(remote=<SSHClient()>, node_name='node')"