Sarvesh Tamba created KAFKA-7580: ------------------------------------ Summary: Unit Test 'shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir' fails when run as root user Key: KAFKA-7580 URL: https://issues.apache.org/jira/browse/KAFKA-7580 Project: Kafka Issue Type: Bug Components: unit tests Affects Versions: 2.0.0, 2.0.1, 2.1.0, 2.2.0, 2.1.1, 2.0.2 Environment: Ubuntu 16.04.3 LTS Reporter: Sarvesh Tamba
Created a non-root user and ran the following command to execute the failiing unit test:- ./gradlew streams:unitTest --tests org.apache.kafka.streams.state.internals.RocksDBStoreTest.shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir For a root user, the test case fails:- ===================================== > Task :streams:testClasses UP-TO-DATE > Task :streams:unitTest org.apache.kafka.streams.state.internals.RocksDBStoreTest > shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir FAILED java.lang.AssertionError: Expected exception: org.apache.kafka.streams.errors.ProcessorStateException 1 test completed, 1 failed > Task :streams:unitTest FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':streams:unitTest'. > There were failing tests. See the report at: > file:///root/sarvesh/kafka-gradle/kafka-2.0.0/streams/build/reports/tests/unitTest/index.html * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 20s 26 actionable tasks: 2 executed, 24 up-to-date ===================================== However, for a non-root user the test cass passes as success:- ===================================== > Task :streams:testClasses > Task :streams:unitTest org.apache.kafka.streams.state.internals.RocksDBStoreTest > shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir PASSED BUILD SUCCESSFUL in 45s 26 actionable tasks: 4 executed, 22 up-to-date ===================================== The failing unit test - "shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir" creates a temporary file directory and sets it as readOnly. The unit test is intended to throw an exception - "ProcessorStateException", when the readOnly temporary file directory is opened/accessed. By default, non-root users opening/accessing readOnly file directory is not allowed and it rightly throws up an error/exception in the unit test(which is the intention of the unit test and it passes for non-root users). sar@p006vm18:~/kafka-gradle/kafka-2.0.0$ mkdir /tmp/readOnlyDir/parent mkdir: cannot create directory â/tmp/readOnlyDir/parentâ: Permission denied sar@p006vm18:~/kafka-gradle/kafka-2.0.0$ ll /tmp/readOnlyDir/ ls: cannot access '/tmp/readOnlyDir/..': Permission denied ls: cannot access '/tmp/readOnlyDir/.': Permission denied ls: cannot access '/tmp/readOnlyDir/kid': Permission denied ls: cannot access '/tmp/readOnlyDir/child': Permission denied total 0 d????????? ? ? ? ? ? ./ d????????? ? ? ? ? ? ../ d????????? ? ? ? ? ? child/ d????????? ? ? ? ? ? kid/ However, by default, root user can access any file in the system.:- root@p006vm18:/tmp# ll /tmp/readOnlyDir/ total 112 dr--rw-rw- 4 root root 4096 Nov 1 03:47 ./ drwxrwxrwt 24 root root 98304 Nov 1 04:02 ../ drwxr-xr-x 2 root root 4096 Nov 1 03:44 child/ drwxrwxr-x 2 sar sar 4096 Nov 1 03:47 kid/ root@p006vm18:/tmp# mkdir /tmp/readOnlyDir/parent root@p006vm18:/tmp# ll /tmp/readOnlyDir/ total 116 dr--rw-rw- 5 root root 4096 Nov 1 04:03 ./ drwxrwxrwt 24 root root 98304 Nov 1 04:02 ../ drwxr-xr-x 2 root root 4096 Nov 1 03:44 child/ drwxrwxr-x 2 sar sar 4096 Nov 1 03:47 kid/ drwxr-xr-x 2 root root 4096 Nov 1 04:03 parent/ Hence the unit test does not throw an exception - "ProcessorStateException" when the readOnly temporary file directory is opened, and the unit test rightly fails for a root user. Two approaches for resolving this failing unit test case:- 1.) Run the unit tests as non-root users(simplest). 2.) If running the unit test as root user, make the temporary file directory as immutable in the unit test code and then test for exception(needs code changes in the unit tests):- root@p006vm18:/tmp# chattr +i /tmp/readOnlyDir/ root@p006vm18:/tmp# mkdir /tmp/readOnlyDir/grandparent mkdir: cannot create directory â/tmp/readOnlyDir/grandparentâ: Permission denied A file with an immutable attribute can not be: - Modified - Deleted - Renamed - No soft or hard link created by anyone including root user. -- This message was sent by Atlassian JIRA (v7.6.3#76005)