-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e48b7ee
commit 5292662
Showing
10 changed files
with
238 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1 @@ | ||
# Tests | ||
This directory contains integrations tests that can be run against the Diode Plugin | ||
|
||
|
||
Here's what you'll need to do in order to run these tests: | ||
- Start the Docker container for Diode Plugin | ||
- Create the user and his token | ||
- Configure the test settings | ||
- Run behave | ||
|
||
|
||
## Start the Docker container for Diode Plugin | ||
|
||
To run the tests, you must have the diode plugin directory and execute the following command in diode/diode-server folder: | ||
|
||
```bash | ||
make docker-compose-up | ||
``` | ||
|
||
## Create the user and his token | ||
|
||
To create the user, execute: | ||
|
||
```bash | ||
docker exec -it diode-netbox-1 /opt/netbox/netbox/manage.py createsuperuser | ||
``` | ||
Fill the username and password for the superuser as requested. | ||
|
||
With this user, you can access the Netbox at http://0.0.0.0:8000/ and using the menu Admin -> API Token, you can create the token for this user. | ||
|
||
## Test settings | ||
Create the test config file from the template: `cp config.ini.tpl config.ini`. | ||
|
||
Then fill in the correct values: | ||
|
||
- **user_token**: | ||
- Mandatory! | ||
- string | ||
- user token created in the previous step | ||
|
||
- **api_root_path**: | ||
- Mandatory! | ||
- string | ||
- netbox API URL, e.g. http://0.0.0.0:8000/api | ||
|
||
|
||
## Run behave using parallel process | ||
|
||
You can use [behavex](https://github.com/hrcorval/behavex) to run the scenarios using multiprocess by simply run: | ||
|
||
Examples: | ||
|
||
> behavex -t @\<TAG\> --parallel-processes=2 --parallel-schema=scenario | ||
> behavex -t @\<TAG\> --parallel-processes=2 --parallel-schema=feature | ||
Running smoke tests: | ||
|
||
> behavex -t=@smoke --parallel-processes=2 --parallel-scheme=feature | ||
|
||
## Test execution reports | ||
[behavex](https://github.com/hrcorval/behavex) provides a friendly HTML test execution report that contains information related to test scenarios, execution status, execution evidence and metrics. A filters bar is also provided to filter scenarios by name, tag or status. | ||
|
||
It should be available at the following path: | ||
|
||
<output_folder>/report.html | ||
|
||
## Clean your environment | ||
|
||
The tests clean up the environment after running, you do not need any manual intervention to clean up the environment. | ||
# diode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Tests | ||
This directory contains integrations tests that can be run against the Diode Plugin | ||
|
||
|
||
Here's what you'll need to do in order to run these tests: | ||
- Start the Docker container for Diode Plugin | ||
- Create the user and his token | ||
- Configure the test settings | ||
- Run behave | ||
|
||
|
||
## Start the Docker container for Diode Plugin | ||
|
||
To run the tests, you must have the diode plugin directory and execute the following command in diode/diode-server folder: | ||
|
||
```bash | ||
make docker-compose-up | ||
``` | ||
|
||
## Create the user and his token | ||
|
||
To create the user, execute: | ||
|
||
```bash | ||
docker exec -it diode-netbox-1 /opt/netbox/netbox/manage.py createsuperuser | ||
``` | ||
Fill the username and password for the superuser as requested. | ||
|
||
With this user, you can access the Netbox at http://0.0.0.0:8000/ and using the menu Admin -> API Token, you can create the token for this user. | ||
|
||
## Test settings | ||
Create the test config file from the template: `cp config.ini.tpl config.ini`. | ||
|
||
Then fill in the correct values: | ||
|
||
- **user_token**: | ||
- Mandatory! | ||
- string | ||
- user token created in the previous step | ||
|
||
- **api_root_path**: | ||
- Mandatory! | ||
- string | ||
- netbox API URL, e.g. http://0.0.0.0:8000/api | ||
|
||
|
||
## Run behave using parallel process | ||
|
||
You can use [behavex](https://github.com/hrcorval/behavex) to run the scenarios using multiprocess by simply run: | ||
|
||
Examples: | ||
|
||
> behavex -t @\<TAG\> --parallel-processes=2 --parallel-schema=scenario | ||
> behavex -t @\<TAG\> --parallel-processes=2 --parallel-schema=feature | ||
Running smoke tests: | ||
|
||
> behavex -t=@smoke --parallel-processes=2 --parallel-scheme=feature | ||
|
||
## Test execution reports | ||
[behavex](https://github.com/hrcorval/behavex) provides a friendly HTML test execution report that contains information related to test scenarios, execution status, execution evidence and metrics. A filters bar is also provided to filter scenarios by name, tag or status. | ||
|
||
It should be available at the following path: | ||
|
||
<output_folder>/report.html | ||
|
||
## Clean your environment | ||
|
||
The tests clean up the environment after running, you do not need any manual intervention to clean up the environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Cleanup tests objects | ||
|
||
|
||
@cleanup | ||
Scenario: Cleanup of site object | ||
Given the site object "Site A" is deleted | ||
Then the site object is removed from the database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[tests_config] | ||
user_token = USER_TOKEN_CREATED_ON_NETBOX | ||
api_root_path = NETBOX API URL (e.g. http://localhost:8000/api) | ||
api_key = INGESTION_API_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Feature: Tests for ingestion of site objects | ||
Validate the behavior of the ingestion of site objects | ||
|
||
@smoke | ||
@ingestion.site | ||
Scenario: Ingestion of new site object | ||
Given a new site "Site A" object | ||
When the site object is ingested | ||
Then the site object is created in the database | ||
|
||
@smoke | ||
@ingestion.site | ||
Scenario: Ingestion of existing site object | ||
Given site object already exists in the database | ||
When the site object is ingested | ||
Then do nothing | ||
|
||
|
||
@smoke | ||
@ingestion.site | ||
Scenario: Ingestion of site object to change existing site object | ||
Given site object with status "planned" and description "some string" | ||
When the site object is ingested with the updates | ||
Then the site object is updated in the database | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from behave import given, when, then | ||
|
||
from steps.utils import get_site, send_delete_request | ||
|
||
|
||
@given('the site object "{site_name}" is deleted') | ||
def delete_site_object(context, site_name): | ||
context.site_name = site_name | ||
endpoint = "dcim/sites/" | ||
site = get_site(context.site_name) | ||
send_delete_request(endpoint, site.get("id")) | ||
|
||
|
||
@then("the site object is removed from the database") | ||
def check_site_object_deleted(context): | ||
"""Check if the response status code is 200 and the result is success""" | ||
site = get_site(context.site_name) | ||
assert site is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import time | ||
|
||
from behave import given, when, then | ||
|
||
from netboxlabs.diode.sdk import DiodeClient | ||
from netboxlabs.diode.sdk.diode.v1.ingester_pb2 import Entity | ||
from netboxlabs.diode.sdk.diode.v1.site_pb2 import Site | ||
|
||
from steps.config import configs | ||
|
||
from steps.utils import get_site, send_delete_request | ||
|
||
|
||
api_key = str(configs["api_key"]) | ||
|
||
|
||
@given('a new site "{site_name}" object') | ||
def step_create_new_site_object(context, site_name): | ||
"""Set the body of the request to create a new site.""" | ||
context.site_name = site_name | ||
|
||
|
||
@when("the site object is ingested") | ||
def ingest_site_object(context): | ||
"""Ingest the site object using the Diode SDK""" | ||
with DiodeClient( | ||
target="localhost:8081", | ||
app_name="my-test-app", | ||
app_version="0.0.1", | ||
api_key=api_key, | ||
) as client: | ||
entities = [ | ||
Entity(site=Site(name=context.site_name)), | ||
] | ||
|
||
context.response = client.ingest(entities=entities) | ||
return context.response | ||
|
||
|
||
@then("the site object is created in the database") | ||
@then("do nothing") | ||
def check_site_object(context): | ||
"""Check if the response status code is 200 and the result is success""" | ||
assert context.response is not None | ||
# Wait for the site object to be added to the cache | ||
time.sleep(3) | ||
site = get_site(context.site_name) | ||
assert site.get("name") == context.site_name | ||
assert site.get("status").get("value") == "active" | ||
|
||
|
||
@given("site object already exists in the database") | ||
def retrieve_existing_site_object(context): | ||
"""Retrieve the site object from the database""" | ||
context.site_name = "Site A" | ||
context.site = get_site(context.site_name) | ||
context.site_name = context.site.get("name") | ||
|
||
|
||
@given('site object with status "{status}" and description "{description}"') | ||
def create_site_object_to_update(context, status, description): | ||
"""Create a site object with a status and description to update""" | ||
context.site_name = "Site A" | ||
context.status = status | ||
context.description = description | ||
|
||
|
||
@when("the site object is ingested with the updates") | ||
def update_site_object(context): | ||
"""Update the site object using the Diode SDK""" | ||
with DiodeClient( | ||
target="localhost:8081", | ||
app_name="my-test-app", | ||
app_version="0.0.1", | ||
api_key=api_key, | ||
) as client: | ||
entities = [ | ||
Entity( | ||
site=Site( | ||
name=context.site_name, | ||
status=context.status, | ||
description=context.description, | ||
) | ||
), | ||
] | ||
|
||
context.response = client.ingest(entities=entities) | ||
return context.response | ||
|
||
|
||
@then("the site object is updated in the database") | ||
def check_site_object_updated(context): | ||
"""Check if the response status code is 200 and the result is success""" | ||
assert context.response is not None | ||
site = get_site(context.site_name) | ||
assert site.get("name") == context.site_name | ||
assert site.get("status").get("value") == context.status | ||
assert site.get("description") == context.description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters