7
7
import subprocess
8
8
from pathlib import Path
9
9
from tempfile import mkstemp
10
- from typing import Dict , Optional , Set , Tuple
10
+ from typing import Dict , Optional , Set , Tuple , Union
11
11
12
12
import psycopg2
13
13
import requests
@@ -137,7 +137,11 @@ async def app_name(
137
137
138
138
139
139
async def change_patroni_setting (
140
- ops_test : OpsTest , setting : str , value : int , use_random_unit : bool = False
140
+ ops_test : OpsTest ,
141
+ setting : str ,
142
+ value : Union [int , bool ],
143
+ use_random_unit : bool = False ,
144
+ tls : bool = False ,
141
145
) -> None :
142
146
"""Change the value of one of the Patroni settings.
143
147
@@ -146,8 +150,13 @@ async def change_patroni_setting(
146
150
setting: the name of the setting.
147
151
value: the value to assign to the setting.
148
152
use_random_unit: whether to use a random unit (default is False,
149
- so it uses the primary)
153
+ so it uses the primary).
154
+ tls: if Patroni is serving using tls.
150
155
"""
156
+ if tls :
157
+ schema = "https"
158
+ else :
159
+ schema = "http"
151
160
for attempt in Retrying (stop = stop_after_delay (30 * 2 ), wait = wait_fixed (3 )):
152
161
with attempt :
153
162
app = await app_name (ops_test )
@@ -158,8 +167,9 @@ async def change_patroni_setting(
158
167
primary_name = await get_primary (ops_test , app )
159
168
unit_ip = get_unit_address (ops_test , primary_name )
160
169
requests .patch (
161
- f"http ://{ unit_ip } :8008/config" ,
170
+ f"{ schema } ://{ unit_ip } :8008/config" ,
162
171
json = {setting : value },
172
+ verify = not tls ,
163
173
)
164
174
165
175
@@ -399,22 +409,27 @@ async def get_ip_from_inside_the_unit(ops_test: OpsTest, unit_name: str) -> str:
399
409
return stdout .splitlines ()[0 ].strip ()
400
410
401
411
402
- async def get_patroni_setting (ops_test : OpsTest , setting : str ) -> Optional [int ]:
412
+ async def get_patroni_setting (ops_test : OpsTest , setting : str , tls : bool = False ) -> Optional [int ]:
403
413
"""Get the value of one of the integer Patroni settings.
404
414
405
415
Args:
406
416
ops_test: ops_test instance.
407
417
setting: the name of the setting.
418
+ tls: if Patroni is serving using tls.
408
419
409
420
Returns:
410
421
the value of the configuration or None if it's using the default value.
411
422
"""
423
+ if tls :
424
+ schema = "https"
425
+ else :
426
+ schema = "http"
412
427
for attempt in Retrying (stop = stop_after_delay (30 * 2 ), wait = wait_fixed (3 )):
413
428
with attempt :
414
429
app = await app_name (ops_test )
415
430
primary_name = await get_primary (ops_test , app )
416
431
unit_ip = get_unit_address (ops_test , primary_name )
417
- configuration_info = requests .get (f"http ://{ unit_ip } :8008/config" )
432
+ configuration_info = requests .get (f"{ schema } ://{ unit_ip } :8008/config" , verify = not tls )
418
433
value = configuration_info .json ().get (setting )
419
434
return int (value ) if value is not None else None
420
435
0 commit comments