Skip to content

Commit bc138d1

Browse files
author
nniehoff
authored
Merge pull request #18 from networktocode/dga-2.10
Update Travis to run tests on Netbox 2.10 too
2 parents 4423b43 + 0cbd15c commit bc138d1

File tree

8 files changed

+144
-83
lines changed

8 files changed

+144
-83
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ env:
88
# Each version of NetBox listed here must have a corresponding directory/configuration file
99
# under development/netbox_<NETBOX_VER>/configuration.py
1010
matrix:
11-
- NETBOX_VER=v2.8.3
12-
- NETBOX_VER=v2.9-beta2
13-
- NETBOX_VER=master
11+
- NETBOX_VER=v2.8.9
12+
- NETBOX_VER=v2.9.11
13+
- NETBOX_VER=v2.10.4
1414
# Encrypted value for PYPI_TOKEN, this secret has been generated with the following command
1515
# travis encrypt PYPI_TOKEN=<value> --add env.global --com
1616
global:

development/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
ARG python_ver=3.7
33
FROM python:${python_ver}
44

5-
ARG netbox_ver=master
65
ENV PYTHONUNBUFFERED 1
76

87
RUN mkdir /prom_cache
@@ -18,9 +17,9 @@ RUN pip install --upgrade pip\
1817
# -------------------------------------------------------------------------------------
1918
# Remove redis==3.4.1 from the requirements.txt file as a workaround to #4910
2019
# https://github.com/netbox-community/netbox/issues/4910, required for version 2.8.8 and earlier
20+
ARG netbox_ver=${NETBOX_VER}
2121
RUN git clone --single-branch --branch ${netbox_ver} https://github.com/netbox-community/netbox.git /opt/netbox/ && \
2222
cd /opt/netbox/ && \
23-
sed -i '/^redis\=\=/d' /opt/netbox/requirements.txt && \
2423
pip install -r /opt/netbox/requirements.txt
2524

2625
# Make the django-debug-toolbar always visible when DEBUG is enabled,
@@ -29,9 +28,6 @@ RUN echo "import sys" >> /opt/netbox/netbox/netbox/settings.py && \
2928
echo "TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'" >> /opt/netbox/netbox/netbox/settings.py && \
3029
echo "DEBUG_TOOLBAR_CONFIG = {'SHOW_TOOLBAR_CALLBACK': lambda _: DEBUG and not TESTING }" >> /opt/netbox/netbox/netbox/settings.py
3130

32-
# Work around https://github.com/rq/django-rq/issues/421
33-
RUN pip install django-rq==2.3.2
34-
3531
# -------------------------------------------------------------------------------------
3632
# Install Netbox Plugin
3733
# -------------------------------------------------------------------------------------

development/base_configuration.py renamed to development/configuration.py

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
1-
"""NetBox configuration file."""
1+
"""NetBox configuration."""
22
import os
3+
from distutils.util import strtobool
4+
from django.core.exceptions import ImproperlyConfigured
5+
from .settings import VERSION # pylint: disable=relative-beyond-top-level
6+
7+
8+
# Enforce required configuration parameters
9+
for key in [
10+
"ALLOWED_HOSTS",
11+
"POSTGRES_DB",
12+
"POSTGRES_USER",
13+
"POSTGRES_HOST",
14+
"POSTGRES_PASSWORD",
15+
"REDIS_HOST",
16+
"REDIS_PASSWORD",
17+
"SECRET_KEY",
18+
]:
19+
if not os.environ.get(key):
20+
raise ImproperlyConfigured(f"Required environment variable {key} is missing.")
21+
22+
23+
def is_truthy(arg):
24+
"""Convert "truthy" strings into Booleans.
25+
26+
Examples:
27+
>>> is_truthy('yes')
28+
True
29+
Args:
30+
arg (str): Truthy string (True values are y, yes, t, true, on and 1; false values are n, no,
31+
f, false, off and 0. Raises ValueError if val is anything else.
32+
"""
33+
if isinstance(arg, bool):
34+
return arg
35+
return bool(strtobool(arg))
36+
337

438
# For reference see http://netbox.readthedocs.io/en/latest/configuration/mandatory-settings/
539
# Based on https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/configuration.example.py
@@ -16,46 +50,52 @@
1650
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
1751
#
1852
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
19-
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(" ")
53+
ALLOWED_HOSTS = os.environ["ALLOWED_HOSTS"].split(" ")
2054

