Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and adds configurability to test_spark_sql_s3_with_privileges.py regtest #1060

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions regtests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ NUM_SUCCESSES=0
export AWS_ACCESS_KEY_ID=''
export AWS_SECRET_ACCESS_KEY=''

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

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

if [ "$token" == "unauthorized_client" ]; then
logred "Error: Failed to retrieve bearer token"
exit 1
fi
if [ "$token" == "unauthorized_client" ]; then
logred "Error: Failed to retrieve bearer token"
exit 1
fi

export REGTEST_ROOT_BEARER_TOKEN=$token
export REGTEST_ROOT_BEARER_TOKEN=$token
fi

echo "Root bearer token: ${REGTEST_ROOT_BEARER_TOKEN}"

Expand Down
42 changes: 34 additions & 8 deletions regtests/t_pyspark/src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import codecs
import os
import uuid
from typing import List

import pytest
Expand All @@ -39,15 +40,30 @@ def polaris_host():
def polaris_port():
return int(os.getenv('POLARIS_PORT', '8181'))

@pytest.fixture
def polaris_path_prefix():
"""
Used to provide a path prefix between the port number and the standard polaris endpoint paths
:return:
"""
return os.getenv('POLARIS_PATH_PREFIX', '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is expected to begin with / but to never end with it, while polaris_url_scheme and polaris_host are the opposite?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - you're right - there's some inconsistencies.
Polaris_Host => no leading or trailing /
AWS_Bucket_Prefix = > No leading or trailing /
URL Schema => Updated to not have leading or trailing /
POLARIS_PATH_PREFIX => Now also updated to not have a leading or trailing / (the callsites that use it can determine whether to add those)


@pytest.fixture
def polaris_url(polaris_host, polaris_port):
return f"http://{polaris_host}:{polaris_port}/api/management/v1"
def polaris_url_scheme():
"""
Used to provide a path prefix between the port number and the standard polaris endpoint paths
:return:
"""
return os.getenv('POLARIS_URL_SCHEME', 'http://')

@pytest.fixture
def polaris_url(polaris_url_scheme, polaris_host, polaris_port, polaris_path_prefix):
return f"{polaris_url_scheme}{polaris_host}:{polaris_port}{polaris_path_prefix}/api/management/v1"


@pytest.fixture
def polaris_catalog_url(polaris_host, polaris_port):
return f"http://{polaris_host}:{polaris_port}/api/catalog"
def polaris_catalog_url(polaris_url_scheme, polaris_host, polaris_port, polaris_path_prefix):
return f"{polaris_url_scheme}{polaris_host}:{polaris_port}{polaris_path_prefix}/api/catalog"

@pytest.fixture
def test_bucket():
Expand All @@ -57,6 +73,16 @@ def test_bucket():
def aws_role_arn():
return os.getenv('AWS_ROLE_ARN')

@pytest.fixture
def aws_bucket_base_location_prefix():
"""
:return: Base location prefix for tests, excluding leading and trailing '/'
Provides a default if null or empty
"""
default_val = 'polaris_test'
bucket_prefix = os.getenv('AWS_BUCKET_BASE_LOCATION_PREFIX', default_val)
return default_val if bucket_prefix == '' else bucket_prefix

@pytest.fixture
def catalog_client(polaris_catalog_url):
"""
Expand All @@ -72,13 +98,13 @@ def catalog_client(polaris_catalog_url):


@pytest.fixture
def snowflake_catalog(root_client, catalog_client, test_bucket, aws_role_arn):
def snowflake_catalog(root_client, catalog_client, test_bucket, aws_role_arn, aws_bucket_base_location_prefix):
storage_conf = AwsStorageConfigInfo(storage_type="S3",
allowed_locations=[f"s3://{test_bucket}/polaris_test/"],
allowed_locations=[f"s3://{test_bucket}/{aws_bucket_base_location_prefix}/"],
role_arn=aws_role_arn)
catalog_name = 'snowflake'
catalog_name = f'snowflake_{str(uuid.uuid4())[-10:]}'
catalog = Catalog(name=catalog_name, type='INTERNAL', properties={
"default-base-location": f"s3://{test_bucket}/polaris_test/snowflake_catalog",
"default-base-location": f"s3://{test_bucket}/{aws_bucket_base_location_prefix}/snowflake_catalog",
"client.credentials-provider": "software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider"
},
storage_config_info=storage_conf)
Expand Down
Loading