Environment
- Python version: 3.10.9
- Network Importer version: 3.1.0
- Nautobot version: 1.5.6
- pynautobot: 1.2.2
Steps to Reproduce
- select a device where the hostname in config includes a nonalphanumeric character, eg the hostname of the device is configured as
hostname.3rdleveldomain instead of hostname
- model the device in Nautobot
- network-importer check --update-configs
- network-importer apply
Expected Behavior
import the device correctly
Observed Behavior
pynautobot.core.query.RequestError: The request failed with code 400 Bad Request: {'slug': ['Enter a valid “slug” consisting of Unicode letters, numbers, underscores, or hyphens.', 'Enter a valid "slug" consisting of Unicode letters, numbers, underscores, or hyphens.']}
It appears that when the nautobot adapter is creating device tags as part of vlan creation, it is passing a slug value. I tried removing the slug value from the call in the hopes that AutoSlugField would work, but that just changed the error:
pynautobot.core.query.RequestError: The request failed with code 400 Bad Request: {'slug': ['This field is required.']}
I was able to resolve the issue for network-importer by changing the slug field:
index 068dd3d..252ed51 100644
--- a/network_importer/adapters/nautobot_api/models.py
+++ b/network_importer/adapters/nautobot_api/models.py
@@ -48,9 +48,9 @@ class NautobotDevice(Device):
return self.device_tag_id
tag = self.diffsync.nautobot.extras.tags.get(name=f"device={self.name}")
-
if not tag:
- tag = self.diffsync.nautobot.extras.tags.create(name=f"device={self.name}", slug=f"device__{self.name}")
+ tag = self.diffsync.nautobot.extras.tags.create(
+ name=f"device={self.name}", slug=''.join(c if c.isalnum() else '_' for c in self.name))
self.device_tag_id = tag.id
return self.device_tag_id
Is this worth submitting a PR for since I know that the name field is expected to be alphanumeric only? I'm happy to patch my own instance to handle our badly configured brownfield devices. I'm also wondering if I should be submitting an issue to pynautobot about slug being required or if that is FAD.
Environment
Steps to Reproduce
hostname.3rdleveldomaininstead ofhostnameExpected Behavior
import the device correctly
Observed Behavior
It appears that when the nautobot adapter is creating device tags as part of vlan creation, it is passing a slug value. I tried removing the slug value from the call in the hopes that AutoSlugField would work, but that just changed the error:
I was able to resolve the issue for network-importer by changing the slug field:
Is this worth submitting a PR for since I know that the name field is expected to be alphanumeric only? I'm happy to patch my own instance to handle our badly configured brownfield devices. I'm also wondering if I should be submitting an issue to pynautobot about slug being required or if that is FAD.