Esempio n. 1
0
    def test_master_failure(self):
        LOG.debug("test_master_failure")

        client = stub_etcd.Client()
        client.add_read_exception(stub_etcd.EtcdKeyNotFound())
        # Now become the master but fail
        client.add_write_exception(stub_etcd.EtcdException())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_result(key="/bloop", value=None, action="delete")
        # Now become the master but fail again
        client.add_write_exception(stub_etcd.EtcdException())
        # Go back to the beginning again.
        client.add_read_result(key="/bloop", value="value")
        client.add_read_result(key="/bloop", value=None, action="delete")
        client.add_write_exception(None)
        client.add_write_exception(None)
        elector = election.Elector(client,
                                   "test_basic",
                                   "/bloop",
                                   interval=5,
                                   ttl=15)
        self._wait_and_stop(client, elector)

        # We are no longer the master, after error.
        self.assertFalse(elector.master())
Esempio n. 2
0
 def test_check_master_process_died(self, m_exists):
     m_exists.return_value = False
     client = mock.Mock()
     elector = election.Elector(client,
                                "server-id",
                                "/bloop",
                                interval=5,
                                ttl=15)
     client.delete.side_effect = stub_etcd.EtcdKeyNotFound()
     self.assertRaises(election.RestartElection,
                       elector._check_master_process, "server-id:1234")
     self.assertEqual([mock.call("/bloop", prevValue="server-id:1234")],
                      client.delete.mock_calls)
Esempio n. 3
0
 def test_fail_to_maintain(self):
     # Become the master after once round
     LOG.debug("test_become_master_first_time")
     client = stub_etcd.Client()
     client.add_read_exception(stub_etcd.EtcdKeyNotFound())
     client.add_write_exception(None)
     client.add_write_exception(stub_etcd.EtcdClusterIdChanged())
     elector = election.Elector(client,
                                "test_basic",
                                "/bloop",
                                interval=5,
                                ttl=15)
     self._wait_and_stop(client, elector)
Esempio n. 4
0
 def test_become_master_implausible(self):
     # Become the master after key vanishes
     LOG.debug("test_become_master_implausible")
     client = stub_etcd.Client()
     client.add_read_result(key="/bloop", value="value")
     client.add_read_result(key="/bloop", value="value")
     client.add_read_exception(stub_etcd.EtcdKeyNotFound())
     client.add_write_result()
     client.add_write_result()
     elector = election.Elector(client,
                                "test_basic",
                                "/bloop",
                                interval=5,
                                ttl=15)
     self._wait_and_stop(client, elector)