2155
# PostgreSQL database configuration.
2256
DATABASE = {
23-
"NAME": os.environ.get("DB_NAME", "netbox"), # Database name
24-
"USER": os.environ.get("DB_USER", ""), # PostgreSQL username
25-
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
57+
"NAME": os.environ["POSTGRES_DB"], # Database name
58+
"USER": os.environ["POSTGRES_USER"], # PostgreSQL username
59+
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
2660
# PostgreSQL password
27-
"HOST": os.environ.get("DB_HOST", "localhost"), # Database server
28-
"PORT": os.environ.get("DB_PORT", ""), # Database port (leave blank for default)
61+
"HOST": os.environ["POSTGRES_HOST"], # Database server
62+
"PORT": 5432 if not os.environ.get("POSTGRES_PORT", False) else int(os.environ["POSTGRES_PORT"]), # Database port
2963
}
3064

3165
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
3266
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
3367
# symbols. NetBox will not run without this defined. For more information, see
3468
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
35-
SECRET_KEY = os.environ.get("SECRET_KEY", "")
69+
SECRET_KEY = os.environ["SECRET_KEY"]
3670

3771
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
3872
# Seperate sections for webhooks and caching allow for connecting to seperate Redis instances/datbases if desired.
3973
# Full connection details are required in both sections, even if they are the same.
4074
REDIS = {
4175
"caching": {
42-
"HOST": os.environ.get("REDIS_HOST", "redis"),
76+
"HOST": os.environ["REDIS_HOST"],
4377
"PORT": int(os.environ.get("REDIS_PORT", 6379)),
44-
"PASSWORD": os.environ.get("REDIS_PASSWORD", ""),
78+
"PASSWORD": os.environ["REDIS_PASSWORD"],
4579
"DATABASE": 1,
46-
"DEFAULT_TIMEOUT": 300,
47-
"SSL": bool(os.environ.get("REDIS_SSL", False)),
80+
"SSL": is_truthy(os.environ.get("REDIS_SSL", False)),
4881
},
4982
"tasks": {
50-
"HOST": os.environ.get("REDIS_HOST", "redis"),
83+
"HOST": os.environ["REDIS_HOST"],
5184
"PORT": int(os.environ.get("REDIS_PORT", 6379)),
52-
"PASSWORD": os.environ.get("REDIS_PASSWORD", ""),
85+
"PASSWORD": os.environ["REDIS_PASSWORD"],
5386
"DATABASE": 0,
54-
"DEFAULT_TIMEOUT": 300,
55-
"SSL": bool(os.environ.get("REDIS_SSL", False)),
87+
"SSL": is_truthy(os.environ.get("REDIS_SSL", False)),
5688
},
5789
}
5890

91+
if VERSION.startswith("2.8."):
92+
# NetBox 2.8.x Specific Settings
93+
REDIS["caching"]["DEFAULT_TIMEOUT"] = 300
94+
REDIS["tasks"]["DEFAULT_TIMEOUT"] = 300
95+
elif VERSION.startswith("2.9.") or VERSION.startswith("2.10."):
96+
RQ_DEFAULT_TIMEOUT = 300
97+
else:
98+
raise ImproperlyConfigured(f"Version {VERSION} of NetBox is unsupported at this time.")
5999

60100
#########################
61101
# #
@@ -71,8 +111,8 @@
71111

72112
# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
73113
# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
74-
BANNER_TOP = os.environ.get("BANNER_TOP", None)
75-
BANNER_BOTTOM = os.environ.get("BANNER_BOTTOM", None)
114+
BANNER_TOP = os.environ.get("BANNER_TOP", "")
115+
BANNER_BOTTOM = os.environ.get("BANNER_BOTTOM", "")
76116

77117
# Text to include on the login page above the login form. HTML is allowed.
78118
BANNER_LOGIN = os.environ.get("BANNER_LOGIN", "")
@@ -87,45 +127,65 @@
87127
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
88128
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
89129
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
90-
CORS_ORIGIN_ALLOW_ALL = True
130+
CORS_ORIGIN_ALLOW_ALL = is_truthy(os.environ.get("CORS_ORIGIN_ALLOW_ALL", False))
91131
CORS_ORIGIN_WHITELIST = []
92132
CORS_ORIGIN_REGEX_WHITELIST = []
93133

94134
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
95135
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
96136
# on a production system.
97-
DEBUG = True
98-
DEVELOPER = True
137+
DEBUG = is_truthy(os.environ.get("DEBUG", False))
138+
DEVELOPER = is_truthy(os.environ.get("DEVELOPER", False))
99139

100140
# Email settings
101141
EMAIL = {
102-
"SERVER": "localhost",
103-
"PORT": 25,
104-
"USERNAME": "",
105-
"PASSWORD": "",
106-
"TIMEOUT": 10,
107-
"FROM_EMAIL": "",
142+
"SERVER": os.environ.get("EMAIL_SERVER", "localhost"),
143+
"PORT": int(os.environ.get("EMAIL_PORT", 25)),
144+
"USERNAME": os.environ.get("EMAIL_USERNAME", ""),
145+
"PASSWORD": os.environ.get("EMAIL_PASSWORD", ""),
146+
"TIMEOUT": int(os.environ.get("EMAIL_TIMEOUT", 10)), # seconds
147+
"FROM_EMAIL": os.environ.get("EMAIL_FROM", ""),
108148
}
109149

