Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions functional-tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.


# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

[pytest]
markers =
cleanEZ: clean up the encryption zone
createEZ: create encryption zone
get: get methods
post: post methods
put: put methods
delete: delete methods
positive: positive test cases
negative: negative test cases
xuserrest: xuserrest test cases
secure_endpoint: secure endpoint test cases
rolerest: rolerest test cases
pythonpath = .
165 changes: 111 additions & 54 deletions functional-tests/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,141 @@ 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.
-->


This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
## Pytest Functional Test Suite

This workflow uses actions that are not certified by GitHub.
They are provided by a third-party and are governed by
separate terms of service, privacy policy, and support
documentation.
-->
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

## Pytest Functional Test-suite
| Suite | Description |
|---|---|
| **hdfs** | Test cases for HDFS encryption lifecycle using KMS |
| **kms** | Test cases for KMS REST API functionality |
| **xuserrest** | Test cases for Ranger Admin User/Group REST APIs |
| **rolerest** | Test cases for Ranger Admin Role REST APIs |
| **servicerest** | Test cases for Ranger Admin Service REST APIs |

---

This test suite validates REST API endpoints for KMS (Key Management Service) and tests HDFS encryption functionalities including key management and file operations within encryption zones.
This framework brings up docker containers and executes test cases
### Directory Structure

**hdfs :** contains test cases for checking KMS functionality through hdfs encryption lifecycle
```text
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

**kms :** contains test cases for checking KMS API functionality
```
> **Note:** A Python virtual environment folder named `myenv` will be automatically
> generated upon running the tests for the first time.


### Directory Structure
## Prerequisites
1. Docker & Docker Compose installed and running
2. Python 3.10 or higher
3. Change the working directory to functional-tests
```text
cd functional-tests/
```
4. Make the shell script executable

```text
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:
```text
export CLEAN_CONTAINERS=1
./run-tests.sh
```
functional-tests/
├── hdfs/ # Tests on HDFS encryption cycle
├── kms/ # Tests on KMS API
├── pytest.ini # Registers custom pytest markers
├── run_tests.sh # Script to automate test execution
├── requirements.txt
├── readme.md

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

```text
export CLEAN_CONTAINERS=0
./run-tests.sh
```

2. Infrastructure Only (Skip Tests)

Start Docker infrastructure without executing Pytest suites:

```text
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):

```text
export RUN_TESTS=1
./run-tests.sh
```

### Running Tests

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

Before running the tests, configure container behavior using the following environment variable:
~~~
# To force a fresh container setup:
export CLEAN_CONTAINERS=1
~~~
1. Interactive Mode:

After the initial setup, you can disable fresh container creation by setting below for the next re-runs:
~~~
export CLEAN_CONTAINERS=0
~~~
Run the script without arguments to be prompted for inputs:
```text
./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.

#### Executing Tests
example:
```text

Run the test script using:
~~~
./run-tests.sh [db-type] [additional-services]

# valid values for db-type: mysql/postgres/oracle , postgres is the default
# additional-services: multiple services can be specified separated by space

# e.g for running tests within kms and hdfs use below command:

./run-tests.sh postgres hadoop

# Note: If additional-services are specified, db-type must also be explicitly specified
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
```

~~~
2. Command-Line Arguments Mode:

Pass arguments directly to skip prompts:

```text
./run-tests.sh [db-type] [test-suites...]
```
db-type — Must be the first argument. Valid values: postgres, mysql, oracle.

#### Note (Optional)
test-suites — Space-separated list: hdfs, kms, xuserrest, servicerest.

If you only need to start the infrastructure i.e containers (without running tests):
~~~
export RUN_TESTS=0
~~~
This is useful when tests are failing due to incomplete container setup.
Examples:

After the infrastructure is successfully up, set RUN_TESTS=1 and rerun the script to execute the tests without setup issues.
```text
./run-tests.sh postgres kms hdfs
```

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

Reports generated after tests execution in html can be viewed in any browser for detailed test results.
| Suite | Report File |
|:------------|:------------------------|
| hdfs | report_hdfs.html |
| kms | report_kms.html |
| xuserrest | report_xuserrest.html |
| rolerest | report_rolerest.html |
| servicerest | report_servicerest.html |
14 changes: 14 additions & 0 deletions functional-tests/rolerest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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.
Loading
Loading