-
Notifications
You must be signed in to change notification settings - Fork 5
Inventory Workflow - Compute device related changes updated #293
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
base: main
Are you sure you want to change the base?
Inventory Workflow - Compute device related changes updated #293
Conversation
devices_to_add (list): A list of devices to be added. | ||
|
||
Returns: | ||
object: An instance of the class with updated results and status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any return values from the API.. Can you check and update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the self as return
device_params (dict): A dictionary containing device parameters. | ||
|
||
Returns: | ||
dict: A dictionary containing parsed compute device parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not returning any values.. can you check and update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return not required because we are just parsing the param to to device_params also it is passing from outside. i have added device_params as return now
"DEBUG", | ||
) | ||
self.cred_updated_not_required.append(device_ip) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Docstring you mentioned as
Returns:
dict: A dictionary containing parsed network device parameters for update.
But not returning anything from here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as return device param, and playbook param
if not playbook_params["snmpRwCommunity"]: | ||
playbook_params["snmpRwCommunity"] = device_data.get( | ||
"snmp_write_community", None | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have any return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated playbook param as return
…talyst-center-ansible-intg into inventory_workflow_manager
self.msg = "Required parameter 'snmpROCommunity' for adding device with snmmp version v2 is not present" | ||
self.result["response"] = self.msg | ||
self.log(self.msg, "ERROR") | ||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning self here..but in else part.. it is not returning anything..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually return not required. but if the SNMP param not available for V2 version need to fail and exit. added the device_params as return below.
…talyst-center-ansible-intg into inventory_workflow_manager
…talyst-center-ansible-intg into inventory_workflow_manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed Code review comments.
device_params (dict): A dictionary containing device parameters. | ||
|
||
Returns: | ||
dict: A dictionary containing parsed compute device parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return not required because we are just parsing the param to to device_params also it is passing from outside. i have added device_params as return now
devices_to_add (list): A list of devices to be added. | ||
|
||
Returns: | ||
object: An instance of the class with updated results and status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the self as return
self.msg = "Required parameter 'snmpROCommunity' for adding device with snmmp version v2 is not present" | ||
self.result["response"] = self.msg | ||
self.log(self.msg, "ERROR") | ||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually return not required. but if the SNMP param not available for V2 version need to fail and exit. added the device_params as return below.
"DEBUG", | ||
) | ||
self.cred_updated_not_required.append(device_ip) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as return device param, and playbook param
if not playbook_params["snmpRwCommunity"]: | ||
playbook_params["snmpRwCommunity"] = device_data.get( | ||
"snmp_write_community", None | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated playbook param as return
device_params.pop("snmpPrivPassphrase", None) | ||
device_params.pop("snmpPrivProtocol", None) | ||
|
||
return device_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still not clear. We are returning 'device_params', yet in the if statement, we are returning self. Could you please check and update the entire code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was splitting from large function to small, this is function used to parse and remove unwanted values from "device_params" we are passing "device_params" as argument, any required values in param is missing then need to show failed return. the same updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address the review comments
device_params.pop("snmpPrivPassphrase", None) | ||
device_params.pop("snmpPrivProtocol", None) | ||
|
||
return device_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was splitting from large function to small, this is function used to parse and remove unwanted values from "device_params" we are passing "device_params" as argument, any required values in param is missing then need to show failed return. the same updated.
self.log(self.msg, "ERROR") | ||
self.fail_and_exit(self.msg) | ||
|
||
while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add sleep
Also add a code to come out of while, otherwise it will be in continuous loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the sleep and exit while statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed code review comments.
self.log(self.msg, "ERROR") | ||
self.fail_and_exit(self.msg) | ||
|
||
while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the sleep and exit while statement.
self.log(self.msg, "ERROR") | ||
self.result["response"] = self.msg | ||
break | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a log message before sleep..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the Sleep log message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address Sleep log message.
self.log(self.msg, "ERROR") | ||
self.result["response"] = self.msg | ||
break | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the Sleep log message.
…talyst-center-ansible-intg into inventory_workflow_manager
Type of Change
Description
As per the bug, when a new compute device was added to the inventory with only the required fields, it threw an error because the code did not separate compute devices. This has now been fixed.
Bug Fix:
The bug was raised when adding a compute device to the inventory with only the required fields. It failed earlier, but the issue is now resolved.
Root Cause (if applicable):
The code did not properly separate compute device types, so SNMP parameters for network devices were also being added to compute devices.
Fix Implemented:
The code was updated to correctly separate compute devices and network devices, and some cognitive complexity was reduced.
Enhancement: [Brief description of the improvement/enhancement made]
Enhancement Description: [Explain what was enhanced, why, and how]
Impact Area: [Mention which part of the system/codebase is affected]
Testing Done:
Test cases covered: [Mention test case IDs or brief points]
Checklist
Ansible Best Practices
ansible-vault
or environment variables)Documentation
Screenshots (if applicable)
Notes to Reviewers