Skip to content

Commit dac42aa

Browse files
committed
Experimental fix for 500 controller response
The field serializer for extension_values in PayloadVrfsAttachmentsLanAttachListItem needs to set the value to “” if MULTISOTE_CONN and VRF_LITE_CONN both have zero length, else the controller chokes on the payload. This commit tests one way to accomplish this. If this works against the contoller, I’ll clean things up in the next commit.
1 parent 33e7750 commit dac42aa

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

plugins/module_utils/vrf/model_payload_vrfs_attachments.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ def serialize_extension_values(self, value: PayloadVrfsAttachmentsLanAttachListE
395395
Serialize extension_values to a JSON string.
396396
"""
397397
if value == "":
398-
return json.dumps({}) # return empty JSON value
398+
return ""
399+
# return json.dumps({}) # return empty JSON value
400+
if len(value.MULTISITE_CONN.MULTISITE_CONN) == 0 and len(value.VRF_LITE_CONN.VRF_LITE_CONN) == 0:
401+
return ""
399402
return value.model_dump_json(by_alias=True)
400403

401404
@field_serializer("instance_values")

plugins/module_utils/vrf/transmute_diff_attach_to_payload.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,14 @@ def commit(self) -> None:
174174

175175
payload_model: list[PayloadVrfsAttachments] = []
176176
for vrf_attach_payload in diff_attach_list:
177-
new_lan_attach_list = self.update_lan_attach_list_model(vrf_attach_payload)
178-
vrf_attach_payload.lan_attach_list = new_lan_attach_list
177+
lan_attach_list = self.update_lan_attach_list_model(vrf_attach_payload)
178+
msg = f"ZZZ: lan_attach_list: {lan_attach_list}"
179+
self.log.debug(msg)
180+
# for item in lan_attach_list:
181+
# if item.extension_values.VRF_LITE_CONN.VRF_LITE_CONN == [] and item.extension_values.MULTISITE_CONN.MULTISITE_CONN == []:
182+
# item.extension_values = ""
183+
vrf_attach_payload.lan_attach_list = lan_attach_list
184+
# vrf_attach_payload.lan_attach_list = self.update_lan_attach_list_model(vrf_attach_payload)
179185
payload_model.append(vrf_attach_payload)
180186

181187
msg = f"Setting payload_model: type(payload_model[0]): {type(payload_model[0])} length: {len(payload_model)}."
@@ -184,6 +190,8 @@ def commit(self) -> None:
184190

185191
self._payload_model = payload_model
186192
self._payload = json.dumps([model.model_dump(exclude_unset=True, by_alias=True) for model in payload_model])
193+
msg = f"Setting payload: {self._payload}"
194+
self.log.debug(msg)
187195

188196
def update_lan_attach_list_model(self, diff_attach: PayloadVrfsAttachments) -> list[PayloadVrfsAttachmentsLanAttachListItem]:
189197
"""
@@ -351,19 +359,19 @@ def update_vrf_attach_vrf_lite_extensions(
351359
352360
## Description
353361
354-
1. Merge the values from the vrf_attach object into a matching
355-
vrf_lite extension object (if any) from the switch.
362+
1. Merge the values from the vrf_attach object into a matching vrf_lite extension object (if any) from the switch.
356363
2. Update the vrf_attach object with the merged result.
357364
3. Return the updated vrf_attach object.
358365
359-
If no matching ControllerResponseVrfsSwitchesExtensionPrototypeValue model is found,
360-
return the unmodified vrf_attach object.
366+
## Raises
367+
368+
- ValueError if:
369+
- No matching ControllerResponseVrfsSwitchesExtensionPrototypeValue model is found, return the unmodified vrf_attach object.
361370
362371
"matching" in this case means:
363372
364373
1. The extensionType of the switch's extension object is VRF_LITE
365-
2. The IF_NAME in the extensionValues of the extension object
366-
matches the interface in vrf_attach.extension_values.
374+
2. The IF_NAME in the extensionValues of the extension object matches the interface in vrf_attach.extension_values.
367375
"""
368376
method_name = inspect.stack()[0][3]
369377
caller = inspect.stack()[1][3]

0 commit comments

Comments
 (0)