Files
impala/tests/custom_cluster/test_logging.py
Riza Suminto 28cff4022d IMPALA-14333: Run impala-py.test using Python3
Running exhaustive tests with env var IMPALA_USE_PYTHON3_TESTS=true
reveals some tests that require adjustment. This patch made such
adjustment, which mostly revolves around encoding differences and string
vs bytes type in Python3. This patch also switch the default to run
pytest with Python3 by setting IMPALA_USE_PYTHON3_TESTS=true. The
following are the details:

Change hash() function in conftest.py to crc32() to produce
deterministic hash. Hash randomization is enabled by default since
Python 3.3 (see
https://docs.python.org/3/reference/datamodel.html#object.__hash__).
This cause test sharding (like --shard_tests=1/2) produce inconsistent
set of tests per shard. Always restart minicluster during custom cluster
tests if --shard_tests argument is set, because test order may change
and affect test correctness, depending on whether running on fresh
minicluster or not.

Moved one test case from delimited-latin-text.test to
test_delimited_text.py for easier binary comparison.

Add bytes_to_str() as a utility function to decode bytes in Python3.
This is often needed when inspecting the return value of
subprocess.check_output() as a string.

Implement DataTypeMetaclass.__lt__ to substitute
DataTypeMetaclass.__cmp__ that is ignored in Python3 (see
https://peps.python.org/pep-0207/).

Fix WEB_CERT_ERR difference in test_ipv6.py.

Fix trivial integer parsing in test_restart_services.py.

Fix various encoding issues in test_saml2_sso.py,
test_shell_commandline.py, and test_shell_interactive.py.

Change timeout in Impala.for_each_impalad() from sys.maxsize to 2^31-1.

Switch to binary comparison in test_iceberg.py where needed.

Specify text mode when calling tempfile.NamedTemporaryFile().

Simplify create_impala_shell_executable_dimension to skip testing dev
and python2 impala-shell when IMPALA_USE_PYTHON3_TESTS=true. The reason
is that several UTF-8 related tests in test_shell_commandline.py break
in Python3 pytest + Python2 impala-shell combo. This skipping already
happen automatically in build OS without system Python2 available like
RHEL9 (IMPALA_SYSTEM_PYTHON2 env var is empty).

Removed unused vector argument and fixed some trivial flake8 issues.

Several test logic require modification due to intermittent issue in
Python3 pytest. These include:

Add _run_query_with_client() in test_ranger.py to allow reusing a single
Impala client for running several queries. Ensure clients are closed
when the test is done. Mark several tests in test_ranger.py with

SkipIfFS.hive because they run queries through beeline + HiveServer2,
but Ozone and S3 build environment does not start HiveServer2 by
default.

Increase the sleep period from 0.1 to 0.5 seconds per iteration in
test_statestore.py and mark TestStatestore to execute serially. This is
because TServer appears to shut down more slowly when run concurrently
with other tests. Handle the deprecation of Thread.setDaemon() as well.

Always force_restart=True each test method in TestLoggingCore,
TestShellInteractiveReconnect, and TestQueryRetries to prevent them from
reusing minicluster from previous test method. Some of these tests
destruct minicluster (kill impalad) and will produce minidump if metrics
verifier for next tests fail to detect healthy minicluster state.

Testing:
Pass exhaustive tests with IMPALA_USE_PYTHON3_TESTS=true.

Change-Id: I401a93b6cc7bcd17f41d24e7a310e0c882a550d4
Reviewed-on: http://gerrit.cloudera.org:8080/23319
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2025-09-03 10:01:29 +00:00

112 lines
4.5 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 logging
import time
import pytest
import os
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
LOG = logging.getLogger(__name__)
class TestLoggingCore(CustomClusterTestSuite):
"""Test existence of certain log lines under some scenario."""
def _test_max_errors(self, max_error_logs_per_instance, max_errors, expect_downgraded):
"""Test that number of non-fatal error printed to INFO log is limited by
max_errors and max_error_logs_per_instance."""
query = ("select id, bool_col, tinyint_col, smallint_col "
"from functional.alltypeserror order by id")
client = self.create_impala_client()
self.execute_query_expect_success(client, query, {'max_errors': max_errors})
self.assert_impalad_log_contains("INFO", "Error parsing row",
max_error_logs_per_instance if expect_downgraded else 8)
self.assert_impalad_log_contains("INFO",
"printed {0} non-fatal error to log level 1".format(max_error_logs_per_instance),
1 if expect_downgraded else 0)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(cluster_size=1,
impalad_args="--max_error_logs_per_instance=2",
disable_log_buffering=True,
force_restart=True)
def test_max_errors(self):
self._test_max_errors(2, 4, True)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(cluster_size=1,
impalad_args="--max_error_logs_per_instance=3",
disable_log_buffering=True,
force_restart=True)
def test_max_errors_0(self):
self._test_max_errors(3, 0, True)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(cluster_size=1,
impalad_args="--max_error_logs_per_instance=2",
disable_log_buffering=True,
force_restart=True)
def test_max_errors_no_downgrade(self):
self._test_max_errors(2, -1, False)
class TestLogFlushPermissionDenied(CustomClusterTestSuite):
"""Test logging of failures to open log files with cause Permission denied."""
LOG_FLUSH_FAILURES_DIR = "log_flush_failures_dir"
def setup_method(self, method):
# Override parent
super(TestLogFlushPermissionDenied, self).setup_method(method)
tmp_dir = self.get_tmp_dir(self.LOG_FLUSH_FAILURES_DIR)
self.orig_permissions = os.stat(tmp_dir).st_mode
os.chmod(tmp_dir, 0)
def teardown_method(self, method):
# Override parent
os.chmod(self.get_tmp_dir(self.LOG_FLUSH_FAILURES_DIR), self.orig_permissions)
super(TestLogFlushPermissionDenied, self).teardown_method(method)
def __test_permission_denied(self, log_dir):
self.assert_impalad_log_contains("INFO",
r"Could not open log file: {0}.*, cause: Permission denied".format(log_dir), 2)
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
impalad_args="--lineage_event_log_dir={" + LOG_FLUSH_FAILURES_DIR + "}",
tmp_dir_placeholders=[LOG_FLUSH_FAILURES_DIR])
def test_lineage_log_failure(self):
self.__test_permission_denied(self.get_tmp_dir(self.LOG_FLUSH_FAILURES_DIR))
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
impalad_args="--audit_event_log_dir={" + LOG_FLUSH_FAILURES_DIR + "}",
tmp_dir_placeholders=[LOG_FLUSH_FAILURES_DIR])
def test_audit_log_failure(self):
self.__test_permission_denied(self.get_tmp_dir(self.LOG_FLUSH_FAILURES_DIR))
@pytest.mark.execute_serially
@CustomClusterTestSuite.with_args(
impalad_args="--profile_log_dir={" + LOG_FLUSH_FAILURES_DIR + "}",
tmp_dir_placeholders=[LOG_FLUSH_FAILURES_DIR])
def test_profiles_failure(self):
time.sleep(5)
self.__test_permission_denied(self.get_tmp_dir(self.LOG_FLUSH_FAILURES_DIR))