mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
There are many custom cluster tests that require creating temporary directory. The temporary directory typically live within a scope of test method and cleaned afterwards. However, some test do create temporary directory directly and forgot to clean them afterwards, leaving junk dirs under /tmp/ or $LOG_DIR. This patch unify the temporary directory management inside CustomClusterTestSuite. It introduce new 'tmp_dir_placeholders' arg in CustomClusterTestSuite.with_args() that list tmp dirs to create. 'impalad_args', 'catalogd_args', and 'impala_log_dir' now accept formatting pattern that is replaceable by a temporary dir path, defined through 'tmp_dir_placeholders'. There are few occurrences where mkdtemp is called and not replaceable by this work, such as tests/comparison/cluster.py. In that case, this patch change them to supply prefix arg so that developer knows that it comes from Impala test script. This patch also addressed several flake8 errors in modified files. Testing: - Pass custom cluster tests in exhaustive mode. - Manually run few modified tests and observe that the temporary dirs are created and removed under logs/custom_cluster_tests/ as the tests go. Change-Id: I8dd665e8028b3f03e5e33d572c5e188f85c3bdf5 Reviewed-on: http://gerrit.cloudera.org:8080/21836 Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
142 lines
5.7 KiB
Python
142 lines
5.7 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.
|
|
#
|
|
# Tests for the behavior of startup_filesystem_check_directories
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
import logging
|
|
import pytest
|
|
import os
|
|
|
|
from impala_py_lib.helpers import find_all_files, is_core_dump
|
|
from tests.common.file_utils import assert_file_in_dir_contains
|
|
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
|
|
from tests.util.filesystem_utils import get_fs_path
|
|
|
|
LOG = logging.getLogger('test_startup_filesystem_checks')
|
|
|
|
|
|
class TestStartupFilesystemChecks(CustomClusterTestSuite):
|
|
"""
|
|
Tests for the behavior of startup_filesystem_check_directories.
|
|
|
|
All test cases in this testsuite
|
|
are expected to fail cluster startup and will swallow exceptions thrown during
|
|
setup_method().
|
|
"""
|
|
|
|
# Use get_fs_path because testdata in Ozone requires a volume prefix and does not
|
|
# accept underscore as a bucket name (the first element after volume prefix).
|
|
NONEXISTENT_PATH = get_fs_path("/nonexistent-path")
|
|
NONDIRECTORY_PATH = \
|
|
get_fs_path("/test-warehouse/alltypes/year=2009/month=1/090101.txt")
|
|
VALID_SUBDIRECTORY = get_fs_path("/test-warehouse")
|
|
# Test multiple valid directories along with an empty entry
|
|
MULTIPLE_VALID_DIRECTORIES = ",".join([
|
|
"/",
|
|
get_fs_path("/test-warehouse/zipcode_incomes"),
|
|
"",
|
|
get_fs_path("/test-warehouse/alltypes")]
|
|
)
|
|
LOG_DIR = "startup_filesystem_checks"
|
|
MINIDUMP_PATH = "minidump_path"
|
|
LOG_DIR_PLACEHOLDER = "{" + LOG_DIR + "}"
|
|
MINIDUMP_PLACEHOLDER = "--minidump_path={" + MINIDUMP_PATH + "}"
|
|
|
|
IMPALAD_ARGS = "--startup_filesystem_check_directories={0} "
|
|
|
|
pre_test_cores = None
|
|
|
|
def get_log_dir(self):
|
|
return self.get_tmp_dir(self.LOG_DIR)
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(
|
|
impala_log_dir=LOG_DIR_PLACEHOLDER,
|
|
impalad_args=IMPALAD_ARGS.format(NONEXISTENT_PATH) + MINIDUMP_PLACEHOLDER,
|
|
tmp_dir_placeholders=[LOG_DIR, MINIDUMP_PATH])
|
|
def test_nonexistent_path(self):
|
|
# parse log file for expected exception
|
|
assert_file_in_dir_contains(self.get_log_dir(),
|
|
("Invalid path specified for startup_filesystem_check_directories: "
|
|
"{0} does not exist.").format(self.NONEXISTENT_PATH))
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(
|
|
impala_log_dir=LOG_DIR_PLACEHOLDER,
|
|
impalad_args=IMPALAD_ARGS.format(NONDIRECTORY_PATH) + MINIDUMP_PLACEHOLDER,
|
|
tmp_dir_placeholders=[LOG_DIR, MINIDUMP_PATH])
|
|
def test_nondirectory_path(self):
|
|
# parse log file for expected exception
|
|
assert_file_in_dir_contains(self.get_log_dir(),
|
|
("Invalid path specified for startup_filesystem_check_directories: "
|
|
"{0} is not a directory.").format(self.NONDIRECTORY_PATH))
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(
|
|
impala_log_dir=LOG_DIR_PLACEHOLDER,
|
|
impalad_args=IMPALAD_ARGS.format(VALID_SUBDIRECTORY) + MINIDUMP_PLACEHOLDER,
|
|
tmp_dir_placeholders=[LOG_DIR, MINIDUMP_PATH])
|
|
def test_valid_subdirectory(self):
|
|
# parse log file for expected log message showing success
|
|
assert_file_in_dir_contains(self.get_log_dir(),
|
|
"Successfully listed {0}".format(self.VALID_SUBDIRECTORY))
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(
|
|
impala_log_dir=LOG_DIR_PLACEHOLDER,
|
|
impalad_args=IMPALAD_ARGS.format(MULTIPLE_VALID_DIRECTORIES) + MINIDUMP_PLACEHOLDER,
|
|
tmp_dir_placeholders=[LOG_DIR, MINIDUMP_PATH])
|
|
def test_multiple_valid_dirs(self):
|
|
valid_directories = self.MULTIPLE_VALID_DIRECTORIES.split(",")
|
|
for valid_dir in valid_directories:
|
|
if len(valid_dir) == 0:
|
|
continue
|
|
# parse log file for expected log message showing success
|
|
assert_file_in_dir_contains(self.get_log_dir(),
|
|
"Successfully listed {0}".format(valid_dir))
|
|
|
|
def setup_method(self, method):
|
|
# Make a note of any core files that already exist
|
|
possible_cores = find_all_files('*core*')
|
|
self.pre_test_cores = set([f for f in possible_cores if is_core_dump(f)])
|
|
|
|
# Explicitly override CustomClusterTestSuite.setup_method() to
|
|
# allow it to exception, since this testsuite is for cases where
|
|
# startup fails
|
|
try:
|
|
super(TestStartupFilesystemChecks, self).setup_method(method)
|
|
except Exception:
|
|
self._stop_impala_cluster()
|
|
|
|
def teardown_method(self, method):
|
|
try:
|
|
# The core dumps expected to be generated by this test should be cleaned up
|
|
possible_cores = find_all_files('*core*')
|
|
post_test_cores = set([f for f in possible_cores if is_core_dump(f)])
|
|
|
|
for f in (post_test_cores - self.pre_test_cores):
|
|
LOG.info("Cleaned up {core} created by tests".format(core=f))
|
|
os.remove(f)
|
|
|
|
# Explicitly override CustomClusterTestSuite.teardown_method() to
|
|
# allow it to exception, since it relies on setup_method() having
|
|
# completed successfully
|
|
super(TestStartupFilesystemChecks, self).teardown_method(method)
|
|
except Exception:
|
|
self._stop_impala_cluster()
|