33# See LICENSE file for licensing details.
44
55import logging
6+ import os
67import subprocess
78from pathlib import Path
89from string import Template
1415import pytest
1516import yaml
1617from botocore .client import Config
18+ from dotenv import load_dotenv
1719
18- from .types import IntegrationTestsCharms , TestCharm
20+ from .types import IntegrationTestsCharms , S3Info , TestCharm
1921
22+ load_dotenv ()
2023logger = logging .getLogger (__name__ )
2124logging .getLogger ("jubilant.wait" ).setLevel (logging .WARNING )
2225
@@ -112,23 +115,29 @@ def charm_versions() -> IntegrationTestsCharms:
112115
113116
114117@pytest .fixture (scope = "module" )
115- def s3_bucket_and_creds (request : pytest .FixtureRequest ):
118+ def s3_bucket_and_creds (request : pytest .FixtureRequest ) -> Iterable [ S3Info ] :
116119 keep_models = bool (request .config .getoption ("--keep-models" ))
117- logger .info ("Fetching S3 credentials from minio....." )
118120
119- fetch_s3_output = (
120- subprocess .check_output (
121- "./tests/integration/setup/fetch_s3_credentials.sh | tail -n 3" ,
122- shell = True ,
123- stderr = None ,
121+ if any (
122+ (
123+ (access_key := os .environ .get ("S3_ACCESS_KEY" , None )) is None ,
124+ (secret_key := os .environ .get ("S3_SECRET_KEY" , None )) is None ,
125+ (endpoint_url := os .environ .get ("S3_SERVER_URL" , None )) is None ,
126+ )
127+ ):
128+ logger .info ("Fetching S3 credentials from minio....." )
129+ fetch_s3_output = (
130+ subprocess .check_output (
131+ "./tests/integration/setup/fetch_s3_credentials.sh | tail -n 3" ,
132+ shell = True ,
133+ stderr = None ,
134+ )
135+ .decode ("utf-8" )
136+ .strip ()
124137 )
125- .decode ("utf-8" )
126- .strip ()
127- )
128-
129- logger .info (f"fetch_s3_credentials output:\n { fetch_s3_output } " )
130138
131- endpoint_url , access_key , secret_key = fetch_s3_output .strip ().splitlines ()
139+ logger .info (f"fetch_s3_credentials output:\n { fetch_s3_output } " )
140+ endpoint_url , access_key , secret_key = fetch_s3_output .strip ().splitlines ()
132141
133142 session = boto3 .session .Session (aws_access_key_id = access_key , aws_secret_access_key = secret_key )
134143 s3 = session .resource (
@@ -155,13 +164,14 @@ def s3_bucket_and_creds(request: pytest.FixtureRequest):
155164 # Create the test bucket
156165 s3 .create_bucket (Bucket = TEST_BUCKET_NAME )
157166 logger .info (f"Created bucket: { TEST_BUCKET_NAME } " )
158- test_bucket .put_object (Key = TEST_PATH_NAME )
167+ test_bucket .put_object (Key = os . path . join ( TEST_PATH_NAME , "touch" ) )
159168 yield {
160- "endpoint" : endpoint_url ,
161- "access_key" : access_key ,
162- "secret_key" : secret_key ,
169+ "endpoint" : str ( endpoint_url ) ,
170+ "access_key" : str ( access_key ) ,
171+ "secret_key" : str ( secret_key ) ,
163172 "bucket" : TEST_BUCKET_NAME ,
164173 "path" : TEST_PATH_NAME ,
174+ "ca_bundle_path" : os .environ .get ("S3_CA_BUNDLE_PATH" , "" ),
165175 }
166176
167177 if not keep_models :
0 commit comments