Skip to content

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

@sol1-matt

Description

@sol1-matt

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.

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions