Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0d15e64

Browse files
committed
refactoring in script
1 parent 43b264e commit 0d15e64

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

run_shardlord.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from time import sleep
44

55
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"
710

811

912
class Shardlord(PostgresNode):
@@ -12,6 +15,12 @@ def __init__(self, name):
1215

1316
self.nodes = []
1417

18+
@staticmethod
19+
def _common_conn_string(port):
20+
return (
21+
"host=localhost port={} dbname={} user={}"
22+
).format(port, DBNAME, default_username())
23+
1524
@staticmethod
1625
def _common_conf_lines():
1726
return (
@@ -33,13 +42,15 @@ def _common_conf_lines():
3342
def init(self):
3443
super(Shardlord, self).init()
3544

45+
conn_string = self._common_conn_string(self.port)
46+
3647
config_lines = (
3748
"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"
4051
"shardman.cmd_retry_naptime = 500\n"
4152
"shardman.poll_interval = 500\n"
42-
).format(self.port)
53+
).format(DBNAME, conn_string)
4354

4455
# add common config lines
4556
config_lines += self._common_conf_lines()
@@ -49,7 +60,7 @@ def init(self):
4960
return self
5061

5162
def install(self):
52-
self.safe_psql(dbname="postgres",
63+
self.safe_psql(dbname=DBNAME,
5364
query="create extension pg_shardman cascade")
5465

5566
return self
@@ -80,14 +91,13 @@ def add_node(self, name):
8091
node.init() \
8192
.append_conf("postgresql.conf", config_lines) \
8293
.start() \
83-
.safe_psql(dbname="postgres",
94+
.safe_psql(dbname=DBNAME,
8495
query="create extension pg_shardman cascade")
8596

8697
# 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)
91101

92102
return self
93103

0 commit comments

Comments
 (0)