netbox-docker-plugin
netbox-docker-plugin copied to clipboard
:bug: Fix race condition in Container API
Decision Record
When creating or updating a container via the API, here's what happens:
sequenceDiagram
actor Client
participant PluginAPI
participant Netbox
participant Agent
Client ->>PluginAPI: PATCH with operation=recreate, binds=[...]
PluginAPI->>Netbox: update Container
Netbox->>Agent: Webhook Call
PluginAPI->>Netbox: update binds, ...
Agent->>Netbox: write back binds=[]
Because the creation/update is not in an atomic transaction, the Agent writes back to Netbox potentially invalid data.
To alleviate this, the Client needs to first PATCH with the data for Netbox, then PATCH operation=recreate (just as you would do in the Netbox UI).
We can skip that part if we use Django transactions.
Changes
- [x] :bug: Use
transaction.atomic()for container creation/update in API - [ ] :white_check_mark: Add test suite
☂️ Python Coverage
current status: ✅
Overall Coverage
| Lines | Covered | Coverage | Threshold | Status |
|---|---|---|---|---|
| 2177 | 2143 | 98% | 90% | ✅ |
New Files
No new covered files...
Modified Files
No covered modified files...
updated for commit:
c34d54dby action🐍