networktocode / ntc-netbox-plugin-onboarding

A plugin for NetBox to easily onboard new devices.
Other
245 stars 46 forks source link

Device display error after deleting its primary IP address #137

Open matthieup opened 3 years ago

matthieup commented 3 years ago

Environment

Steps to Reproduce

  1. Create device Test_01
  2. Create test-interface and binding to to Test_01
  3. Create IPaddress 1.1.1.1/24 and binding to test-interface
  4. Set primary IP of Test_01 to 1.1.1.1/24
  5. Delete IPaddress 1.1.1.1/24
  6. View Device Test_01 and it'll get an error of IPaddressDoesNotExist

Confirmed also that this only happens when having netbox_onboarding plugin enabled in netbox. This was also reported on https://github.com/netbox-community/netbox/issues/6069 before we found out this is only happening when netbox_onboarding is enabled.

Expected Behavior

After removing primary IP address of device, the device details should show up correctly without a restart of netbox.

Observed Behavior

Gettting an exception <class 'ipam.models.IPAddress.DoesNotExist'> as can be seen in the attached pictures.

Restarting Netbox fixes the problem, so it seems it may be related to a cache issue

Tested fix

As a quick fix, I tried to catch the exception by:

        try:
            ip = self.device.primary_ip4
        except IPAddress.DoesNotExist:
            return "unknown"

in functions last_check_attempt_date(self), last_check_successful_date(self), status(self) and last_ot(self) and device was able to be displayed correctly.

snapshot-ipv4-1 snapshot-ipv4-2