77import subprocess
88from pathlib import Path
99from tempfile import mkstemp
10- from typing import Dict , Optional , Set , Tuple
10+ from typing import Dict , Optional , Set , Tuple , Union
1111
1212import psycopg2
1313import requests
@@ -137,7 +137,11 @@ async def app_name(
137137
138138
139139async 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 ,
141145) -> None :
142146 """Change the value of one of the Patroni settings.
143147
@@ -146,8 +150,13 @@ async def change_patroni_setting(
146150 setting: the name of the setting.
147151 value: the value to assign to the setting.
148152 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.
150155 """
156+ if tls :
157+ schema = "https"
158+ else :
159+ schema = "http"
151160 for attempt in Retrying (stop = stop_after_delay (30 * 2 ), wait = wait_fixed (3 )):
152161 with attempt :
153162 app = await app_name (ops_test )
@@ -158,8 +167,9 @@ async def change_patroni_setting(
158167 primary_name = await get_primary (ops_test , app )
159168 unit_ip = get_unit_address (ops_test , primary_name )
160169 requests .patch (
161- f"http ://{ unit_ip } :8008/config" ,
170+ f"{ schema } ://{ unit_ip } :8008/config" ,
162171 json = {setting : value },
172+ verify = not tls ,
163173 )
164174
165175
@@ -399,22 +409,27 @@ async def get_ip_from_inside_the_unit(ops_test: OpsTest, unit_name: str) -> str:
399409 return stdout .splitlines ()[0 ].strip ()
400410
401411
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 ]:
403413 """Get the value of one of the integer Patroni settings.
404414
405415 Args:
406416 ops_test: ops_test instance.
407417 setting: the name of the setting.
418+ tls: if Patroni is serving using tls.
408419
409420 Returns:
410421 the value of the configuration or None if it's using the default value.
411422 """
423+ if tls :
424+ schema = "https"
425+ else :
426+ schema = "http"
412427 for attempt in Retrying (stop = stop_after_delay (30 * 2 ), wait = wait_fixed (3 )):
413428 with attempt :
414429 app = await app_name (ops_test )
415430 primary_name = await get_primary (ops_test , app )
416431 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 )
418433 value = configuration_info .json ().get (setting )
419434 return int (value ) if value is not None else None
420435
0 commit comments