Skip to content

Commit e43b5e4

Browse files
authored
Added testing framework (#121)
* added api test case for access list * initial testing framework
1 parent 9611816 commit e43b5e4

22 files changed

+394
-52
lines changed

.github/linters/.flake8

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/linters/.isort.cfg

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/linters/.jscpd.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
# This ensures that previous jobs for the workflow are canceled when the ref is
8+
# updated.
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
run-lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
with:
20+
# Full git history is needed to get a proper list of changed files within `super-linter`
21+
fetch-depth: 0
22+
23+
- name: Lint Code Base
24+
uses: github/super-linter/slim@v4
25+
env:
26+
DEFAULT_BRANCH: dev
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
SUPPRESS_POSSUM: true
29+
LINTER_RULES_PATH: /
30+
VALIDATE_ALL_CODEBASE: false
31+
VALIDATE_DOCKERFILE: false
32+
VALIDATE_JSCPD: true
33+
FILTER_REGEX_EXCLUDE: (.*/)?(configuration/.*)
34+
35+
test:
36+
runs-on: ubuntu-latest
37+
name: Runs plugin tests
38+
needs: run-lint
39+
steps:
40+
- id: git-checkout
41+
name: Checkout
42+
uses: actions/checkout@v3
43+
44+
- id: docker-test
45+
name: Test the image
46+
run: ./test.sh snapshot

.github/workflows/super-linter.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.jscpd.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"threshold": 10,
3+
"ignore": ["**/tests/**"]
4+
}

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ repos:
99
- id: debug-statements
1010
- id: end-of-file-fixer
1111
- id: name-tests-test
12+
args:
13+
- "--django"
1214
- id: requirements-txt-fixer
1315
- id: trailing-whitespace
1416
- repo: https://github.com/PyCQA/isort

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG NETBOX_VARIANT=v3.4
2+
3+
FROM netboxcommunity/netbox:${NETBOX_VARIANT}
4+
5+
RUN mkdir -pv /plugins/netbox-acls
6+
COPY . /plugins/netbox-acls
7+
8+
RUN /opt/netbox/venv/bin/python3 /plugins/netbox-acls/setup.py develop
9+
RUN cp -rf /plugins/netbox-acls/netbox_acls/ /opt/netbox/venv/lib/python3.10/site-packages/netbox_acls

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
include README.md
22
include LICENSE
33
recursive-include netbox_acls/templates *
4-
recursive-include netbox_acls/static *

configuration/configuration.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
####
2+
## We recommend to not edit this file.
3+
## Create separate files to overwrite the settings.
4+
## See `extra.py` as an example.
5+
####
6+
7+
from os import environ
8+
from os.path import abspath, dirname
9+
10+
# For reference see https://netbox.readthedocs.io/en/stable/configuration/
11+
# Based on https://github.com/netbox-community/netbox/blob/master/netbox/netbox/configuration.example.py
12+
13+
# Read secret from file
14+
def _read_secret(secret_name, default=None):
15+
try:
16+
f = open("/run/secrets/" + secret_name, encoding="utf-8")
17+
except OSError:
18+
return default
19+
else:
20+
with f:
21+
return f.readline().strip()
22+
23+
24+
_BASE_DIR = dirname(dirname(abspath(__file__)))
25+
26+
#########################
27+
# #
28+
# Required settings #
29+
# #
30+
#########################
31+
32+
# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write
33+
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
34+
#
35+
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
36+
ALLOWED_HOSTS = environ.get("ALLOWED_HOSTS", "*").split(" ")
37+
38+
# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
39+
# https://docs.djangoproject.com/en/stable/ref/settings/#databases
40+
DATABASE = {
41+
"NAME": environ.get("DB_NAME", "netbox"), # Database name
42+
"USER": environ.get("DB_USER", ""), # PostgreSQL username
43+
"PASSWORD": _read_secret("db_password", environ.get("DB_PASSWORD", "")),
44+
# PostgreSQL password
45+
"HOST": environ.get("DB_HOST", "localhost"), # Database server
46+
"PORT": environ.get("DB_PORT", ""), # Database port (leave blank for default)
47+
"OPTIONS": {"sslmode": environ.get("DB_SSLMODE", "prefer")},
48+
# Database connection SSLMODE
49+
"CONN_MAX_AGE": int(environ.get("DB_CONN_MAX_AGE", "300")),
50+
# Max database connection age
51+
"DISABLE_SERVER_SIDE_CURSORS": environ.get(
52+
"DB_DISABLE_SERVER_SIDE_CURSORS",
53+
"False",
54+
).lower()
55+
== "true",
56+
# Disable the use of server-side cursors transaction pooling
57+
}
58+
59+
# Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate
60+
# configuration exists for each. Full connection details are required in both sections, and it is strongly recommended
61+
# to use two separate database IDs.
62+
REDIS = {
63+
"tasks": {
64+
"HOST": environ.get("REDIS_HOST", "localhost"),
65+
"PORT": int(environ.get("REDIS_PORT", 6379)),
66+
"PASSWORD": _read_secret("redis_password", environ.get("REDIS_PASSWORD", "")),
67+
"DATABASE": int(environ.get("REDIS_DATABASE", 0)),
68+
"SSL": environ.get("REDIS_SSL", "False").lower() == "true",
69+
"INSECURE_SKIP_TLS_VERIFY": environ.get(
70+
"REDIS_INSECURE_SKIP_TLS_VERIFY",
71+
"False",
72+
).lower()
73+
== "true",
74+
},
75+
"caching": {
76+
"HOST": environ.get("REDIS_CACHE_HOST", environ.get("REDIS_HOST", "localhost")),
77+
"PORT": int(environ.get("REDIS_CACHE_PORT", environ.get("REDIS_PORT", 6379))),
78+
"PASSWORD": _read_secret(
79+
"redis_cache_password",
80+
environ.get("REDIS_CACHE_PASSWORD", environ.get("REDIS_PASSWORD", "")),
81+
),
82+
"DATABASE": int(environ.get("REDIS_CACHE_DATABASE", 1)),
83+
"SSL": environ.get("REDIS_CACHE_SSL", environ.get("REDIS_SSL", "False")).lower()
84+
== "true",
85+
"INSECURE_SKIP_TLS_VERIFY": environ.get(
86+
"REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY",
87+
environ.get("REDIS_INSECURE_SKIP_TLS_VERIFY", "False"),
88+
).lower()
89+
== "true",
90+
},
91+
}
92+
93+
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
94+
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
95+
# symbols. NetBox will not run without this defined. For more information, see
96+
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
97+
SECRET_KEY = _read_secret("secret_key", environ.get("SECRET_KEY", ""))
98+
99+
DEVELOPER = True

0 commit comments

Comments
 (0)