Skip to content
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

Add functionality for handling varbind errors in get command #262

Merged
merged 6 commits into from
Jun 24, 2024

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Jun 20, 2024

Work towards fixing #261 and #212

Adds function that takes an ObjectType and raises a relevant exception if it contains an error instead of a real value. I refer to this type of error as varbind errors since they are not defined via errorStatus or errorIndication, but are defined as values inside the response varbind

This PR makes use of the new function in the get command, but should be used for all the different commands. That can be done in other PRs once this one is completed.

To fully fix #212, some changes have to be made to the juniperalarmtask, including reverting some changes made in #231.
Handling of the new errors should also be added. NoSuchObjectError is definitely relevant, but maybe NoSuchInstanceError is too? Im not too sure about the difference about these two.. I'll leave @johannaengland to complete this task

Also sneakily fixes ErrorIndication not inheriting correctly (an SNMP related exception should probably inherit from the exception specifically made to be a base exception for everything SNMP related...)

Also2, there's quite a few SNMP specific exception classes now, thoughts on putting them in their own file?

Copy link

github-actions bot commented Jun 20, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 2 0 0.59s
✅ PYTHON isort 2 0 0.22s
✅ PYTHON ruff 2 0 0.01s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@stveit stveit changed the title Handle varbind errors for get command Add functionality for handling errors in varbinds Jun 20, 2024
Copy link

github-actions bot commented Jun 20, 2024

Test results

    3 files      3 suites   52s ⏱️
  388 tests   388 ✅ 0 💤 0 ❌
1 164 runs  1 162 ✅ 2 💤 0 ❌

Results for commit e940301.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.04%. Comparing base (3f7bc0f) to head (e940301).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #262   +/-   ##
=======================================
  Coverage   99.03%   99.04%           
=======================================
  Files          50       50           
  Lines        6735     6750   +15     
=======================================
+ Hits         6670     6685   +15     
  Misses         65       65           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stveit stveit self-assigned this Jun 20, 2024
@stveit stveit force-pushed the fix/missing-object-not-raising-error branch from 7f51422 to 33d036b Compare June 20, 2024 16:02
@stveit stveit changed the title Add functionality for handling errors in varbinds Add functionality for handling varbind errors in get command Jun 20, 2024
@stveit stveit force-pushed the fix/missing-object-not-raising-error branch from 33d036b to c4c2900 Compare June 20, 2024 16:09
@stveit stveit force-pushed the fix/missing-object-not-raising-error branch from 1292d62 to e940301 Compare June 20, 2024 16:21
@lunkwill42
Copy link
Member

Work towards fixing #261 and #212

Adds function that takes an ObjectType and raises a relevant exception if it contains an error instead of a real value. I refer to this type of error as varbind errors since they are not defined via errorStatus or errorIndication, but are defined as values inside the response varbind

This PR makes use of the new function in the get command, but should be used for all the different commands. That can be done in other PRs once this one is completed.

To fully fix #212, some changes have to be made to the juniperalarmtask, including reverting some changes made in #231. Handling of the new errors should also be added. NoSuchObjectError is definitely relevant, but maybe NoSuchInstanceError is too? Im not too sure about the difference about these two.. I'll leave @johannaengland to complete this task

Also sneakily fixes ErrorIndication not inheriting correctly (an SNMP related exception should probably inherit from the exception specifically made to be a base exception for everything SNMP related...)

Also2, there's quite a few SNMP specific exception classes now, thoughts on putting them in their own file?

@lunkwill42 lunkwill42 closed this Jun 24, 2024
@lunkwill42 lunkwill42 reopened this Jun 24, 2024
@lunkwill42 lunkwill42 self-requested a review June 24, 2024 13:42
Copy link

sonarcloud bot commented Jun 24, 2024

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes use of the new function in the get command, but should be used for all the different commands. That can be done in other PRs once this one is completed.

Not necessarily. In cases where the client code expects to fetch multiple values using a single operation, the client may be fine with some of the return values being errors. The client might want to keep the successfully retrieved values and make decisions about changing its queries for failed values.

This could also be a flag to a method that retrieves multiple values. The default could be to raise exceptions, but if the calling code wants to handle error values in custom ways, it could set a flag, asking the library to stay out of its business.

Also sneakily fixes ErrorIndication not inheriting correctly (an SNMP related exception should probably inherit from the exception specifically made to be a base exception for everything SNMP related...)

👍

Also2, there's quite a few SNMP specific exception classes now, thoughts on putting them in their own file?

Sure, I'd support that - but the likely cleanup here would be to split zino/snmp.py into zino/snmp/__init__.py and zino/snmp/errors.py.

@stveit stveit merged commit 6eca215 into master Jun 24, 2024
17 checks passed
@johannaengland johannaengland deleted the fix/missing-object-not-raising-error branch June 25, 2024 06:41
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.

Alarm count is not int
2 participants