Skip to content

Commit 15f4186

Browse files
Fixes and adds configurability to test_spark_sql_s3_with_privileges.py regtest (apache#1060) (apache#23)
* Test fix and ability to pass REG_TEST_TOKEN * Ability to configure bucket prefix * Add reg_test env var to docker compose * PR Comments * Add path prefix * Nit Updates * More updates * PR Feedback --------- Co-authored-by: Travis Bowen <122238243+travis-bowen@users.noreply.github.com>
1 parent 0d3788e commit 15f4186

File tree

3 files changed

+99
-66
lines changed

3 files changed

+99
-66
lines changed

regtests/run.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,26 @@ NUM_SUCCESSES=0
6767
export AWS_ACCESS_KEY_ID=''
6868
export AWS_SECRET_ACCESS_KEY=''
6969

70-
if ! output=$(curl -X POST -H "Polaris-Realm: POLARIS" "http://${POLARIS_HOST:-localhost}:8181/api/catalog/v1/oauth/tokens" \
71-
-d "grant_type=client_credentials" \
72-
-d "client_id=root" \
73-
-d "client_secret=secret" \
74-
-d "scope=PRINCIPAL_ROLE:ALL"); then
75-
logred "Error: Failed to retrieve bearer token"
76-
exit 1
77-
fi
70+
# Allow bearer token to be provided if desired
71+
if [[ -z "$REGTEST_ROOT_BEARER_TOKEN" ]]; then
72+
if ! output=$(curl -X POST -H "Polaris-Realm: POLARIS" "http://${POLARIS_HOST:-localhost}:8181/api/catalog/v1/oauth/tokens" \
73+
-d "grant_type=client_credentials" \
74+
-d "client_id=root" \
75+
-d "client_secret=secret" \
76+
-d "scope=PRINCIPAL_ROLE:ALL"); then
77+
logred "Error: Failed to retrieve bearer token"
78+
exit 1
79+
fi
7880

79-
token=$(echo "$output" | awk -F\" '{print $4}')
81+
token=$(echo "$output" | awk -F\" '{print $4}')
8082

81-
if [ "$token" == "unauthorized_client" ]; then
82-
logred "Error: Failed to retrieve bearer token"
83-
exit 1
84-
fi
83+
if [ "$token" == "unauthorized_client" ]; then
84+
logred "Error: Failed to retrieve bearer token"
85+
exit 1
86+
fi
8587

86-
export REGTEST_ROOT_BEARER_TOKEN=$token
88+
export REGTEST_ROOT_BEARER_TOKEN=$token
89+
fi
8790

8891
echo "Root bearer token: ${REGTEST_ROOT_BEARER_TOKEN}"
8992

regtests/t_pyspark/src/conftest.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import codecs
2121
import os
22+
import uuid
2223
from typing import List
2324

2425
import pytest
@@ -39,15 +40,33 @@ def polaris_host():
3940
def polaris_port():
4041
return int(os.getenv('POLARIS_PORT', '8181'))
4142

43+
@pytest.fixture
44+
def polaris_path_prefix():
45+
"""
46+
Used to provide a path prefix between the port number and the standard polaris endpoint paths.
47+
No leading or trailing /
48+
:return:
49+
"""
50+
return os.getenv('POLARIS_PATH_PREFIX', '')
4251

4352
@pytest.fixture
44-
def polaris_url(polaris_host, polaris_port):
45-
return f"http://{polaris_host}:{polaris_port}/api/management/v1"
53+
def polaris_url_scheme():
54+
"""
55+
The URL Schema - either http or https - no : or trailing /
56+
:return:
57+
"""
58+
return os.getenv('POLARIS_URL_SCHEME', 'http')
59+
60+
@pytest.fixture
61+
def polaris_url(polaris_url_scheme, polaris_host, polaris_port, polaris_path_prefix):
62+
polaris_path_prefix = polaris_path_prefix if len(polaris_path_prefix) == 0 else '/' + polaris_path_prefix
63+
return f"{polaris_url_scheme}://{polaris_host}:{polaris_port}{polaris_path_prefix}/api/management/v1"
4664

4765

4866
@pytest.fixture
49-
def polaris_catalog_url(polaris_host, polaris_port):
50-
return f"http://{polaris_host}:{polaris_port}/api/catalog"
67+
def polaris_catalog_url(polaris_url_scheme, polaris_host, polaris_port, polaris_path_prefix):
68+
polaris_path_prefix = polaris_path_prefix if len(polaris_path_prefix) == 0 else '/' + polaris_path_prefix
69+
return f"{polaris_url_scheme}://{polaris_host}:{polaris_port}{polaris_path_prefix}/api/catalog"
5170

5271
@pytest.fixture
5372
def test_bucket():
@@ -57,6 +76,16 @@ def test_bucket():
5776
def aws_role_arn():
5877
return os.getenv('AWS_ROLE_ARN')
5978

79+
@pytest.fixture
80+
def aws_bucket_base_location_prefix():
81+
"""
82+
:return: Base location prefix for tests, excluding leading and trailing '/'
83+
Provides a default if null or empty
84+
"""
85+
default_val = 'polaris_test'
86+
bucket_prefix = os.getenv('AWS_BUCKET_BASE_LOCATION_PREFIX', default_val)
87+
return default_val if bucket_prefix == '' else bucket_prefix
88+
6089
@pytest.fixture
6190
def catalog_client(polaris_catalog_url):
6291
"""
@@ -72,13 +101,13 @@ def catalog_client(polaris_catalog_url):
72101

73102

74103
@pytest.fixture
75-
def snowflake_catalog(root_client, catalog_client, test_bucket, aws_role_arn):
104+
def snowflake_catalog(root_client, catalog_client, test_bucket, aws_role_arn, aws_bucket_base_location_prefix):
76105
storage_conf = AwsStorageConfigInfo(storage_type="S3",
77-
allowed_locations=[f"s3://{test_bucket}/polaris_test/"],
106+
allowed_locations=[f"s3://{test_bucket}/{aws_bucket_base_location_prefix}/"],
78107
role_arn=aws_role_arn)
79-
catalog_name = 'snowflake'
108+
catalog_name = f'snowflake_{str(uuid.uuid4())[-10:]}'
80109
catalog = Catalog(name=catalog_name, type='INTERNAL', properties={
81-
"default-base-location": f"s3://{test_bucket}/polaris_test/snowflake_catalog",
110+
"default-base-location": f"s3://{test_bucket}/{aws_bucket_base_location_prefix}/snowflake_catalog",
82111
"client.credentials-provider": "software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider"
83112
},
84113
storage_config_info=storage_conf)

0 commit comments

Comments
 (0)