Demote master when etcd is not accessible

This commit is contained in:
Alexander Kukushkin
2015-05-22 12:26:19 +02:00
parent 09163ac454
commit 34f9b666cf
2 changed files with 12 additions and 0 deletions
+3
View File
@@ -89,6 +89,9 @@ class Ha:
return 'no action. i am a secondary and i am following a leader'
except EtcdError:
logger.error('Error communicating with Etcd')
if self.state_handler.is_leader():
self.state_handler.demote(None)
return 'demoted self because etcd is not accessible and i was a leader'
except OperationalError:
logger.error('Error communicating with Postgresql. Will try again')
except HealthiestMemberError:
+9
View File
@@ -1,6 +1,7 @@
import unittest
import requests
from helpers.errors import EtcdError
from helpers.etcd import Cluster, Etcd
from helpers.ha import Ha
from test_etcd import requests_get, requests_put, requests_delete
@@ -54,6 +55,10 @@ def nop(*args, **kwargs):
pass
def dead_etcd():
raise EtcdError('Etcd is not responding properly')
class TestHa(unittest.TestCase):
def __init__(self, method_name='runTest'):
@@ -124,3 +129,7 @@ class TestHa(unittest.TestCase):
self.ha.cluster.is_unlocked = false
self.p.is_leader = false
self.assertEquals(self.ha.run_cycle(), 'no action. i am a secondary and i am following a leader')
def test_no_etcd_connection_master_demote(self):
self.ha.load_cluster_from_etcd = dead_etcd
self.assertEquals(self.ha.run_cycle(), 'demoted self because etcd is not accessible and i was a leader')