Skip to content

Commit fd66a6c

Browse files
author
chenyunliang520
committed
Update tests-ssl.yml and cluster_ha_showcase.py: Enhance config permissions to include directory creation, add null checks for database queries, and improve error handling in connect_with_retry
1 parent c0ea136 commit fd66a6c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.github/workflows/tests-ssl.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ jobs:
7070
7171
- name: Set config permissions
7272
run: |
73-
sudo chown -R omm:omm ${{ github.workspace }}/opengauss/conf
73+
sudo mkdir -p ${{ github.workspace }}/opengauss/conf
74+
sudo chown -R omm:omm ${{ github.workspace }}/opengauss
7475
7576
- name: Create postgresql.conf with SSL
7677
run: |

example/cluster_ha_showcase.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ def get_cluster_mode(conn: Connection) -> str:
3535
with conn.cursor() as cur:
3636
try:
3737
cur.execute("SELECT local_role FROM pg_stat_get_stream_replications()")
38-
local_role = cur.fetchone()[0].lower()
38+
row = cur.fetchone()
39+
if row is None:
40+
return "single"
41+
local_role = row[0].lower()
3942
if local_role in ("primary", "standby"):
4043
return "master-standby"
4144
elif local_role == "normal":
4245
try:
4346
cur.execute("SELECT count(1) FROM pgxc_node")
44-
node_count = cur.fetchone()[0]
47+
row = cur.fetchone()
48+
if row is None:
49+
node_count = 0
50+
else:
51+
node_count = row[0]
4552
return "distributed" if node_count > 0 else "single"
4653
except Error:
4754
logger.warning("pgxc_node 表不存在,返回 single 模式")
@@ -72,7 +79,10 @@ def get_node_role(conn: Connection, cluster_mode: str, host: str, port: str) ->
7279
"SELECT CASE WHEN pg_is_in_recovery() "
7380
"THEN 'Standby' ELSE 'Primary' END"
7481
)
75-
return cur.fetchone()[0]
82+
row = cur.fetchone()
83+
if row is None:
84+
return 'single'
85+
return row[0]
7686
elif cluster_mode == "distributed":
7787
cur.execute(
7888
"SELECT node_name, node_host FROM pgxc_node "
@@ -108,6 +118,7 @@ def connect_with_retry(
108118
if attempt == max_attempts:
109119
raise
110120
time.sleep(2**attempt)
121+
raise RuntimeError(f"连接失败: {dsn}")
111122

112123

113124
def disaster_recovery(params, simulate_failure: bool = False):

0 commit comments

Comments
 (0)