3
3
from time import sleep
4
4
5
5
from testgres import PostgresNode
6
- from testgres import get_new_node
6
+ from testgres import get_new_node , default_username
7
+
8
+
9
+ DBNAME = "postgres"
7
10
8
11
9
12
class Shardlord (PostgresNode ):
@@ -12,6 +15,12 @@ def __init__(self, name):
12
15
13
16
self .nodes = []
14
17
18
+ @staticmethod
19
+ def _common_conn_string (port ):
20
+ return (
21
+ "host=localhost port={} dbname={} user={}"
22
+ ).format (port , DBNAME , default_username ())
23
+
15
24
@staticmethod
16
25
def _common_conf_lines ():
17
26
return (
@@ -33,13 +42,15 @@ def _common_conf_lines():
33
42
def init (self ):
34
43
super (Shardlord , self ).init ()
35
44
45
+ conn_string = self ._common_conn_string (self .port )
46
+
36
47
config_lines = (
37
48
"shardman.shardlord = on\n "
38
- "shardman.shardlord_dbname = postgres \n "
39
- "shardman.shardlord_connstring = 'dbname=postgres port= {}'\n "
49
+ "shardman.shardlord_dbname = {} \n "
50
+ "shardman.shardlord_connstring = '{}'\n "
40
51
"shardman.cmd_retry_naptime = 500\n "
41
52
"shardman.poll_interval = 500\n "
42
- ).format (self . port )
53
+ ).format (DBNAME , conn_string )
43
54
44
55
# add common config lines
45
56
config_lines += self ._common_conf_lines ()
@@ -49,7 +60,7 @@ def init(self):
49
60
return self
50
61
51
62
def install (self ):
52
- self .safe_psql (dbname = "postgres" ,
63
+ self .safe_psql (dbname = DBNAME ,
53
64
query = "create extension pg_shardman cascade" )
54
65
55
66
return self
@@ -80,14 +91,13 @@ def add_node(self, name):
80
91
node .init () \
81
92
.append_conf ("postgresql.conf" , config_lines ) \
82
93
.start () \
83
- .safe_psql (dbname = "postgres" ,
94
+ .safe_psql (dbname = DBNAME ,
84
95
query = "create extension pg_shardman cascade" )
85
96
86
97
# finally, register this node
87
- add_node_cmd = (
88
- "select shardman.add_node('dbname={} port={}')"
89
- ).format ("postgres" , node .port )
90
- self .safe_psql ("postgres" , add_node_cmd )
98
+ conn_string = self ._common_conn_string (node .port )
99
+ add_node_cmd = "select shardman.add_node('{}')" .format (conn_string )
100
+ self .safe_psql (DBNAME , add_node_cmd )
91
101
92
102
return self
93
103
0 commit comments