Skip to content

Commit

Permalink
Merge pull request #615 from nautobot/bootstrap_fix_614
Browse files Browse the repository at this point in the history
fix: 🐛 Pydantic errors and field normalization issues
  • Loading branch information
bile0026 authored Dec 6, 2024
2 parents c14be83 + 769f9e2 commit ab1c9e2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changes/614.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed creating platforms with no Manufacturer assigned.
Fixed time_zone attribute normalization on Location objects.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def load_location(self):
except AttributeError:
_time_zone = nb_location.time_zone
else:
_time_zone = None
_time_zone = ""
if nb_location.tenant is not None:
_tenant = nb_location.tenant.name
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Platform(DiffSyncModel):
_children = {}

name: str
manufacturer: str
manufacturer: Optional[str] = None
network_driver: Optional[str] = None
napalm_driver: Optional[str] = None
napalm_arguments: Optional[dict] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ def create(cls, adapter, ids, attrs):
"""Create Platform in Nautobot from NautobotPlatform object."""
adapter.job.logger.info(f'Creating Nautobot Platform {ids["name"]}')
try:
_manufacturer = ORMManufacturer.objects.get(name=ids["manufacturer"])
_manufacturer = None
if ids["manufacturer"]:
_manufacturer = ORMManufacturer.objects.get(name=ids["manufacturer"])
_new_platform = ORMPlatform(
name=ids["name"],
manufacturer=_manufacturer,
Expand Down
23 changes: 23 additions & 0 deletions nautobot_ssot/integrations/bootstrap/fixtures/global_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ platform:
napalm_driver: ""
napalm_arguments: {}
description: "Arista Devices"
- name: "linux"
manufacturer: ""
network_driver: ""
napalm_driver: ""
napalm_arguments: {}
description: "Linux Devices"
location_type:
- name: "Region"
parent: ""
Expand Down Expand Up @@ -248,6 +254,23 @@ location:
contact_phone: ""
contact_email: ""
tags: []
- name: "Southwest"
location_type: "Region"
parent: ""
status: "Active"
facility: "OR1"
asn:
time_zone: ""
description: ""
tenant: ""
physical_address: ""
shipping_address: ""
latitude:
longitude:
contact_name: ""
contact_phone: ""
contact_email: ""
tags: []
team:
- name: "Datacenter"
phone: "123-456-7890"
Expand Down
22 changes: 22 additions & 0 deletions nautobot_ssot/tests/bootstrap/fixtures/global_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@
"napalm_driver": "",
"napalm_arguments": {},
"description": "Arista Devices"
},
{
"name": "linux",
"manufacturer": "",
"network_driver": "",
"napalm_driver": "",
"napalm_arguments": {},
"description": "Linux Devices"
}
],
"location_type": [
Expand Down Expand Up @@ -281,6 +289,20 @@
"contact_phone": "",
"contact_email": "",
"tags": []
},
{
"name": "Southwest",
"location_type": "Region",
"status": "Active",
"facility": "OR1",
"time_zone": "",
"description": "",
"physical_address": "",
"shipping_address": "",
"contact_name": "",
"contact_phone": "",
"contact_email": "",
"tags": []
}
],
"team": [
Expand Down
4 changes: 3 additions & 1 deletion nautobot_ssot/tests/bootstrap/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ def _setup_manufacturers(self):

def _setup_platforms(self):
for _platform in GLOBAL_YAML_SETTINGS["platform"]:
_manufac = Manufacturer.objects.get(name=_platform["manufacturer"])
_manufac = None
if _platform["manufacturer"]:
_manufac = Manufacturer.objects.get(name=_platform["manufacturer"])
_platf = Platform.objects.create(
name=_platform["name"],
manufacturer=_manufac,
Expand Down

0 comments on commit ab1c9e2

Please sign in to comment.