def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members()
def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = "i-deadbeef3" self.manager.region = "eu-west-1" EtcdCluster.REGIONS = ["eu-west-1"] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertFalse(EtcdCluster.is_multiregion())
def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' EtcdCluster.REGIONS = ['eu-west-1'] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertFalse(EtcdCluster.is_multiregion())
def setUp(self, res): res.return_value.instances.filter.return_value = public_instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' EtcdCluster.REGIONS = ['eu-west-1', 'eu-central-1'] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertTrue(EtcdCluster.is_multiregion())
def set_up(self): requests.post = requests_post requests.get = requests_get requests.delete = requests_delete boto.ec2.connect_to_region = boto_ec2_connect_to_region self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members()
class TestEtcdCluster(unittest.TestCase): def __init__(self, method_name='runTest'): self.setUp = self.set_up super(TestEtcdCluster, self).__init__(method_name) def set_up(self): requests.post = requests_post requests.get = requests_get requests.delete = requests_delete boto.ec2.connect_to_region = boto_ec2_connect_to_region self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members() def test_load_members(self): self.assertEqual(len(self.cluster.members), 4) self.assertNotEqual(self.cluster.me, None) def test_is_new_cluster(self): self.assertEqual(self.cluster.is_new_cluster(), False) def test_register_me(self): self.assertEqual(self.cluster.register_me(), [ '-name', 'i-deadbeef3', '--data-dir', 'data', '-listen-peer-urls', 'http://0.0.0.0:2380', '-initial-advertise-peer-urls', 'http://127.0.0.3:2380', '-listen-client-urls', 'http://0.0.0.0:2379', '-advertise-client-urls', 'http://127.0.0.3:2379', '-initial-cluster', 'i-deadbeef1=http://127.0.0.1:2380,i-deadbeef2=http://127.0.0.2:2380,i-deadbeef3=http://127.0.0.3:2380,i-deadbeef4=http://127.0.0.4:2380', '-initial-cluster-token', 'etc-cluster', '-initial-cluster-state', 'existing', ]) self.cluster.me.id = 'ifoobari7' self.assertRaises(Exception, self.cluster.register_me) self.cluster.me.client_urls = [] self.cluster.me.id = '' self.cluster.me.addr = '127.0.0.4' self.assertRaises(Exception, self.cluster.register_me) self.cluster.leader = None self.assertRaises(Exception, self.cluster.register_me) self.cluster.accessible_member = None self.assertEqual(self.cluster.register_me()[17], 'new')
class TestEtcdCluster(unittest.TestCase): @patch('requests.get', requests_get) @patch('boto3.resource') def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members() @patch('boto3.resource') def test_load_members(self, res): res.return_value.instances.filter.return_value = instances() self.assertEqual(len(self.cluster.members), 4) with patch('requests.get', Mock(side_effect=Exception)): self.cluster.load_members() def test_is_healthy(self): me = EtcdMember({ 'id': 'ifoobari7', 'name': 'i-sadfjhg', 'clientURLs': ['http://127.0.0.2:{}'.format(EtcdMember.DEFAULT_CLIENT_PORT)], 'peerURLs': ['http://127.0.0.2:{}'.format(EtcdMember.DEFAULT_PEER_PORT)], }) self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].instance_id = 'foo' self.cluster.members[-1].name = '' self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].peer_urls = ['http://127.0.0.2:2380'] self.assertTrue(self.cluster.is_healthy(me)) self.cluster.members.pop() self.assertTrue(self.cluster.is_healthy(me))
class TestEtcdCluster(unittest.TestCase): def __init__(self, method_name='runTest'): self.setUp = self.set_up super(TestEtcdCluster, self).__init__(method_name) def set_up(self): requests.get = requests_get boto.ec2.connect_to_region = boto_ec2_connect_to_region self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members() def test_load_members(self): self.assertEqual(len(self.cluster.members), 4) requests.get = requests_get_fail self.cluster.load_members() def test_is_healthy(self): me = EtcdMember({ 'id': 'ifoobari7', 'name': 'i-sadfjhg', 'clientURLs': ['http://127.0.0.2:{}'.format(EtcdMember.DEFAULT_CLIENT_PORT)], 'peerURLs': ['http://127.0.0.2:{}'.format(EtcdMember.DEFAULT_PEER_PORT)], }) self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].instance_id = 'foo' self.cluster.members[-1].name = '' self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].peer_urls = ['http://127.0.0.2:2380'] self.assertTrue(self.cluster.is_healthy(me)) self.cluster.members.pop() self.assertTrue(self.cluster.is_healthy(me))
def set_up(self): requests.get = requests_get boto.ec2.connect_to_region = boto_ec2_connect_to_region self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' self.cluster = EtcdCluster(self.manager) self.cluster.load_members()
def test_register_me(self, res): res.return_value.instances.filter.return_value = instances() cluster = EtcdCluster(self.manager) cluster.load_members() self.manager.me.id = '1' self.manager.register_me(cluster) self.manager.me.id = None cluster.accessible_member.add_member = Mock(return_value=False) self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) self.manager.me.client_urls = ['a'] cluster.accessible_member.delete_member = Mock(return_value=False) self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member.delete_member = cluster.accessible_member.add_member = Mock( return_value=True) self.manager.register_me(cluster) cluster.leader_id = None self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member = None self.manager.register_me(cluster)
def test_register_me(self): cluster = EtcdCluster(self.manager) cluster.load_members() self.manager.me.id = '1' self.manager.register_me(cluster) self.manager.me.id = None cluster.accessible_member.add_member = lambda e: False self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) self.manager.me.client_urls = ['a'] cluster.accessible_member.delete_member = lambda e: False self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member.delete_member = cluster.accessible_member.add_member = lambda e: True self.manager.register_me(cluster) cluster.leader_id = None self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member = None self.manager.register_me(cluster)
class TestEtcdCluster(unittest.TestCase): @patch('requests.get', requests_get) @patch('boto3.resource') def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' EtcdCluster.REGIONS = ['eu-west-1'] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertFalse(EtcdCluster.is_multiregion()) @patch('boto3.resource') def test_load_members(self, res): res.return_value.instances.filter.return_value = instances() self.assertEqual(len(self.cluster.members), 4) with patch('requests.get', Mock(side_effect=Exception)): self.cluster.load_members() def test_is_healthy(self): private_ip_address = '127.0.0.22' private_dns_name = 'ip-{}.eu-west-1.compute.internal'.format( private_ip_address.replace('.', '-')) url = 'http://' + private_ip_address peer_urls = ['{}:{}'.format(url, EtcdMember.DEFAULT_PEER_PORT)] me = EtcdMember({ 'id': 'ifoobari7', 'name': 'i-sadfjhg', 'clientURLs': [ '{}:{}'.format(private_ip_address, EtcdMember.DEFAULT_CLIENT_PORT) ], 'peerURLs': peer_urls }) me.private_ip_address = private_ip_address self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].instance_id = 'foo' self.cluster.members[-1].name = '' self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].peer_urls = peer_urls self.assertTrue(self.cluster.is_healthy(me)) self.cluster.members.pop() self.assertTrue(self.cluster.is_healthy(me))
def test_register_me(self, res): res.return_value.instances.filter.return_value = instances() cluster = EtcdCluster(self.manager) cluster.load_members() self.manager.me.id = '1' self.manager.register_me(cluster) self.manager.me.id = None cluster.accessible_member.add_member = Mock(return_value=False) self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) self.manager.me.client_urls = ['a'] cluster.accessible_member.delete_member = Mock(return_value=False) self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member.delete_member = cluster.accessible_member.add_member = Mock(return_value=True) self.manager.register_me(cluster) cluster.leader_id = None self.assertRaises(EtcdClusterException, self.manager.register_me, cluster) cluster.accessible_member = None self.manager.register_me(cluster)
class TestEtcdCluster(unittest.TestCase): @patch("requests.get", requests_get) @patch("boto3.resource") def setUp(self, res): res.return_value.instances.filter.return_value = instances() self.manager = EtcdManager() self.manager.instance_id = "i-deadbeef3" self.manager.region = "eu-west-1" EtcdCluster.REGIONS = ["eu-west-1"] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertFalse(EtcdCluster.is_multiregion()) @patch("boto3.resource") def test_load_members(self, res): res.return_value.instances.filter.return_value = instances() self.assertEqual(len(self.cluster.members), 4) with patch("requests.get", Mock(side_effect=Exception)): self.cluster.load_members() def test_is_healthy(self): private_ip_address = "127.0.0.22" private_dns_name = "ip-{}.eu-west-1.compute.internal".format(private_ip_address.replace(".", "-")) url = "http://" + private_ip_address peer_urls = ["{}:{}".format(url, EtcdMember.DEFAULT_PEER_PORT)] me = EtcdMember( { "id": "ifoobari7", "name": "i-sadfjhg", "clientURLs": ["{}:{}".format(private_ip_address, EtcdMember.DEFAULT_CLIENT_PORT)], "peerURLs": peer_urls, } ) me.private_ip_address = private_ip_address self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].instance_id = "foo" self.cluster.members[-1].name = "" self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].peer_urls = peer_urls self.assertTrue(self.cluster.is_healthy(me)) self.cluster.members.pop() self.assertTrue(self.cluster.is_healthy(me))
class TestEtcdMultiRegionCluster(unittest.TestCase): @patch('requests.get', requests_get_multiregion) @patch('boto3.resource') def setUp(self, res): res.return_value.instances.filter.return_value = public_instances() self.manager = EtcdManager() self.manager.instance_id = 'i-deadbeef3' self.manager.region = 'eu-west-1' EtcdCluster.REGIONS = ['eu-west-1', 'eu-central-1'] self.cluster = EtcdCluster(self.manager) self.cluster.load_members() self.assertTrue(EtcdCluster.is_multiregion()) @patch('boto3.resource') def test_load_members(self, res): res.return_value.instances.filter.return_value = public_instances() self.assertEqual(len(self.cluster.members), 7) with patch('requests.get', Mock(side_effect=Exception)): self.cluster.load_members() def test_is_healthy(self): public_dns_name = 'ec2-52-0-0-128.eu-west-1.compute.amazonaws.com' url = 'http://' + public_dns_name peer_urls = ['{}:{}'.format(url, EtcdMember.DEFAULT_PEER_PORT)] me = EtcdMember({ 'id': 'ifoobari0815', 'name': 'i-sadfjhg', 'clientURLs': ['{}:{}'.format(url, EtcdMember.DEFAULT_CLIENT_PORT)], 'peerURLs': peer_urls }) me.public_dns_name = public_dns_name self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].instance_id = 'foo' self.cluster.members[-1].name = '' self.assertFalse(self.cluster.is_healthy(me)) self.cluster.members[-1].peer_urls = peer_urls self.assertTrue(self.cluster.is_healthy(me)) self.cluster.members.pop() self.assertTrue(self.cluster.is_healthy(me))