Netbox: Connected Endpoint is not updated when Cable is updated

Created on 12 Mar 2019  路  6Comments  路  Source: netbox-community/netbox

Environment

  • Python version: 3.6.6
  • NetBox version: 2.5.8

Steps to Reproduce

  1. Create device name: sw1
  2. Create interface on sw1 name sw_port1
  3. Create device name srv1
  4. Create interfaces on srv1 with the names: srv_port1 and srv_port2
  5. Create cable connection sw1:sw_port1 -> srv1:srv_port1
  6. Using the PUT or PATCH method, change the connection from sw1:sw_port1 -> srv1: srv_port1 to sw1:sw_port1 -> srv1:srv_port2
    sw_port1 id: 10925
    srv_port1 id: 10929
    srv_port2 id: 10930
    cable id: 688
    curl -X PUT "http://netbox/api/dcim/cables/688/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: ...." -d "{ \"termination_a_type\": \"dcim.interface\", \"termination_a_id\": 10930, \"termination_b_type\": \"dcim.interface\", \"termination_b_id\": 10925}"

Expected Behavior

1) All information on the 688 cable from the srv_port1 port will be removed
2) There will be full information about the connection of cable 688 on the port srv_port2

Observed Behavior

1) The cable information from the srv_port1 port has not been removed:

curl ..... http://netbox/api/dcim/interfaces/10929/
{
    "id": 10929,
    "device": {
        "id": 3133,
        "url": "http://netbox/api/dcim/devices/3133/",
        "name": "srv1",
        "display_name": "srv1"
    },
    "name": "srv_port1",
..........
    "connected_endpoint_type": "dcim.interface",
    "connected_endpoint": {
        "id": 10925,
        "url": "http://netbox/api/dcim/interfaces/10925/",
        "device": {
            "id": 3132,
            "url": "http://netbox/api/dcim/devices/3132/",
            "name": "sw1",
            "display_name": "sw1"
        },
        "name": "sw_port1",
        "cable": 688,
        "connection_status": {
            "value": true,
            "label": "Connected"
        }
    },
    "connection_status": {
        "value": true,
        "label": "Connected"
    },
    "cable": {
        "id": 688,
        "url": "http://netbox/api/dcim/cables/688/",
        "label": ""
    },
......
}

2) Not full information on connecting cable 688 to port srv_port2

curl ... http://netbox/api/dcim/interfaces/10930/
{
    "id": 10930,
    "device": {
        "id": 3133,
        "url": "http://netbox/api/dcim/devices/3133/",
        "name": "srv1",
        "display_name": "srv1"
    },
    "name": "srv_port2",
.............
    "connected_endpoint_type": null,
    "connected_endpoint": null,
    "connection_status": null,
    "cable": {
        "id": 688,
        "url": "http://netbox/api/dcim/cables/688/",
        "label": ""
    },
..............
}

PS
But in the cable information is all correct:

curl  ..... http://netbox/api/dcim/cables/688/
{
    "id": 688,
    "termination_a_type": "dcim.interface",
    "termination_a_id": 10930,
    "termination_a": {
        "id": 10930,
        "url": "http://netbox/api/dcim/interfaces/10930/",
        "device": {
            "id": 3133,
            "url": "http://netbox/api/dcim/devices/3133/",
            "name": "srv1",
            "display_name": "srv1"
        },
        "name": "srv_port2",
        "cable": 688,
        "connection_status": null
    },
    "termination_b_type": "dcim.interface",
    "termination_b_id": 10925,
    "termination_b": {
        "id": 10925,
        "url": "http://netbox/api/dcim/interfaces/10925/",
        "device": {
            "id": 3132,
            "url": "http://netbox/api/dcim/devices/3132/",
            "name": "sw1",
            "display_name": "sw1"
        },
        "name": "sw_port1",
        "cable": 688,
        "connection_status": {
            "value": true,
            "label": "Connected"
        }
    },
    "type": null,
    "status": {
        "value": true,
        "label": "Connected"
    },
    "label": "",
    "color": "",
    "length": null,
    "length_unit": null
}
accepted bug

Most helpful comment

I think the most reasonable approach is to disallow modifying the endpoint of an existing cable. This was never part of the intended workflow; the cable should be deleted and a new one created with the desired endpoints.

All 6 comments

Looked into this a little bit, looks like there are a couple of things going on here..

First, when a cable is created, it saves the "connected interface" into the interfaces table for that specific interface.

When a cable is updated, that interface is suppose to be updated by a signal, however it cannot because, at least in my testing, I found there was a duplicate foreign key from the old value.

We cod do away with this caching, and instead run direct calls to get_path_endpoints(), however that presents another problem, which is we would most likely need to run several database queries for each cable to get endpoints. This could have a negative performance impact.

Another way, is to possibly add in a pre_save and have that remove the endpoint from the model first, but I think @jeremystretch and @lampwins should weigh in first if we even want to do this. I am not 100% familiar with DJango signals.

I think the most reasonable approach is to disallow modifying the endpoint of an existing cable. This was never part of the intended workflow; the cable should be deleted and a new one created with the desired endpoints.

FYI: I can fix this as part of #3633.

@steffann How are you proposing to fix it? If you do fix it, it would be best to have it part of a separate commit.

Agreed. Bugs need to be addressed individually and not conflated with separate feature work. This allows us to clearly track how they are fixed (or not fixed) over time.

This bug is a side effect of limitations in the current way connected endpoints are implemented. My suggestion is to improve the endpoint handling to be more flexible, and then this bug won't be an issue anymore.

There have been multiple bugs that are caused by architectural limitations. Let's fix the architecture instead of paying whack-a-mole with the resulting bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hoalex picture hoalex  路  3Comments

billyzoellers picture billyzoellers  路  3Comments

robbagithub picture robbagithub  路  3Comments

benjy44 picture benjy44  路  3Comments

soer7022 picture soer7022  路  3Comments