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

SNOW-1786584 update test setup #2103

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ jobs:
env:
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
run: |
mkdir -p ~/.snowflake
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" \
.github/workflows/parameters/public/parameters_${{ matrix.cloud-provider }}.py.gpg > test/parameters.py
.github/workflows/connections/connections_${{ matrix.cloud-provider }}.toml.gpg > ~/.snowflake/connections.toml
chmod 0600 "/home/runner/.snowflake/connections.toml" || true
- name: Download wheel(s)
uses: actions/download-artifact@v4
with:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/snowflake/connector/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def read_config(
continue

if (
sliceoptions.check_permissions # Skip checking if this file couldn't hold sensitive information
sliceoptions.check_permissions # Skip checking if this slice isn't holding sensitive information
# Same check as openssh does for permissions
# https://github.com/openssh/openssh-portable/blob/2709809fd616a0991dc18e3a58dea10fb383c3f0/readconf.c#LL2264C1-L2264C1
and filep.stat().st_mode & READABLE_BY_OTHERS != 0
Expand Down
13 changes: 6 additions & 7 deletions src/snowflake/connector/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,12 @@ def cmd_query(
data["queryContextDTO"] = queryContext
client = "sfsql_file_transfer" if is_file_transfer else "sfsql"

if logger.getEffectiveLevel() <= logging.DEBUG:
logger.debug(
"sql=[%s], sequence_id=[%s], is_file_transfer=[%s]",
self._format_query_for_log(data["sqlText"]),
data["sequenceId"],
is_file_transfer,
)
logger.debug(
"sql=[%s], sequence_id=[%s], is_file_transfer=[%s]",
self._format_query_for_log(data["sqlText"]),
data["sequenceId"],
is_file_transfer,
)

url_parameters = {REQUEST_ID: request_id}

Expand Down
4 changes: 1 addition & 3 deletions test/extras/simple_select1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from snowflake.connector import connect

from ..parameters import CONNECTION_PARAMETERS

with connect(**CONNECTION_PARAMETERS) as conn:
with connect() as conn:
with conn.cursor() as cur:
assert cur.execute("select 1;").fetchall() == [
(1,),
Expand Down
90 changes: 56 additions & 34 deletions test/integ/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
from snowflake.connector.connection import DefaultConverterClass

from .. import running_on_public_ci
from ..parameters import CONNECTION_PARAMETERS

try:
from snowflake.connector.config_manager import CONFIG_MANAGER
except ImportError:
CONFIG_MANAGER = None

try:
from ..parameters import CONNECTION_PARAMETERS
except ImportError:
CONNECTION_PARAMETERS: dict[str, Any] = {} # type: ignore


try:
from ..parameters import CLIENT_FAILOVER_PARAMETERS # type: ignore
Expand All @@ -34,9 +44,11 @@
RUNNING_ON_GH = os.getenv("GITHUB_ACTIONS") == "true"
TEST_USING_VENDORED_ARROW = os.getenv("TEST_USING_VENDORED_ARROW") == "true"

if not isinstance(CONNECTION_PARAMETERS["host"], str):
if CONNECTION_PARAMETERS and not isinstance(CONNECTION_PARAMETERS.get("host"), str):
raise Exception("default host is not a string in parameters.py")
RUNNING_AGAINST_LOCAL_SNOWFLAKE = CONNECTION_PARAMETERS["host"].endswith("local")
RUNNING_AGAINST_LOCAL_SNOWFLAKE = CONNECTION_PARAMETERS.get("host", "").endswith(
"local"
)

try:
from ..parameters import CONNECTION_PARAMETERS_ADMIN # type: ignore
Expand Down Expand Up @@ -110,30 +122,46 @@ def get_db_parameters(connection_name: str = "default") -> dict[str, Any]:
os.environ["TZ"] = "UTC"
if not IS_WINDOWS:
time.tzset()

connections = {
"default": CONNECTION_PARAMETERS,
"client_failover": CLIENT_FAILOVER_PARAMETERS,
"admin": CONNECTION_PARAMETERS_ADMIN,
}

chosen_connection = connections[connection_name]
if "account" not in chosen_connection:
pytest.skip(f"{connection_name} connection is unavailable in parameters.py")

# testaccount connection info
ret = {**DEFAULT_PARAMETERS, **chosen_connection}

# snowflake admin account. Not available in GH actions
for k, v in CONNECTION_PARAMETERS_ADMIN.items():
ret["sf_" + k] = v

if "host" in ret and ret["host"] == DEFAULT_PARAMETERS["host"]:
ret["host"] = ret["account"] + ".snowflakecomputing.com"

if "account" in ret and ret["account"] == DEFAULT_PARAMETERS["account"]:
print_help()
sys.exit(2)
if (
CONFIG_MANAGER is not None
and (
CONFIG_MANAGER["default_connection_name"]
if connection_name == "default"
else connection_name
)
in CONFIG_MANAGER["connections"]
):
# If config_manager knows of this connection then use it
ret = CONFIG_MANAGER["connections"][
(
CONFIG_MANAGER["default_connection_name"]
if connection_name == "default"
else connection_name
)
].value.value
else:
connections = {
"default": CONNECTION_PARAMETERS,
"failover": CLIENT_FAILOVER_PARAMETERS,
"admin": CONNECTION_PARAMETERS_ADMIN,
}

chosen_connection = connections[connection_name]
if "account" not in chosen_connection:
pytest.skip(f"{connection_name} connection is unavailable in parameters.py")

# testaccount connection info
ret = {**DEFAULT_PARAMETERS, **chosen_connection}
# snowflake admin account. Not available in GH actions
for k, v in CONNECTION_PARAMETERS_ADMIN.items():
ret["sf_" + k] = v

if "host" in ret and ret["host"] == DEFAULT_PARAMETERS["host"]:
ret["host"] = ret["account"] + ".snowflakecomputing.com"

if "account" in ret and ret["account"] == DEFAULT_PARAMETERS["account"]:
print_help()
sys.exit(2)

# a unique table name
ret["name"] = "python_tests_" + str(uuid.uuid4()).replace("-", "_")
Expand Down Expand Up @@ -170,13 +198,7 @@ def init_test_schema(db_parameters) -> Generator[None, None, None]:
"""
ret = db_parameters
with snowflake.connector.connect(
user=ret["user"],
password=ret["password"],
host=ret["host"],
port=ret["port"],
database=ret["database"],
account=ret["account"],
protocol=ret["protocol"],
**ret,
) as con:
con.cursor().execute(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA}")
yield
Expand Down
53 changes: 20 additions & 33 deletions test/integ/test_autocommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

from __future__ import annotations

import snowflake.connector
import uuid


def exe0(cnx, sql):
return cnx.cursor().execute(sql)


def _run_autocommit_off(cnx, db_parameters):
def _run_autocommit_off(cnx, name):
"""Runs autocommit off test.

Args:
Expand All @@ -21,7 +21,7 @@ def _run_autocommit_off(cnx, db_parameters):
"""

def exe(cnx, sql):
return cnx.cursor().execute(sql.format(name=db_parameters["name"]))
return cnx.cursor().execute(sql.format(name=name))

exe(
cnx,
Expand Down Expand Up @@ -89,7 +89,7 @@ def exe(cnx, sql):
assert res[0] == 2


def _run_autocommit_on(cnx, db_parameters):
def _run_autocommit_on(cnx, name):
"""Run autocommit on test.

Args:
Expand All @@ -98,7 +98,7 @@ def _run_autocommit_on(cnx, db_parameters):
"""

def exe(cnx, sql):
return cnx.cursor().execute(sql.format(name=db_parameters["name"]))
return cnx.cursor().execute(sql.format(name=name))

exe(
cnx,
Expand All @@ -116,16 +116,18 @@ def exe(cnx, sql):
assert res[0] == 4


def test_autocommit_attribute(conn_cnx, db_parameters):
def test_autocommit_attribute(conn_cnx):
"""Tests autocommit attribute.

Args:
conn_cnx: The database connection context.
db_parameters: Database parameters.
"""

name = "python_tests_" + str(uuid.uuid4()).replace("-", "_")

def exe(cnx, sql):
return cnx.cursor().execute(sql.format(name=db_parameters["name"]))
return cnx.cursor().execute(sql.format(name=name))

with conn_cnx() as cnx:
exe(
Expand All @@ -136,9 +138,9 @@ def exe(cnx, sql):
)
try:
cnx.autocommit(False)
_run_autocommit_off(cnx, db_parameters)
_run_autocommit_off(cnx, name)
cnx.autocommit(True)
_run_autocommit_on(cnx, db_parameters)
_run_autocommit_on(cnx, name)
finally:
exe(
cnx,
Expand All @@ -148,25 +150,18 @@ def exe(cnx, sql):
)


def test_autocommit_parameters(db_parameters):
def test_autocommit_parameters(conn_cnx):
"""Tests autocommit parameter.

Args:
db_parameters: Database parameters.
"""
name = "python_tests_" + str(uuid.uuid4()).replace("-", "_")

def exe(cnx, sql):
return cnx.cursor().execute(sql.format(name=db_parameters["name"]))

with snowflake.connector.connect(
user=db_parameters["user"],
password=db_parameters["password"],
host=db_parameters["host"],
port=db_parameters["port"],
account=db_parameters["account"],
protocol=db_parameters["protocol"],
schema=db_parameters["schema"],
database=db_parameters["database"],
return cnx.cursor().execute(sql.format(name=name))

with conn_cnx(
autocommit=False,
) as cnx:
exe(
Expand All @@ -175,20 +170,12 @@ def exe(cnx, sql):
CREATE TABLE {name} (c1 boolean)
""",
)
_run_autocommit_off(cnx, db_parameters)

with snowflake.connector.connect(
user=db_parameters["user"],
password=db_parameters["password"],
host=db_parameters["host"],
port=db_parameters["port"],
account=db_parameters["account"],
protocol=db_parameters["protocol"],
schema=db_parameters["schema"],
database=db_parameters["database"],
_run_autocommit_off(cnx, name)

with conn_cnx(
autocommit=True,
) as cnx:
_run_autocommit_on(cnx, db_parameters)
_run_autocommit_on(cnx, name)
exe(
cnx,
"""
Expand Down
Loading
Loading