tree: c43e668bcd1330796034994239fdbbf619b52ff2
  1. hdfs/
  2. kms/
  3. rolerest/
  4. xuserrest/
  5. pytest.ini
  6. readme.md
  7. requirements.txt
  8. run-tests.sh
functional-tests/readme.md

Pytest Functional Test Suite

This test suite validates REST API endpoints for Apache Ranger services,Admin (rolerest, xuserrest, servicerest), KMS (Key Management Service), and tests HDFS encryption functionalities including key management and file operations within encryption zones.

Available Test Suites

SuiteDescription
hdfsTest cases for HDFS encryption lifecycle using KMS
kmsTest cases for KMS REST API functionality
xuserrestTest cases for Ranger Admin User/Group REST APIs
rolerestTest cases for Ranger Admin Role REST APIs
servicerestTest cases for Ranger Admin Service REST APIs

Directory Structure

functional-tests/
├── hdfs/                        # Tests on HDFS encryption cycle
├── kms/                         # Tests on KMS REST API
├── xuserrest/                   # Tests on Ranger User/Group/Role REST APIs
├── rolerest/                    # Tests on Ranger Role REST APIs
├── servicerest/                 # Tests on Ranger Service REST APIs

├── pytest.ini                   # Registers custom pytest markers
├── run-tests.sh                 # Script to automate setup and test execution
├── requirements.txt             # Python dependencies
└── readme.md                    # This documentation

Note: A Python virtual environment folder named myenv will be automatically generated upon running the tests for the first time.

Prerequisites

  1. Docker & Docker Compose installed and running
  2. Python 3.10 or higher
  3. Change the working directory to functional-tests
cd functional-tests/
  1. Make the shell script executable
chmod +x run-tests.sh

Environment Variables

Configure container behavior before running the script using the following environment variables:

  1. Fresh Setup & Cleanup:

Force a clean environment & helps building binaries with local changes:

export CLEAN_CONTAINERS=1
./run-tests.sh

After initial setup, disable fresh container creation to speed up subsequent runs (default behavior):

export CLEAN_CONTAINERS=0
./run-tests.sh
  1. Infrastructure Only (Skip Tests)

Start Docker infrastructure without executing Pytest suites:

export RUN_TESTS=0
./run-tests.sh

This is useful when tests fail due to slow container startup. Once all containers are healthy, re-enable tests (default behavior):

export RUN_TESTS=1
./run-tests.sh

Running Tests

The run-tests.sh script manages Docker container setup, dependency installation, and test execution. It supports both interactive and argument-based modes.

  1. Interactive Mode:

Run the script without arguments to be prompted for inputs:

./run-tests.sh

DB Type: Enter one of postgres, mysql, oracle, mssql. Defaults to postgres.

Test Suites: Enter space-separated suite names. Defaults to ALL suites.

example:


Available DB types: postgres, mysql, oracle Enter DB type (press Enter to default to postgres): postgres Available test suites: xuserrest servicerest hdfs kms Enter test suites space-separated (press Enter to run ALL): kms hdfs
  1. Command-Line Arguments Mode:

Pass arguments directly to skip prompts:

./run-tests.sh [db-type] [test-suites...]

db-type — Must be the first argument. Valid values: postgres, mysql, oracle.

test-suites — Space-separated list: hdfs, kms, xuserrest, servicerest.

Examples:

./run-tests.sh postgres kms hdfs

Test Reports

After execution, HTML reports are automatically generated for each suite. Open the corresponding file in any browser to view detailed results:

SuiteReport File
hdfsreport_hdfs.html
kmsreport_kms.html
xuserrestreport_xuserrest.html
rolerestreport_rolerest.html
servicerestreport_servicerest.html