4
4
import asyncio
5
5
import logging
6
6
7
- import psycopg2
8
7
import pytest
9
8
from pip ._vendor import requests
10
9
from pytest_operator .plugin import OpsTest
16
15
get_machine_from_unit ,
17
16
get_password ,
18
17
get_unit_address ,
19
- run_command_on_unit , scale_application , build_connection_string , FIRST_DATABASE_RELATION_NAME ,
18
+ run_command_on_unit ,
19
+ scale_application ,
20
20
)
21
21
from .conftest import APPLICATION_NAME
22
22
from .helpers import (
29
29
change_patroni_setting ,
30
30
change_wal_settings ,
31
31
check_writes ,
32
+ create_test_data ,
32
33
cut_network_from_unit ,
33
34
cut_network_from_unit_without_ip_change ,
34
35
fetch_cluster_members ,
35
36
get_controller_machine ,
37
+ get_db_connection ,
36
38
get_patroni_setting ,
37
39
get_primary ,
38
40
get_unit_ip ,
51
53
storage_id ,
52
54
storage_type ,
53
55
update_restart_condition ,
54
- wait_network_restore , get_db_connection , validate_test_data , create_test_data ,
56
+ validate_test_data ,
57
+ wait_network_restore ,
55
58
)
56
59
57
60
logger = logging .getLogger (__name__ )
@@ -584,8 +587,10 @@ async def test_deploy_zero_units(ops_test: OpsTest):
584
587
for unit_ip in unit_ip_addresses :
585
588
try :
586
589
resp = requests .get (f"http://{ unit_ip } :8008" )
587
- assert resp .status_code != 200 , f"status code = { resp .status_code } , message = { resp .text } "
588
- except requests .exceptions .ConnectionError as e :
590
+ assert (
591
+ resp .status_code != 200
592
+ ), f"status code = { resp .status_code } , message = { resp .text } "
593
+ except requests .exceptions .ConnectionError :
589
594
assert True , f"unit host = http://{ unit_ip } :8008, all units shutdown"
590
595
except Exception as e :
591
596
assert False , f"{ e } unit host = http://{ unit_ip } :8008, something went wrong"
@@ -608,13 +613,13 @@ async def test_deploy_zero_units(ops_test: OpsTest):
608
613
await ops_test .model .wait_for_idle (status = "active" , timeout = 3000 )
609
614
for unit in ops_test .model .applications [app ].units :
610
615
if not await unit .is_leader_from_status ():
611
- assert await reused_replica_storage (ops_test , unit_name = unit .name
612
- ), "attached storage not properly re-used by Postgresql."
616
+ assert await reused_replica_storage (
617
+ ops_test , unit_name = unit .name
618
+ ), "attached storage not properly re-used by Postgresql."
613
619
logger .info (f"check test database data of unit name { unit .name } " )
614
- connection_string , _ = await get_db_connection (ops_test ,
615
- dbname = dbname ,
616
- is_primary = False ,
617
- replica_unit_name = unit .name )
620
+ connection_string , _ = await get_db_connection (
621
+ ops_test , dbname = dbname , is_primary = False , replica_unit_name = unit .name
622
+ )
618
623
await validate_test_data (connection_string )
619
624
620
- await check_writes (ops_test )
625
+ await check_writes (ops_test )
0 commit comments