tree: 5804a511f74ff8fd047170b1088abad512512107 [search]
  1. api/
  2. api_tests/
  3. hbase/
  4. hdfs/
  5. hive/
  6. kafka/
  7. kms/
  8. ranger_test_utils/
  9. rolerest/
  10. servicerest/
  11. tagrest/
  12. xuserrest/
  13. .gitignore
  14. conftest.py
  15. pytest.ini
  16. readme.md
  17. requirements.txt
  18. run-tests.sh
functional-tests/readme.md

Pytest Functional Test Suite

A Docker-based test execution framework that validates Apache Ranger service integrations through pytest. Spins up the required containers, runs the test suites, and tears down — all from a single script. New service modules can be added as pytest folders without changing the script.

Available Test Suites

SuiteDescription
hdfsHDFS encryption lifecycle (KMS) and Ranger HDFS plugin path policies (hdfs_policy marker)
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
tagrestTest cases for Ranger Admin Tag REST APIs
apiPublic API v2 service and policy CRUD (admin Docker only)
api_testsPublic API v2 user REST calls by role: admin, keyadmin, auditor, user role, and negative cases (admin Docker only)
hiveHive Ranger plugin enforcement via HS2/beeline (requires ranger-hadoop + ranger-hive)
hbaseHBase Ranger plugin enforcement via HBase shell (requires ranger-hadoop + ranger-hbase)
kafkaKafka Ranger plugin enforcement via console producer (requires ranger-kafka)

Directory Structure

functional-tests/
├── <component> test modules     # i.e hive,hdfs,kms etc
├── REST API modules             # xuserrest,servicerest,api,tagrest etc
|
├── pytest.ini                   # Registers custom pytest markers
├── run-tests.sh                 # Script to automate setup and test execution
├── requirements.txt             # Python dependencies
└── readme.md                    # This documentation
├── ranger_test_utils/utils.py   # Shared logging, HTTP asserts, Public API v2 helpers
├── ranger_test_utils/<service>_utils.py
├── ranger_test_utils/access_audit_utils.py  # For future access-audit asserts

Note: A Python virtual environment folder named myenv is created automatically on the first run and reused on all subsequent runs — no reinstallation overhead.


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

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 (Preferred)

Run the script without arguments to be prompted for each input:

./run-tests.sh

You will be asked four questions in sequence:

Available DB types: postgres, mysql, oracle
Enter DB type (press Enter to default to postgres): postgres

Available audit stores: opensearch, solr, none
Enter audit store (press Enter to default to opensearch): opensearch

Available test suites: rolerest xuserrest servicerest tagrest hdfs kms api hive ...
Enter test suites space-separated (press Enter to run ALL): hdfs kms

Available containers : hadoop hive hbase knox trino ozone kafka
  (base always starts: ranger, kdc, db, zk, kms, pdp, usersync, tagsync + audit pipeline)
Enter containers space-separated (press Enter or 'all' for ALL): hadoop

Press Enter at any prompt to accept the default. Type all at the containers prompt to bring up every optional container.

2. Command-Line Arguments Mode

Pass db-type and test-suites as arguments to skip those prompts. Use env vars for the remaining options:

./run-tests.sh [db-type] [test-suites...]
  • db-type — First positional argument. Valid values: postgres, mysql, oracle.
  • test-suites — Remaining arguments, space-separated.

The containers prompt always appears unless SELECTED_CONTAINERS is exported.

Examples:

# Run hdfs suite (encryption + hdfs_policy tests) — requires ranger-hadoop
export AUDIT_INDEX_STORE=none
export SELECTED_CONTAINERS=hadoop
./run-tests.sh postgres hdfs

# Run hdfs and kms tests — postgres db, no audit pipeline, hadoop container only
export AUDIT_INDEX_STORE=none
export SELECTED_CONTAINERS=hadoop
./run-tests.sh postgres hdfs kms

# Run all test suites — mysql db, opensearch audit, all optional containers
export SELECTED_CONTAINERS=all
./run-tests.sh mysql

# Full clean rebuild — all suites, all containers
export CLEAN_CONTAINERS=1 
export SELECTED_CONTAINERS=all 
./run-tests.sh postgres

