Files
impala/tests/custom_cluster/test_delegation.py
Joe McDonnell c5a0ec8bdf IMPALA-11980 (part 1): Put all thrift-generated python code into the impala_thrift_gen package
This puts all of the thrift-generated python code into the
impala_thrift_gen package. This is similar to what Impyla
does for its thrift-generated python code, except that it
uses the impala_thrift_gen package rather than impala._thrift_gen.
This is a preparatory patch for fixing the absolute import
issues.

This patches all of the thrift files to add the python namespace.
This has code to apply the patching to the thirdparty thrift
files (hive_metastore.thrift, fb303.thrift) to do the same.

Putting all the generated python into a package makes it easier
to understand where the imports are getting code. When the
subsequent change rearranges the shell code, the thrift generated
code can stay in a separate directory.

This uses isort to sort the imports for the affected Python files
with the provided .isort.cfg file. This also adds an impala-isort
shell script to make it easy to run.

Testing:
 - Ran a core job

Change-Id: Ie2927f22c7257aa38a78084efe5bd76d566493c0
Reviewed-on: http://gerrit.cloudera.org:8080/20169
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Reviewed-by: Riza Suminto <riza.suminto@cloudera.com>
2025-04-15 17:03:02 +00:00

88 lines
4.2 KiB
Python

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import absolute_import, division, print_function
import getpass
import pytest
from impala_thrift_gen.TCLIService import TCLIService
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
from tests.hs2.hs2_test_suite import HS2TestSuite, needs_session
USER_NAME = getpass.getuser()
PROXY_USER = "proxy_user_name"
PROXY_USER_WITH_COMMA = "proxy_user,name_2"
PROXY_USERS_ALL = "proxy_user_name/proxy_user,name_2"
PROXY_USER_DELIMITER = "/"
class TestDelegation(CustomClusterTestSuite, HS2TestSuite):
def check_user_and_effective_user(self, proxy_user):
execute_statement_req = TCLIService.TExecuteStatementReq()
execute_statement_req.sessionHandle = self.session_handle
execute_statement_req.confOverlay = dict()
execute_statement_req.statement = \
"SELECT effective_user(), current_user(), logged_in_user(), user(), session_user()"
execute_statement_resp = self.hs2_client.ExecuteStatement(execute_statement_req)
HS2TestSuite.check_response(execute_statement_resp)
fetch_results_req = TCLIService.TFetchResultsReq()
fetch_results_req.operationHandle = execute_statement_resp.operationHandle
fetch_results_req.maxRows = 1
fetch_results_resp = self.hs2_client.FetchResults(fetch_results_req)
HS2TestSuite.check_response(fetch_results_resp)
assert (self.column_results_to_string(fetch_results_resp.results.columns) ==
(1, "%s, %s, %s, %s, %s\n" % (proxy_user, proxy_user, proxy_user,
USER_NAME, USER_NAME)))
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
"--authorized_proxy_user_config=\"%s=%s\"" % (USER_NAME, PROXY_USER))
@needs_session(TCLIService.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6,
conf_overlay = {"impala.doas.user": PROXY_USER})
def test_effective_user_single_proxy(self):
'''Test that the effective user is correctly set when impala.doas.user is correct, and
that the effective_user() builtin returns the right thing'''
self.check_user_and_effective_user(PROXY_USER)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
"--authorized_proxy_user_config=\"%s=%s\"\
--authorized_proxy_user_config_delimiter=%c" % (USER_NAME, PROXY_USERS_ALL,
PROXY_USER_DELIMITER))
@needs_session(TCLIService.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6,
conf_overlay = {"impala.doas.user": PROXY_USER_WITH_COMMA})
def test_effective_user_multiple_proxies(self):
'''Test that the effective user is correctly set when there are multiple proxy users
seperated with the authorized_user_proxy_config_delimiter and when impala.doas.user
is correct, and that the effective_user() builtin returns the right thing'''
self.check_user_and_effective_user(PROXY_USER_WITH_COMMA)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
"--authorized_proxy_user_config=\"%s=%s\"\
--authorized_proxy_user_config_delimiter=" % (USER_NAME, PROXY_USER_WITH_COMMA))
@needs_session(TCLIService.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6,
conf_overlay = {"impala.doas.user": PROXY_USER_WITH_COMMA})
def test_effective_user_empty_delimiter(self):
'''Test that the effective user is correctly set when the
authorized_user_proxy_config_delimiter is set to the empty string and
impala.doas.user is correct, and that the effective_user() builtin returns the
right thing'''
self.check_user_and_effective_user(PROXY_USER_WITH_COMMA)