mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
keep as much backward compatibility as possible.
Following changes were made:
1. All internal checks are performed as `role in ('master', 'primary')`
2. All internal variables/functions/methods are renamed
3. `GET /metrics` endpoint returns `patroni_primary` in addition to `patroni_master`.
4. Logs are changed to use leader/primary/member/remote depending on the context
5. Unit-tests are using only role = 'primary' instead of 'master' to verify that 1 works.
6. patronictl still supports old syntax, but also accepts `--leader` and `--primary`.
7. `master_(start|stop)_timeout` is automatically translated to `primary_(start|stop)_timeout` if the last one is not set.
8. updated the documentation and some examples
Future plan: in the next major release switch role name from `master` to `primary` and maybe drop `master` altogether.
The Kubernetes implementation will require more work and keep two labels in parallel. Label values should probably be configurable as described in https://github.com/zalando/patroni/issues/2495.
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
import botocore
|
|
import sys
|
|
import unittest
|
|
import urllib3
|
|
|
|
from mock import Mock, patch
|
|
from collections import namedtuple
|
|
from patroni.scripts.aws import AWSConnection, main as _main
|
|
|
|
|
|
class MockVolumes(object):
|
|
|
|
@staticmethod
|
|
def filter(*args, **kwargs):
|
|
oid = namedtuple('Volume', 'id')
|
|
return [oid(id='a'), oid(id='b')]
|
|
|
|
|
|
class MockEc2Connection(object):
|
|
|
|
volumes = MockVolumes()
|
|
|
|
@staticmethod
|
|
def create_tags(Resources, **kwargs):
|
|
if len(Resources) == 0:
|
|
raise botocore.exceptions.ClientError({'Error': {'Code': 503, 'Message': 'Request limit exceeded'}},
|
|
'create_tags')
|
|
return True
|
|
|
|
|
|
@patch('boto3.resource', Mock(return_value=MockEc2Connection()))
|
|
class TestAWSConnection(unittest.TestCase):
|
|
|
|
@patch('patroni.scripts.aws.requests_get', Mock(return_value=urllib3.HTTPResponse(
|
|
status=200, body=b'{"instanceId": "012345", "region": "eu-west-1"}')))
|
|
def setUp(self):
|
|
self.conn = AWSConnection('test')
|
|
|
|
def test_on_role_change(self):
|
|
self.assertTrue(self.conn.on_role_change('primary'))
|
|
with patch.object(MockVolumes, 'filter', Mock(return_value=[])):
|
|
self.conn._retry.max_tries = 1
|
|
self.assertFalse(self.conn.on_role_change('primary'))
|
|
|
|
@patch('patroni.scripts.aws.requests_get', Mock(side_effect=Exception('foo')))
|
|
def test_non_aws(self):
|
|
conn = AWSConnection('test')
|
|
self.assertFalse(conn.on_role_change("primary"))
|
|
|
|
@patch('patroni.scripts.aws.requests_get', Mock(return_value=urllib3.HTTPResponse(status=200, body=b'foo')))
|
|
def test_aws_bizare_response(self):
|
|
conn = AWSConnection('test')
|
|
self.assertFalse(conn.aws_available())
|
|
|
|
@patch('patroni.scripts.aws.requests_get', Mock(return_value=urllib3.HTTPResponse(status=503, body=b'Error')))
|
|
@patch('sys.exit', Mock())
|
|
def test_main(self):
|
|
self.assertIsNone(_main())
|
|
sys.argv = ['aws.py', 'on_start', 'replica', 'foo']
|
|
self.assertIsNone(_main())
|