Skip to content

Commit

Permalink
refactor: Refactored v1/v2 contrib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abates committed Jan 26, 2024
1 parent ab99eda commit 9dc8b16
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 428 deletions.
2 changes: 2 additions & 0 deletions development/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ POSTGRES_DB=${NAUTOBOT_DB_NAME}
MYSQL_USER=${NAUTOBOT_DB_USER}
MYSQL_DATABASE=${NAUTOBOT_DB_NAME}
MYSQL_ROOT_HOST=%

DESIGN_BUILDER_ENABLE_BGP=True
51 changes: 16 additions & 35 deletions development/docker-compose.mysql.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,40 @@
# We can't remove volumes in a compose override, for the test configuration using the final containers
# we don't want the volumes so this is the default override file to add the volumes in the dev case
# any override will need to include these volumes to use them.
# see: https://github.com/docker/compose/issues/3729
---
version: "3.8"

services:
nautobot:
command: "nautobot-server runserver 0.0.0.0:8080"
ports:
- "8080:8080"
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
- "../examples/backbone_design/designs:/opt/nautobot/designs:cached"
- "../examples/backbone_design/jobs:/opt/nautobot/jobs:cached"
healthcheck:
test: ["CMD", "true"] # Due to layering, disable: true won't work. Instead, change the test
docs:
entrypoint: "mkdocs serve -v -a 0.0.0.0:8080"
ports:
- "8001:8080"
volumes:
- "../:/source"
image: "nautobot-design-builder/nautobot:${NAUTOBOT_VER}-py${PYTHON_VER}"
healthcheck:
disable: true
tty: true
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
worker:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
beat:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
db:
image: "mysql:8"
command:
- "--default-authentication-plugin=mysql_native_password"
- "--max_connections=1000"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
- "../examples/backbone_design/designs:/opt/nautobot/designs:cached"
- "../examples/backbone_design/jobs:/opt/nautobot/jobs:cached"
- "mysql_data:/var/lib/mysql"
healthcheck:
test:
- "CMD"
- "mysqladmin"
- "ping"
- "-h"
- "localhost"
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: "20s"
retries: 10
volumes:
Expand Down
34 changes: 27 additions & 7 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Nautobot development configuration file."""
from importlib import metadata
from importlib.util import find_spec
import os
import sys

from packaging.version import Version

from nautobot.core.settings import * # noqa: F403 # pylint: disable=wildcard-import,unused-wildcard-import
from nautobot.core.settings_funcs import is_truthy, parse_redis_connection
from importlib import metadata
from packaging.version import Version

#
# Debug
Expand Down Expand Up @@ -136,11 +138,29 @@
# Apps configuration settings. These settings are used by various Apps that the user may have installed.
# Each key in the dictionary is the name of an installed App and its value is a dictionary of settings.

# TODO: The following is necessary only until BGP models plugin
# is officially supported in 2.0
nautobot_version = Version(Version(metadata.version("nautobot")).base_version)

if nautobot_version < Version("2.0"):
if is_truthy(os.getenv("DESIGN_BUILDER_ENABLE_BGP", "False")):
if find_spec("nautobot_bgp_models") is None:
nautobot_version = Version(Version(metadata.version("nautobot")).base_version)
import subprocess # nosec

package = "nautobot-bgp-models"
if nautobot_version < Version("2.0"):
# pip doesn't have the capability to automatically pick
# a version compatible with the current Nautobot, so we
# do that manually. This is only for development environments
# so that we can run unit tests on Nautobot 1.6 and 2.x
package = "nautobot-bgp-models==0.9.1"
command = [
sys.executable,
"-m",
"pip",
"install",
package,
]
# Since we aren't evaluating any input variables, *and* we
# are not using a shell, this command should be considered
# save, therefore the `nosec` annotation.
subprocess.check_call(command, shell=False) # nosec
PLUGINS.append("nautobot_bgp_models")

PLUGINS_CONFIG = {"design_builder": {"context_repository": os.getenv("DESIGN_BUILDER_CONTEXT_REPO_SLUG", None)}}
Loading

0 comments on commit 9dc8b16

Please sign in to comment.