Skip to content

Conversation

md-rafeek
Copy link
Collaborator

@md-rafeek md-rafeek commented Aug 18, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

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:

  • Manual testing
  • Unit tests
  • Integration tests

Test cases covered: [Mention test case IDs or brief points]

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • All the sanity checks have been completed and the sanity test cases have been executed

Ansible Best Practices

  • Tasks are idempotent (can be run multiple times without changing state)
  • Variables and secrets are handled securely (e.g., using ansible-vault or environment variables)
  • Playbooks are modular and reusable
  • Handlers are used for actions that need to run on change

Documentation

  • All options and parameters are documented clearly.
  • Examples are provided and tested.
  • Notes and limitations are clearly stated.

Screenshots (if applicable)

Notes to Reviewers

devices_to_add (list): A list of devices to be added.

Returns:
object: An instance of the class with updated results and status.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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..

Copy link
Collaborator Author

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
)
Copy link
Collaborator

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?

Copy link
Collaborator Author

@md-rafeek md-rafeek Aug 27, 2025

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

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
Copy link
Collaborator

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..

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@md-rafeek md-rafeek left a 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.
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
)
Copy link
Collaborator Author

@md-rafeek md-rafeek Aug 27, 2025

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@md-rafeek md-rafeek left a 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
Copy link
Collaborator Author

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:
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@md-rafeek md-rafeek left a 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:
Copy link
Collaborator Author

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

Copy link
Collaborator

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..

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@md-rafeek md-rafeek left a 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

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants