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

configtree: T5251: catch/raise errors in functions delete and delete_value #2023

Merged
merged 2 commits into from
Jun 2, 2023

Conversation

jestabro
Copy link
Contributor

@jestabro jestabro commented May 31, 2023

Change Summary

The functions delete and delete_value should raise ConfigTreeError on a non-zero return value from the respective libvyosconfig functions.

This was a missing case in the implementation; all other functions raise error when appropriate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Component(s) name

Proposed changes

How to test

>>> from vyos.configtree import ConfigTree, ConfigTreeError
>>> with open('/config/config.boot') as f:
...     config_file = f.read()
... 
>>> config = ConfigTree(config_file)
>>> try:
...     config.delete(['interfaces', 'ethernet', 'eth999', 'address'])
... except ConfigTreeError as e:
...     print(e)
... 
Path doesn't exist: ['interfaces', 'ethernet', 'eth999', 'address']
>>> try:
...     config.delete_value(['interfaces', 'ethernet', 'eth0', 'address'], 'foo')
... except ConfigTreeError as e:
...     print(e)
... 
Value doesn't exist: 'foo'

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

Configtree functions delete/delete_value do not check return value of
libvyosconfig functions; raise error on non-zero return value.
The node was already deleted in the 'if path exists' branch; attempt to
delete in 'else' branch will now raise an error.
@jestabro jestabro self-assigned this May 31, 2023
@vyosbot vyosbot requested review from a team, dmbaturin, sarthurdev, zdc, sever-sever and c-po and removed request for a team May 31, 2023 23:28
@sever-sever sever-sever merged commit b8a3dc5 into vyos:current Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants