11from contextlib import contextmanager
22import dataclasses
33from pathlib import Path
4+ import time
45from typing import Any , Callable , Dict , Generator , List
56import urllib .parse
67import uuid
2829
2930_RETRY_ARGS = {
3031 "wait" : tenacity .wait_exponential (max = 10 ),
31- "stop" : tenacity .stop_after_attempt (10 ),
32+ "stop" : tenacity .stop_after_attempt (5 ),
3233 "reraise" : True ,
3334}
3435
@@ -76,33 +77,36 @@ class Settings(BaseSettings):
7677 # The default values assume the docker-compose.yml in the infra/local has been used.
7778 # These are provided for the convenience of easily running a debugger without having
7879 # to set up remote debugging
79- host_netloc : str = "localhost:58080 "
80- docker_netloc : str = "traefik "
81- s3_access_key : str = "adpuser "
80+ host_netloc : str = "localhost:50080 "
81+ docker_netloc : str = "adp-router:50080 "
82+ s3_access_key : str = "adpsuperuser "
8283 s3_secret_key : str = "adppassword"
83- s3_bucket : str = "e2e-tests-warehouse "
84- s3_endpoint : str = "http://minio :59000"
84+ s3_bucket : str = "e2e-tests"
85+ s3_endpoint : str = "http://adp-router :59000"
8586 s3_region : str = "local-01"
8687 s3_path_style_access : bool = True
87- openid_client_id : str = "localinfra "
88+ openid_client_id : str = "machine-infra "
8889 openid_client_secret : str = "s3cr3t"
8990 openid_scope : str = "lakekeeper"
91+ project_id : str = "c4fcd44f-7ce7-4446-9f7c-dcc7ba76dd22"
9092 warehouse_name : str = "e2e_tests"
9193
9294 # trino
93- trino_http_scheme : str = "http "
95+ trino_http_scheme : str = "https "
9496 trino_host : str = "localhost"
95- trino_port : str = "59088 "
96- trino_user : str = "trino "
97- trino_password : str = ""
97+ trino_port : str = "58443 "
98+ trino_user : str = "machine-infra "
99+ trino_password : str = "s3cr3t "
98100
99101 @property
100102 def lakekeeper_url (self ) -> Endpoint :
101103 return Endpoint (f"http://{ self .host_netloc } /iceberg" , self .docker_netloc )
102104
103105 @property
104106 def openid_provider_uri (self ) -> Endpoint :
105- return Endpoint (f"http://{ self .host_netloc } /auth/realms/iceberg" , self .docker_netloc )
107+ return Endpoint (
108+ f"http://{ self .host_netloc } /auth/realms/analytics-data-platform" , self .docker_netloc
109+ )
106110
107111 def storage_config (self ) -> Dict [str , Any ]:
108112 return {
@@ -129,26 +133,12 @@ def storage_config(self) -> Dict[str, Any]:
129133
130134
131135class Server :
136+ """Wraps a Lakekeeper instance. It is assumed that the instance is bootstrapped."""
137+
132138 def __init__ (self , access_token : str , settings : Settings ):
133139 self .access_token = access_token
134140 self .settings = settings
135141
136- # Bootstrap server once
137- management_endpoint_v1 = self .management_endpoint (version = 1 )
138- server_info = self ._request_with_auth (
139- requests .get ,
140- url = management_endpoint_v1 + "/info" ,
141- )
142- server_info .raise_for_status ()
143- server_info = server_info .json ()
144- if not server_info ["bootstrapped" ]:
145- response = self ._request_with_auth (
146- requests .post ,
147- management_endpoint_v1 + "/bootstrap" ,
148- json = {"accept-terms-of-use" : True },
149- )
150- response .raise_for_status ()
151-
152142 @property
153143 def token_endpoint (self ) -> Endpoint :
154144 return self .settings .openid_provider_uri + "/protocol/openid-connect/token"
@@ -169,13 +159,11 @@ def management_endpoint(self, *, version: int | None = None) -> Endpoint:
169159 def warehouse_endpoint (self , * , version : int = 1 ) -> Endpoint :
170160 return self .management_endpoint (version = version ) + "/warehouse"
171161
172- def create_warehouse (
173- self , name : str , project_id : uuid .UUID , storage_config : dict
174- ) -> "Warehouse" :
162+ def create_warehouse (self , name : str , project_id : str , storage_config : dict ) -> "Warehouse" :
175163 """Create a warehouse in this server"""
176164
177165 payload = {
178- "project-id" : str ( project_id ) ,
166+ "project-id" : project_id ,
179167 ** storage_config ,
180168 }
181169
@@ -233,6 +221,7 @@ def connect(self) -> PyIcebergCatalog:
233221 """Connect to the warehouse in the catalog"""
234222 creds = PyIcebergCatalogCredentials ()
235223 creds .uri = str (self .server .catalog_endpoint ())
224+ creds .project_id = self .server .settings .project_id
236225 creds .warehouse = self .name
237226 creds .oauth2_server_uri = str (self .server .token_endpoint )
238227 creds .client_id = self .server .settings .openid_client_id
@@ -326,12 +315,7 @@ def server(access_token: str) -> Server:
326315
327316
328317@pytest .fixture (scope = "session" )
329- def project () -> uuid .UUID :
330- return uuid .UUID ("{00000000-0000-0000-0000-000000000000}" )
331-
332-
333- @pytest .fixture (scope = "session" )
334- def warehouse (server : Server , project : uuid .UUID ) -> Generator :
318+ def warehouse (server : Server ) -> Generator :
335319 if not settings .warehouse_name :
336320 raise ValueError ("Empty 'warehouse_name' is not allowed." )
337321
@@ -349,7 +333,9 @@ def warehouse(server: Server, project: uuid.UUID) -> Generator:
349333 minio_client .make_bucket (bucket_name = bucket_name )
350334 print (f"Bucket { bucket_name } created." )
351335
352- warehouse = server .create_warehouse (settings .warehouse_name , project , storage_config )
336+ warehouse = server .create_warehouse (
337+ settings .warehouse_name , server .settings .project_id , storage_config
338+ )
353339 print (f"Warehouse { warehouse .project_id } created." )
354340 try :
355341 yield warehouse
@@ -360,6 +346,8 @@ def _remove_bucket(bucket_name):
360346 minio_client .remove_bucket (bucket_name = bucket_name )
361347
362348 try :
349+ # Allow a brief pause for the test operations to complete
350+ time .sleep (1 )
363351 server .purge_warehouse (warehouse )
364352 server .delete_warehouse (warehouse )
365353 _remove_bucket (bucket_name )
0 commit comments