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

Validation of untagged_vlans when creating a virtualization interface is not sufficient #895

Closed
2 tasks done
sirtux opened this issue Sep 8, 2021 · 1 comment · Fixed by #1800
Closed
2 tasks done
Assignees
Labels
type: bug Something isn't working as expected
Milestone

Comments

@sirtux
Copy link
Contributor

sirtux commented Sep 8, 2021

Environment

  • Python version: 3.9
  • Nautobot version: 1.1.2

Steps to Reproduce

  1. Create a VM interface via API with the following data:
{
	"name": "testif2",
	"virtual_machine": "2c39cd68-ea72-4447-a872-01357e8495f9",
	"untagged_vlan": "f42d079e-a218-4207-9d8d-f292e6fdd961"
}
  1. Ask for the created interface again

Expected Behavior

The untagged VLAN is set in the object

Observed Behavior

VLAN is not set in the virtual interface

Workaround

Set the following data:

{ 'mode': 'access',
  'name': 'ens192',
  'untagged_vlan': 'f42d079e-a218-4207-9d8d-f292e6fdd961',
  'virtual_machine': 'aff62dfa-4ca8-4df8-b975-fb3fb0c9c045'}

Acceptance Criteria

  • API returns an 400 Bad Request when mode is not set to properly accept the untagged VLAN attribute, and a message in response to that effect.

Requirements

  • Throw a validation error when mode and untagged_vlan are incompatible
  • Because UI is permitted to silently pass the untagged vlan when mode is changed, the UI should unset the value when hiding the untagged_vlan field
@glennmatthews
Copy link
Contributor

Thanks for the report!

It turns out that this is not actually an API-speciifc issue! The same behavior can be seen via the UI, though the dynamic rendering of the UI form obscures this:

  • Begin creating a new VMInterface via the UI
  • Set mode to access so that the Untagged vlan field appears, and select a VLAN from the dropdown.
  • Clear out the mode setting (the Untagged vlan field now disappears from view, but its selection remains in effect)
  • Submit the form
  • Via your browser's developer tools, you can see that the form was submitted with an untagged_vlan value:
    image
  • But the resulting VMInterface has no associated VLANs.

Furthermore, the same behavior is seen for device Interfaces as well, due to the following common logic (https://github.com/nautobot/nautobot/blob/develop/nautobot/dcim/models/device_components.py#L480):

        # Remove untagged VLAN assignment for non-802.1Q interfaces
        if not self.mode:
            self.untagged_vlan = None

        # Only "tagged" interfaces may have tagged VLANs assigned. ("tagged all" implies all VLANs are assigned.)
        if self.present_in_database and self.mode != InterfaceModeChoices.MODE_TAGGED:
            self.tagged_vlans.clear()

This appears to have been intentionally added in NetBox via netbox-community/netbox#5360, but I agree that this is unintuitive for the REST API, and perhaps we can come up with a better way to solve that problem.

@glennmatthews glennmatthews added type: bug Something isn't working as expected workflow: under review and removed workflow: under review labels Sep 8, 2021
@bryanculver bryanculver moved this to To Groom in Nautobot Core ⚙️ Mar 22, 2022
@lampwins lampwins added this to the v1.4.0 milestone Apr 8, 2022
@bryanculver bryanculver moved this from To Groom to Todo in Nautobot Core ⚙️ May 16, 2022
@jathanism jathanism self-assigned this May 18, 2022
@jathanism jathanism moved this from Todo to In Progress in Nautobot Core ⚙️ May 18, 2022
@jathanism jathanism moved this from In Progress to In Review in Nautobot Core ⚙️ May 20, 2022
Repository owner moved this from In Review to Done in Nautobot Core ⚙️ May 23, 2022
jathanism added a commit that referenced this issue May 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
4 participants