Esempio n. 1
0
def cleanup_generated_core_dumps(request):
    """
  A fixture to cleanup core dumps intentionally generated by tests (for negative testing).

  Only core dumps generated by the decorated test function will be removed. Pre-existing
  cores that need to be triaged from prior test failures are retained.
  """
    possible_cores = find_all_files('*core*')
    pre_test_cores = set([f for f in possible_cores if is_core_dump(f)])

    yield  # Wait for test to execute

    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 - pre_test_cores):
        LOG.info("Cleaned up {core} created by {test}".format(
            core=f, test=request.node.name))
        os.remove(f)
    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()