netboxlabs / netbox-branching

Official NetBox Labs plugin that implements git-like branching functionality for NetBox
http://netboxlabs.com
Other
63 stars 1 forks source link

Branches don't leave pending stage on Netbox-Docker #135

Closed ewscott9 closed 1 month ago

ewscott9 commented 1 month ago

Plugin Version

5.0

NetBox Version

4.1.0 (Netbox-Docker 3.0.1)

Python Version

3.12.3

Steps to Reproduce

  1. Create a new branch.
  2. Wait for branch to leave pending under jobs tab in branch.

Expected Behavior

The provision branch job should leave the pending status, and for the branch's activate button should turn bright green.

Observed Behavior

I get the following error in the logs when I try to create a branch. Looks like netbox-worker-1 doesn't know about the netbox_branching plugin, maybe I need to install the plugin on both instances (I installed the plugin on netbox-1 and added GRANT CREATE ON DATABASE <dbname> TO <username> to the psql db on posgres-1).

netbox-1               | 128.120.37.187 - - [17/Sep/2024:20:52:40 +0000] "POST /plugins/branching/branches/add/ HTTP/1.1" 302 0 "http://128.120.46.138:8000/plugins/branching/branches/add/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
netbox-worker-1        | 20:52:40 [Job 4977e848-9294-4e70-a633-c92d497b25e0]: exception raised while executing (<DeserializationError>)
netbox-worker-1        | Traceback (most recent call last):
netbox-worker-1        |   File "/opt/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 486, in _deserialize_data
netbox-worker-1        |     self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
netbox-worker-1        |                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-worker-1        | ModuleNotFoundError: No module named 'netbox_branching'
netbox-worker-1        |
netbox-worker-1        | The above exception was the direct cause of the following exception:
netbox-worker-1        |
netbox-worker-1        | Traceback (most recent call last):
netbox-worker-1        |   File "/opt/netbox/venv/lib/python3.12/site-packages/rq/worker.py", line 1424, in perform_job
netbox-worker-1        |     self.prepare_job_execution(job, remove_from_intermediate_queue)
netbox-worker-1        |   File "/opt/netbox/venv/lib/python3.12/site-packages/rq/worker.py", line 1353, in prepare_job_execution
netbox-worker-1        |     self.procline(msg.format(job.func_name, job.origin, time.time()))
netbox-worker-1        |                              ^^^^^^^^^^^^^
netbox-worker-1        |   File "/opt/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 520, in func_name
netbox-worker-1        |     self._deserialize_data()
netbox-worker-1        |   File "/opt/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 488, in _deserialize_data
netbox-worker-1        |     raise DeserializationError() from e
netbox-worker-1        | rq.exceptions.DeserializationError
netbox-worker-1        |
ewscott9 commented 1 month ago

Ah-ha! Installing it on the netbox-worker-1 fixed the problem. It seems to be working now.

To resolve I had to run through the installation process listed here: https://github.com/netboxlabs/netbox-branching/blob/develop/docs/index.md

On both netbox-1 and netbox-worker-1. I also found that postgres-1 already has the GRANT CREATE ON DATABASE $database TO $user; set.

Specifically I did the following: Part1

# Enter the postgres-1 container and grant db creation for db_user.
docker exec -u root -ti netbox-docker-301-postgres-1 /bin/bash

#I believe the defaults for these on netbox docker are netbox:netbox.
psql -U <db_user> -d <db_name> -W 

# run this in psql cli
GRANT CREATE ON DATABASE <dbname> TO <dbusername>
\q 

Part 2

# Next run all of Part 3 via docker exec for the following 3 containers:
docker exec -u root -ti netbox-docker-301-netbox-worker-1 /bin/bash
docker exec -u root -ti netbox-docker-301-netbox-housekeeping-1 /bin/bash
docker exec -u root -ti netbox-docker-301-netbox-1 /bin/bash

Part 3

# Run the following. (copy between the ###'s for the longer commands)

### Activate the NetBox virtual environment and Install the plugin from PyPI
source /opt/netbox/venv/bin/activate
pip install netboxlabs-netbox-branching
###

### Append PLUGINS to configuration.py
echo "
PLUGINS = [
    # ...
    'netbox_branching',
]" >> /opt/netbox/netbox/netbox/configuration.py
###

### Create local_settings.py
echo "
from netbox_branching.utilities import DynamicSchemaDict
from .configuration import DATABASE

# Wrap DATABASES with DynamicSchemaDict for dynamic schema support
DATABASES = DynamicSchemaDict({
    'default': DATABASE,
})

# Employ our custom database router
DATABASE_ROUTERS = [
    'netbox_branching.database.BranchAwareRouter',
]" >> /opt/netbox/netbox/netbox/local_settings.py
###

/opt/netbox/netbox/manage.py migrate