110150
# Enforcement of unique IP space can be toggled on a per-VRF basis.
111151
# To enforce unique IP space within the global table (all prefixes and IP addresses not assigned to a VRF),
112152
# set ENFORCE_GLOBAL_UNIQUE to True.
113-
ENFORCE_GLOBAL_UNIQUE = False
153+
ENFORCE_GLOBAL_UNIQUE = is_truthy(os.environ.get("ENFORCE_GLOBAL_UNIQUE", False))
154+
155+
# HTTP proxies NetBox should use when sending outbound HTTP requests (e.g. for webhooks).
156+
# HTTP_PROXIES = {
157+
# "http": "http://192.0.2.1:3128",
158+
# "https": "http://192.0.2.1:1080",
159+
# }
160+
161+
# IP addresses recognized as internal to the system. The debugging toolbar will be available only to clients accessing
162+
# NetBox from an internal IP.
163+
INTERNAL_IPS = ("127.0.0.1", "::1")
164+
165+
LOG_LEVEL = os.environ.get("LOG_LEVEL", "DEBUG" if DEBUG else "INFO")
114166

115167
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
116168
# https://docs.djangoproject.com/en/1.11/topics/logging/
117-
LOGGING = {}
169+
LOGGING = {
170+
"version": 1,
171+
"disable_existing_loggers": False,
172+
"formatters": {
173+
"verbose": {
174+
"format": "{asctime} {levelname} {message} - {name} - {module} - {pathname}:{lineno}",
175+
"datefmt": "%H:%M:%S",
176+
"style": "{",
177+
},
178+
},
179+
"handlers": {"console": {"level": "DEBUG", "class": "rq.utils.ColorizingStreamHandler", "formatter": "verbose"}},
180+
"root": {"handlers": ["console"], "level": LOG_LEVEL},
181+
}
118182

119183
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
120184
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
121-
LOGIN_REQUIRED = False
122-
123-
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
124-
# BASE_PATH = 'netbox/'
125-
BASE_PATH = os.environ.get("BASE_PATH", "")
185+
LOGIN_REQUIRED = is_truthy(os.environ.get("LOGIN_REQUIRED", False))
126186

127187
# Setting this to True will display a "maintenance mode" banner at the top of every page.
128-
MAINTENANCE_MODE = os.environ.get("MAINTENANCE_MODE", False)
188+
MAINTENANCE_MODE = is_truthy(os.environ.get("MAINTENANCE_MODE", False))
129189

130190
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
131191
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
@@ -136,11 +196,14 @@
136196
# the default value of this setting is derived from the installed location.
137197
MEDIA_ROOT = os.environ.get("MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
138198

199+
# Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
200+
METRICS_ENABLED = True
201+
139202
NAPALM_USERNAME = os.environ.get("NAPALM_USERNAME", "")
140203
NAPALM_PASSWORD = os.environ.get("NAPALM_PASSWORD", "")
141204

142205
# NAPALM timeout (in seconds). (Default: 30)
143-
NAPALM_TIMEOUT = os.environ.get("NAPALM_TIMEOUT", 30)
206+
NAPALM_TIMEOUT = int(os.environ.get("NAPALM_TIMEOUT", 30))
144207

145208
# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
146209
# be provided as a dictionary.
@@ -150,26 +213,34 @@
150213
}
151214

152215
# Determine how many objects to display per page within a list. (Default: 50)
153-
PAGINATE_COUNT = os.environ.get("PAGINATE_COUNT", 50)
216+
PAGINATE_COUNT = int(os.environ.get("PAGINATE_COUNT", 50))
154217

155218
# Enable installed plugins. Add the name of each plugin to the list.
156219
PLUGINS = ["netbox_metrics_ext"]
157220

158221
# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
159222
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
160-
# PLUGINS_CONFIG = {}
223+
PLUGINS_CONFIG = {}
161224

162225
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
163226
# prefer IPv4 instead.
164-
PREFER_IPV4 = os.environ.get("PREFER_IPV4", False)
227+
PREFER_IPV4 = is_truthy(os.environ.get("PREFER_IPV4", False))
165228

