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

Adding the untagged_vlan property to dcim.interface using the API that isn't in mode tagged fails without error #17249

Closed
sol1-matt opened this issue Aug 23, 2024 · 4 comments · May be fixed by #17211
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@sol1-matt
Copy link

sol1-matt commented Aug 23, 2024

Deployment Type

Self-hosted

NetBox Version

v4.0.5, v4.0.9

Python Version

3.10

Steps to Reproduce

  1. Create site
  2. Create vlan at site, don't set 802.1Q Mode (leave it unset)
  3. Create device at site
  4. Create interface on device
  5. Try adding the vlan to the interface using the netbox api with the following options
    1. dict containing dict {'untagged_vlan':{vid, name, site}} values from vlan
    2. dict containing dict {'untagged_vlan':{id}}, value from vlan
    3. dict contaning value {'untagged_vlan': id} value from vlan

Test script using pynetbox

pip install logruru pynetbox
loguru because I like the colours

import pynetbox
import requests

from loguru import logger

netbox_url = "https://demo.netbox.dev"
token = "I assume my token will be deleted so add your own :)"
headers = {
    'Authorization': f'Token {token}',
    'Content-Type': 'application/json',
    'Accept': 'application/json',
}

device_id = 129 
iface_id = 1776
vlan_id = 21

nb = pynetbox.api(netbox_url, token=token)

device = nb.dcim.devices.get(id=device_id)
logger.debug(dict(device))

iface = nb.dcim.interfaces.get(id=iface_id)
logger.debug(dict(iface))

vlan = nb.ipam.vlans.get(id=vlan_id)
logger.debug(dict(vlan))



## Pynetbox tests
try:
    logger.error("pynetbox: API doc required vid and name")
    logger.info(f"loaded: {iface.untagged_vlan}")
    iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id}
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

try:
    logger.error("pynetbox: vlan id")
    iface.untagged_vlan = {"id": vlan.id}
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

try:
    logger.error("pynetbox: vlan object")
    iface.untagged_vlan = vlan
    logger.info(f"local: {iface.untagged_vlan}")
    iface.save()
    iface = nb.dcim.interfaces.get(id=iface_id)
    logger.info(f"reloaded: {iface.untagged_vlan}")
except Exception as e:
    logger.critical(e)

Expected Behavior

The api call would return a error message telling me I can't add a untagged_vlan with first setting a 802.1Q Mode.

Observed Behavior

The api works successfully and the interface object is returned unchanged.

@sol1-matt sol1-matt added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Aug 23, 2024
@sol1-matt
Copy link
Author

sol1-matt commented Aug 23, 2024

This started out as a bug report on the api not working until I figured out I needed to set the 802.1Q Mode to tagged on the interface to be able to save to the untagged_vlan field.

That was annoying enough and took enough time to figure out that I still submitted issue so anybody else automating vlan creation has a reference even if it doesn't get fixed.

working example is

    iface.mode = 'tagged'
    iface.untagged_vlan = {"vid": vlan.vid, "name": vlan.name, "site": vlan.site.id}
    iface.save()

@sol1-matt sol1-matt changed the title Adding the untagged_vlan property to dcim.interface that isn't in mode tagged fails without error Adding the untagged_vlan property to dcim.interface using the API that isn't in mode tagged fails without error Aug 23, 2024
@DanSheps DanSheps added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Aug 24, 2024
@jeremystretch
Copy link
Member

This seems very similar to the issue captured under #15924 and can probably be addressed in the same manner. @DanSheps do you think it makes sense to merge these?

@DanSheps DanSheps added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Aug 27, 2024
@DanSheps DanSheps self-assigned this Aug 27, 2024
@DanSheps
Copy link
Member

Good catch, I will implement the fix in the same PR since they are so closely related

@jeremystretch
Copy link
Member

Folding this into #15924, for which PR #17211 has been submitted.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
3 participants