Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connected Endpoint is not updated when Cable is updated #2994

Closed
VictorPavlushin opened this issue Mar 12, 2019 · 6 comments
Closed

Connected Endpoint is not updated when Cable is updated #2994

VictorPavlushin opened this issue Mar 12, 2019 · 6 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@VictorPavlushin
Copy link

VictorPavlushin commented Mar 12, 2019

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": ""
    },
......
}
  1. 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
}
@DanSheps DanSheps changed the title Incorrect cable termination change. Connected Endpoint is not updated when Cable is updated Mar 14, 2019
@DanSheps DanSheps added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Mar 14, 2019
@DanSheps
Copy link
Member

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.

@jeremystretch
Copy link
Member

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.

@steffann
Copy link
Contributor

steffann commented Nov 1, 2019

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

@DanSheps
Copy link
Member

DanSheps commented Nov 1, 2019

@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.

@jeremystretch
Copy link
Member

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.

@steffann
Copy link
Contributor

steffann commented Nov 1, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

4 participants