166229
# Remote authentication support
167230
REMOTE_AUTH_ENABLED = False
168-
REMOTE_AUTH_BACKEND = "utilities.auth_backends.RemoteUserBackend"
169231
REMOTE_AUTH_HEADER = "HTTP_REMOTE_USER"
170232
REMOTE_AUTH_AUTO_CREATE_USER = True
171233
REMOTE_AUTH_DEFAULT_GROUPS = []
172-
REMOTE_AUTH_DEFAULT_PERMISSIONS = []
234+
235+
if VERSION.startswith("2.8."):
236+
# NetBox 2.8.x Specific Settings
237+
REMOTE_AUTH_BACKEND = "utilities.auth_backends.RemoteUserBackend"
238+
REMOTE_AUTH_DEFAULT_PERMISSIONS = []
239+
elif VERSION.startswith("2.9.") or VERSION.startswith("2.10."):
240+
REMOTE_AUTH_BACKEND = "netbox.authentication.RemoteUserBackend"
241+
REMOTE_AUTH_DEFAULT_PERMISSIONS = {}
242+
else:
243+
raise ImproperlyConfigured(f"Version {VERSION} of NetBox is unsupported at this time.")
173244

174245
# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour.
175246
RELEASE_CHECK_TIMEOUT = 24 * 3600
@@ -185,6 +256,10 @@
185256
# this setting is derived from the installed location.
186257
REPORTS_ROOT = os.environ.get("REPORTS_ROOT", os.path.join(BASE_DIR, "reports"))
187258

259+
# The file path where custom scripts will be stored. A trailing slash is not needed. Note that the default value of
260+
# this setting is derived from the installed location.
261+
SCRIPTS_ROOT = os.environ.get("SCRIPTS_ROOT", os.path.join(BASE_DIR, "scripts"))
262+
188263
# Time zone (default: UTC)
189264
TIME_ZONE = os.environ.get("TIME_ZONE", "UTC")
190265

development/dev.env

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
ALLOWED_HOSTS=*
2-
DB_NAME=netbox
3-
DB_USER=netbox
4-
DB_PASSWORD=decinablesprewad
5-
PGPASSWORD=decinablesprewad
6-
DB_HOST=postgres
7-
NAPALM_TIMEOUT=5
2+
BANNER_TOP="Metrics Ext plugin dev"
3+
CHANGELOG_RETENTION=0
4+
DEBUG=True
5+
DEVELOPER=True
6+
7+
EMAIL_PASSWORD=
8+
EMAIL_PORT=25
9+
EMAIL_SERVER=localhost
10+
EMAIL_TIMEOUT=5
11+
EMAIL_USERNAME=netbox
812
MAX_PAGE_SIZE=0
9-
SECRET_KEY=bqn8nn4qmjvx4hv2u5qr4pp46s3w9skbb63y
10-
POSTGRES_USER=netbox
11-
POSTGRES_PASSWORD=decinablesprewad
13+
METRICS_ENABLED=True
14+
NAPALM_TIMEOUT=5
1215
POSTGRES_DB=netbox
13-
CHANGELOG_RETENTION=0
16+
POSTGRES_HOST=postgres
17+
POSTGRES_PASSWORD=notverysecurepwd
18+
POSTGRES_USER=netbox
1419
REDIS_HOST=redis
20+
REDIS_PASSWORD=notverysecurepwd
1521
REDIS_PORT=6379
16-
# Uncomment REDIS_SSL if using SSL
1722
# REDIS_SSL=True
18-
REDIS_PASSWORD=decinablesprewad
19-
23+
# Uncomment REDIS_SSL if using SSL
24+
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
25+
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
26+
SUPERUSER_EMAIL=[email protected]
27+
SUPERUSER_NAME=admin
28+
SUPERUSER_PASSWORD=admin

development/docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ services:
1717
env_file:
1818
- ./dev.env
1919
volumes:
20-
- ./base_configuration.py:/opt/netbox/netbox/netbox/base_configuration.py
21-
- ./netbox_${NETBOX_VER}/configuration.py:/opt/netbox/netbox/netbox/configuration.py
20+
- ./configuration.py:/opt/netbox/netbox/netbox/configuration.py
2221
- ./example_reports:/opt/netbox/netbox/reports
2322
- ../netbox_metrics_ext:/source/netbox_metrics_ext
2423
tty: true
@@ -33,8 +32,7 @@ services:
3332
env_file:
3433
- ./dev.env
3534
volumes:
36-
- ./base_configuration.py:/opt/netbox/netbox/netbox/base_configuration.py
37-
- ./netbox_${NETBOX_VER}/configuration.py:/opt/netbox/netbox/netbox/configuration.py
35+
- ./configuration.py:/opt/netbox/netbox/netbox/configuration.py
3836
- ./example_reports:/opt/netbox/netbox/reports
3937
- ../netbox_metrics_ext:/source/netbox_metrics_ext
4038
tty: true

development/netbox_master/configuration.py

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

development/netbox_v2.8.3/configuration.py

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

development/netbox_v2.9-beta2/configuration.py

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

0 commit comments

Comments
 (0)