Environment Variables

All variables have sensible defaults and can be exported before running or passed inline.

VariableDefaultDescription
CLEAN_CONTAINERS0Set to 1 to wipe all containers and force a full rebuild from scratch
RUN_TESTS1Set to 0 to bring up infrastructure only without running any tests
AUDIT_INDEX_STOREopensearchAudit backend: opensearch, solr, or none to skip the audit pipeline entirely
SELECTED_CONTAINERS(prompted)Space-separated optional containers to bring up, e.g. "hadoop hive". Set to "all" to bring up every optional container. Required for the hdfs suite: export hadoop or all (starts ranger-hadoop).

CLEAN_CONTAINERS

By default containers persist between runs for fast re-execution. Set to 1 only when you need a completely clean rebuild — e.g. after a Maven source change or to reset all data. On all subsequent re-runs, leave it unset to reuse existing containers.

RUN_TESTS

Set to 0 to bring up the full infrastructure without executing any tests. Useful when containers are still initializing or you want to inspect the environment first before running tests.

AUDIT_INDEX_STORE

Controls whether the audit pipeline (Kafka + ingestor + OpenSearch/Solr) is started. Defaults to opensearch. Set to none to skip the entire audit pipeline — no Kafka download, no audit containers.

SELECTED_CONTAINERS

Pre-select which optional containers to bring up without being prompted interactively. Accepts a space-separated list of container names (e.g. "hadoop hive") or all to bring up every optional container. When not set, the script prompts at runtime.


Containers Brought Up

Always (Base Services)

Regardless of which test suites or containers you choose, these always start. This matches the ranger-core command in dev-support/ranger-docker/README.md.

ContainerRole
rangerRanger Admin (policies, users, REST APIs)
ranger-kdcKerberos KDC
ranger-<db>Database (ranger-postgres, ranger-mysql, ranger-oracle)
ranger-zkZooKeeper
ranger-kmsRanger KMS
ranger-pdpRanger PDP (Policy Decision Point)
ranger-usersyncUser/group sync from LDAP or Unix
ranger-tagsyncTag-based policy sync

Audit Pipeline (when AUDIT_INDEX_STORE != none)

ContainerRole
ranger-kafkaKafka broker
ranger-audit-ingestorReads from Kafka, writes to audit store
ranger-opensearch / ranger-solrAudit index store
ranger-audit-dispatcher-<store>Dispatches audit events

Optional Containers (selected at runtime)

Brought up based on what you enter at the containers prompt (or SELECTED_CONTAINERS env var):

Container name enteredContainers startedNotes
hadoopranger-hadoopHDFS + YARN
hiveranger-hadoop, ranger-hivehadoop auto-included
hbaseranger-hadoop, ranger-hbasehadoop auto-included
knoxranger-knox
trinoranger-trino
ozoneozone-om, ozone-scm, ozone-datanodepre-setup script runs automatically
kafkaranger-kafka
all / (Enter)All of the above

Note on hive, hbase, kafka suites

  • Each suite uses its own Docker service repo: dev_hive, dev_hbase, dev_kafka.
  • Tests assert on client output only (beeline, HBase shell, Kafka console producer). Access-audit checks are deferred; helpers are in ranger_test_utils/access_audit_utils.py.
  • hive and hbase start ranger-hadoop automatically. kafka starts ranger-kafka.
  • Example: SELECTED_CONTAINERS="hive hbase kafka" ./run-tests.sh postgres hive hbase kafka

HDFS suite notes

  • Service repo is dev_hdfs.

  • ./run-tests.sh postgres hdfs does not start ranger-hadoop. Export SELECTED_CONTAINERS=hadoop (or all) first.

  • The whole hdfs/ folder runs. For plugin tests only: pytest hdfs/test_hdfs_group_policy_03.py -m hdfs_policy (still needs ranger-hadoopand admin running).

  • Example:

    export AUDIT_INDEX_STORE=none
    export SELECTED_CONTAINERS=hadoop
    ./run-tests.sh postgres hdfs
    

Test Reports

After execution, an HTML report is automatically generated for each suite in the functional-tests/ directory: