Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
4a21b4e8
Commit
4a21b4e8
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
change(test_postgresql): return message on replication check
parent
1b65a39d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_postgresql.py
+14
-10
14 additions, 10 deletions
tests/test_postgresql.py
with
14 additions
and
10 deletions
tests/test_postgresql.py
+
14
−
10
View file @
4a21b4e8
...
...
@@ -232,7 +232,7 @@ def check_psql(db_conn: dict, query: str) -> bool:
return
True
def
check_replication
(
primary
:
dict
,
standby
:
dict
)
->
bool
:
def
check_replication
(
primary
:
dict
,
standby
:
dict
)
->
tuple
:
"""
Check if replication is working between the primary and standby servers.
:param primary: Database connection parameters for primary server
...
...
@@ -240,7 +240,7 @@ def check_replication(primary: dict, standby: dict) -> bool:
:param standby: Database connection parameters for standby server
:type standby: dict
:return: Wether replication between primary/stanbdy is working or not
:rtype:
bool
:rtype:
tuple
"""
# connections
...
...
@@ -248,8 +248,8 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_client
=
psycopg2
.
connect
(
**
primary
)
standby_client
=
psycopg2
.
connect
(
**
standby
)
except
psycopg2
.
Error
:
error
(
"
Cannot connect to the databases
"
)
return
False
msg
=
"
connection error
"
return
False
,
msg
# random id
rand
=
uuid
.
uuid4
().
hex
...
...
@@ -262,7 +262,8 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_psql
=
primary_client
.
cursor
()
primary_psql
.
execute
(
write_query
)
except
psycopg2
.
Error
:
return
False
msg
=
"
write error
"
return
False
,
msg
# read
max_time
=
6.0
...
...
@@ -273,11 +274,13 @@ def check_replication(primary: dict, standby: dict) -> bool:
try
:
standby_psql
=
primary_client
.
cursor
()
standby_psql
.
execute
(
read_query
)
msg
=
"
took ~{}s
"
.
format
(
str
(
timer
))
break
except
psycopg2
.
Error
:
pass
else
:
return
False
msg
=
"
read error
"
return
False
,
msg
# delete
try
:
...
...
@@ -291,7 +294,7 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_client
.
close
()
standby_client
.
close
()
return
True
return
True
,
msg
def
check_ha
(
db_conn
:
dict
,
errors
:
int
=
0
)
->
int
:
...
...
@@ -350,11 +353,12 @@ def check_ha(db_conn: dict, errors: int = 0) -> int:
primary
[
"
port
"
]
=
54321
standby
=
db_conn
standby
[
"
port
"
]
=
54322
if
not
check_replication
(
primary
,
standby
):
error
(
"
Cannot replicate data between primary/standby
"
)
status
,
info
=
check_replication
(
primary
,
standby
)
if
not
status
:
error
(
"
Cannot replicate data between primary/standby: {}
"
.
format
(
info
))
errors
+=
1
else
:
success
(
"
Can replicate data between primary/standby
"
)
success
(
"
Can replicate data between primary/standby
: {}
"
.
format
(
info
)
)
return
errors
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment