@@ -110,82 +110,80 @@ async def test_tls_enabled(ops_test: OpsTest) -> None:
110
110
)
111
111
change_primary_start_timeout (ops_test , primary , 0 )
112
112
113
- # Pause Patroni so it doesn't wipe the custom changes
114
- await change_patroni_setting (ops_test , "pause" , True , use_random_unit = True , tls = True )
115
-
116
- async with ops_test .fast_forward ("24h" ):
117
- for attempt in Retrying (
118
- stop = stop_after_delay (60 * 5 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 30 )
119
- ):
120
- with attempt :
121
- # Promote the replica to primary.
122
- await run_command_on_unit (
123
- ops_test ,
124
- replica ,
125
- "sudo -u snap_daemon charmed-postgresql.pg-ctl -D /var/snap/charmed-postgresql/common/var/lib/postgresql/ promote" ,
126
- )
127
-
128
- # Check that the replica was promoted.
129
- host = get_unit_address (ops_test , replica )
130
- password = await get_password (ops_test , replica )
131
- with db_connect (host , password ) as connection :
132
- connection .autocommit = True
133
- with connection .cursor () as cursor :
134
- cursor .execute ("SELECT pg_is_in_recovery();" )
135
- in_recovery = cursor .fetchone ()[0 ]
136
- print (f"in_recovery: { in_recovery } " )
137
- assert not in_recovery
138
- connection .close ()
139
-
140
- # Write some data to the initial primary (this causes a divergence
141
- # in the instances' timelines).
142
- host = get_unit_address (ops_test , primary )
143
- password = await get_password (ops_test , primary )
144
- with db_connect (host , password ) as connection :
145
- connection .autocommit = True
146
- with connection .cursor () as cursor :
147
- cursor .execute ("CREATE TABLE IF NOT EXISTS pgrewindtest (testcol INT);" )
148
- cursor .execute ("INSERT INTO pgrewindtest SELECT generate_series(1,1000);" )
149
- connection .close ()
150
-
151
- # Stop the initial primary by killing both Patroni and PostgreSQL OS processes.
152
- await run_command_on_unit (
153
- ops_test ,
154
- primary ,
155
- "pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/14/bin/postgres" ,
156
- )
157
- await run_command_on_unit (
158
- ops_test ,
159
- primary ,
160
- "pkill --signal SIGKILL -f /snap/charmed-postgresql/[0-9]*/usr/bin/patroni" ,
161
- )
113
+ # Pause Patroni so it doesn't wipe the custom changes
114
+ await change_patroni_setting (ops_test , "pause" , True , use_random_unit = True , tls = True )
115
+
116
+ async with ops_test .fast_forward ("24h" ):
117
+ for attempt in Retrying (
118
+ stop = stop_after_delay (60 * 5 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 30 )
119
+ ):
120
+ with attempt :
121
+ # Promote the replica to primary.
122
+ await run_command_on_unit (
123
+ ops_test ,
124
+ replica ,
125
+ "sudo -u snap_daemon charmed-postgresql.pg-ctl -D /var/snap/charmed-postgresql/common/var/lib/postgresql/ promote" ,
126
+ )
127
+
128
+ # Check that the replica was promoted.
129
+ host = get_unit_address (ops_test , replica )
130
+ password = await get_password (ops_test , replica )
131
+ with db_connect (host , password ) as connection :
132
+ connection .autocommit = True
133
+ with connection .cursor () as cursor :
134
+ cursor .execute ("SELECT pg_is_in_recovery();" )
135
+ in_recovery = cursor .fetchone ()[0 ]
136
+ print (f"in_recovery: { in_recovery } " )
137
+ assert not in_recovery
138
+ connection .close ()
139
+
140
+ # Write some data to the initial primary (this causes a divergence
141
+ # in the instances' timelines).
142
+ host = get_unit_address (ops_test , primary )
143
+ password = await get_password (ops_test , primary )
144
+ with db_connect (host , password ) as connection :
145
+ connection .autocommit = True
146
+ with connection .cursor () as cursor :
147
+ cursor .execute ("CREATE TABLE IF NOT EXISTS pgrewindtest (testcol INT);" )
148
+ cursor .execute ("INSERT INTO pgrewindtest SELECT generate_series(1,1000);" )
149
+ connection .close ()
150
+
151
+ # Stop the initial primary by killing both Patroni and PostgreSQL OS processes.
152
+ await run_command_on_unit (
153
+ ops_test ,
154
+ primary ,
155
+ "pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/14/bin/postgres" ,
156
+ )
157
+ await run_command_on_unit (
158
+ ops_test ,
159
+ primary ,
160
+ "pkill --signal SIGKILL -f /snap/charmed-postgresql/[0-9]*/usr/bin/patroni" ,
161
+ )
162
162
163
- # Check that the primary changed.
164
- assert await primary_changed (ops_test , primary ), "primary not changed"
165
- change_primary_start_timeout (ops_test , primary , 300 )
163
+ # Check that the primary changed.
164
+ assert await primary_changed (ops_test , primary ), "primary not changed"
165
+ change_primary_start_timeout (ops_test , primary , 300 )
166
166
167
- # Check the logs to ensure TLS is being used by pg_rewind.
168
- primary = await get_primary (ops_test , primary )
169
- await run_command_on_unit (
170
- ops_test ,
171
- primary ,
172
- "grep 'connection authorized: user=rewind database=postgres SSL enabled' /var/snap/charmed-postgresql/common/var/log/postgresql/postgresql-*.log" ,
173
- )
167
+ # Check the logs to ensure TLS is being used by pg_rewind.
168
+ primary = await get_primary (ops_test , primary )
169
+ await run_command_on_unit (
170
+ ops_test ,
171
+ primary ,
172
+ "grep 'connection authorized: user=rewind database=postgres SSL enabled' /var/snap/charmed-postgresql/common/var/log/postgresql/postgresql-*.log" ,
173
+ )
174
174
175
- await change_patroni_setting (ops_test , "pause" , False , use_random_unit = True , tls = True )
175
+ await change_patroni_setting (ops_test , "pause" , False , use_random_unit = True , tls = True )
176
176
177
- # Remove the relation.
178
- await ops_test .model .applications [DATABASE_APP_NAME ].remove_relation (
179
- f"{ DATABASE_APP_NAME } :certificates" , f"{ tls_certificates_app_name } :certificates"
180
- )
181
- await ops_test .model .wait_for_idle (
182
- apps = [DATABASE_APP_NAME ], status = "active" , timeout = 1000
183
- )
177
+ # Remove the relation.
178
+ await ops_test .model .applications [DATABASE_APP_NAME ].remove_relation (
179
+ f"{ DATABASE_APP_NAME } :certificates" , f"{ tls_certificates_app_name } :certificates"
180
+ )
181
+ await ops_test .model .wait_for_idle (apps = [DATABASE_APP_NAME ], status = "active" , timeout = 1000 )
184
182
185
- # Wait for all units disabling TLS.
186
- for unit in ops_test .model .applications [DATABASE_APP_NAME ].units :
187
- assert await check_tls (ops_test , unit .name , enabled = False )
188
- assert await check_tls_patroni_api (ops_test , unit .name , enabled = False )
183
+ # Wait for all units disabling TLS.
184
+ for unit in ops_test .model .applications [DATABASE_APP_NAME ].units :
185
+ assert await check_tls (ops_test , unit .name , enabled = False )
186
+ assert await check_tls_patroni_api (ops_test , unit .name , enabled = False )
189
187
190
188
191
189
@pytest .mark .group (1 )
0 commit comments