From 859da0db0adb98505ad840afd0cd4f7527399554 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 27 Jul 2015 10:10:29 +0200 Subject: [PATCH] Make unit tets run again. --- postgres0.yml | 6 ++++-- postgres1.yml | 6 ++++-- tests/test_aws.py | 32 +++++++++++++++++++++++++------- tests/test_postgresql.py | 10 +++++----- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/postgres0.yml b/postgres0.yml index 0cb694a1..6c9fb82d 100644 --- a/postgres0.yml +++ b/postgres0.yml @@ -1,20 +1,22 @@ ttl: &ttl 30 loop_wait: &loop_wait 10 +scope: &scope batman restapi: listen: 127.0.0.1:8008 connect_address: 127.0.0.1:8008 etcd: - scope: batman + scope: *scope ttl: *ttl host: 127.0.0.1:4001 #discovery_srv: my-etcd.domain #zookeeper: -# scope: batman +# scope: *scope # session_timeout: *ttl # reconnect_timeout: *loop_wait # hosts: 127.0.0.1:2181 postgresql: name: postgresql0 + scope: *scope listen: 127.0.0.1:5432 connect_address: 127.0.0.1:5432 data_dir: data/postgresql0 diff --git a/postgres1.yml b/postgres1.yml index 680091f1..1928cee7 100644 --- a/postgres1.yml +++ b/postgres1.yml @@ -1,20 +1,22 @@ ttl: &ttl 30 loop_wait: &loop_wait 10 +scope: &scope batman restapi: listen: 127.0.0.1:8009 connect_address: 127.0.0.1:8009 etcd: - scope: batman + scope: *scope ttl: *ttl host: 127.0.0.1:4001 #discovery_srv: my-etcd.domain #zookeeper: -# scope: batman +# scope: *scope # session_timeout: *ttl # reconnect_timeout: *loop_wait # hosts: 127.0.0.1:2181 postgresql: name: postgresql1 + scope: *scope listen: 127.0.0.1:5433 connect_address: 127.0.0.1:5433 data_dir: data/postgresql1 diff --git a/tests/test_aws.py b/tests/test_aws.py index 63b50734..4331badb 100644 --- a/tests/test_aws.py +++ b/tests/test_aws.py @@ -2,7 +2,7 @@ import unittest import requests import boto.ec2 from collections import namedtuple -from helpers.aws import AWSConnection +from scripts.aws import AWSConnection from requests.exceptions import RequestException import yaml @@ -24,6 +24,16 @@ class MockEc2Connection: return True +class MockResponse: + + def __init__(self, content): + self.content = content + self.ok = True + + def json(self): + return self.content + + class TestAWSConnection(unittest.TestCase): def __init__(self, method_name='runTest'): @@ -44,25 +54,28 @@ class TestAWSConnection(unittest.TestCase): result = namedtuple('Request', 'ok content') result.ok = True if url.split('/')[-1] == 'document': - result.content = '{\n "instanceId" : "012345",\n "region" : "eu-west-1"\n}' + result = {"instanceId": "012345", "region": "eu-west-1"} else: - result.content = 'foo' - return result + result = 'foo' + return MockResponse(result) def setUp(self): self.error = False requests.get = self.requests_get boto.ec2.connect_to_region = self.boto_ec2_connect_to_region self.config_string = """ -loop_wait: 10 +scope: &scope test +ttl: &ttl 30 +loop_wait: &loop_wait 10 restapi: listen: 0.0.0.0:8008 connect_address: 127.0.0.1:5432 etcd: - scope: test - ttl: 30 + scope: *scope + ttl: *ttl host: 127.0.0.1:8080 postgresql: + scope: *scope name: postgresql_foo listen: 0.0.0.0:5432 connect_address: 127.0.0.1:5432 @@ -76,6 +89,11 @@ postgresql: admin: username: admin password: admin + callbacks: + on_start: patroni/scripts/aws.py + on_stop: patroni/scripts/aws.py + on_restart: patroni/scripts/aws.py + on_role_change: patroni/scripts/aws.py parameters: archive_mode: "on" wal_level: hot_standby diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index d6c01f5b..069c4622 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -110,15 +110,15 @@ class TestPostgresql(unittest.TestCase): def set_up(self): subprocess.call = subprocess_call shutil.copy = nop - self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, *:5432', - 'connect_address': '127.0.0.2:5432', + self.p = Postgresql({'name': 'test0', 'scope': 'batman', 'data_dir': 'data/test0', + 'listen': '127.0.0.1, *:5432', 'connect_address': '127.0.0.2:5432', 'pg_hba': ['hostssl all all 0.0.0.0/0 md5', 'host all all 0.0.0.0/0 md5'], - 'superuser': {'password': ''}, 'admin': {'username': 'admin', 'password': 'admin'}, + 'superuser': {'password': ''}, + 'admin': {'username': 'admin', 'password': 'admin'}, 'replication': {'username': 'replicator', 'password': 'rep-pass', 'network': '127.0.0.1/32'}, - 'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'}}, - on_change_callback=lambda state: True) + 'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'}}) psycopg2.connect = psycopg2_connect if not os.path.exists(self.p.data_dir): os.makedirs(self.p.data_dir)