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

T6589: Return a dict when querying information about a single interface #3840

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

HollyGurza
Copy link
Contributor

@HollyGurza HollyGurza commented Jul 22, 2024

Change Summary

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)

Related PR(s)

Component(s) name

Proposed changes

How to test

vyos@vyos:~$ sudo /usr/libexec/vyos/op_mode/interfaces.py show_summary --raw --intf-name eth0
{
    "ifname": "eth0",
    "oper_state": "up",
    "admin_state": "up",
    "addr": [
        "192.168.122.166/24"
    ],
    "description": "OUT",
    "mtu": 1500,
    "mac": "0c:89:0a:2e:00:00",
    "vrf": null
}
vyos@vyos:~$ sudo /usr/libexec/vyos/op_mode/interfaces.py show_summary --raw
[
    {
        "ifname": "eth0",
        "oper_state": "up",
        "admin_state": "up",
        "addr": [
            "192.168.122.166/24"
        ],
        "description": "OUT",
        "mtu": 1500,
        "mac": "0c:89:0a:2e:00:00",
        "vrf": null
    },
    {
        "ifname": "eth1",
        "oper_state": "up",
        "admin_state": "up",
        "addr": [
            "10.0.0.1/24"
        ],
        "description": "INSIDE",
        "mtu": 1500,
        "mac": "0c:89:0a:2e:00:01",
        "vrf": null
    },
    {
        "ifname": "eth2",
        "oper_state": "down",
        "admin_state": "up",
        "addr": [],
        "description": "",
        "mtu": 1500,
        "mac": "0c:89:0a:2e:00:02",
        "vrf": null
    },
    {
        "ifname": "eth3",
        "oper_state": "down",
        "admin_state": "up",
        "addr": [],
        "description": "",
        "mtu": 1500,
        "mac": "0c:89:0a:2e:00:03",
        "vrf": null
    },
    {
        "ifname": "lo",
        "oper_state": "unknown",
        "admin_state": "up",
        "addr": [
            "127.0.0.1/8",
            "::1/128"
        ],
        "description": "",
        "mtu": 65536,
        "mac": "00:00:00:00:00:00",
        "vrf": null
    }
]
vyos@vyos# sudo /usr/libexec/vyos/op_mode/interfaces.py show_summary --raw --intf-name eth11
Interface eth11 does not exist

Smoketest result

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

Copy link

github-actions bot commented Jul 22, 2024

👍
No issues in PR Title / Commit Title

Copy link

github-actions bot commented Jul 22, 2024

👍
No issues in unused-imports

@c-po
Copy link
Member

c-po commented Jul 22, 2024

As we return a list of dicts for multiple interfaces, shouldn't we also return an empty list for no interface and also a list for even only one interface?

@HollyGurza
Copy link
Contributor Author

As we return a list of dicts for multiple interfaces, shouldn't we also return an empty list for no interface and also a list for even only one interface?

I think it depends on what we are doing, searching for an object or getting information about a specific object. When we try to get information about a single object return dict looks ok, but when we try to find an object then a better return list with elements even only one or an empty list.
As I understand in this task we try to get information about a specific object, but maybe there will be better to raise an exception instead of return an empty dict when the object non exists

@HollyGurza HollyGurza force-pushed the T6589 branch 2 times, most recently from 3ae1177 to bb4785d Compare July 22, 2024 15:59
Copy link
Member

@dmbaturin dmbaturin left a comment

Choose a reason for hiding this comment

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

@c-po I'm not sure if I understand the point abaout "no interface". When the user queries data about a single named interface and that interface is not found, we raise an exception — trying to retrieve data that doesn't exist should not return an empty list for sure, it should result in an error.

@HollyGurza
Copy link
Contributor Author

for more convenience now i use a similar format for
/usr/libexec/vyos/op_mode/interfaces.py show --raw
/usr/libexec/vyos/op_mode/interfaces.py show_summary --raw
/usr/libexec/vyos/op_mode/interfaces.py show_summary_extended --raw
/usr/libexec/vyos/op_mode/interfaces.py show_counters --raw

return list when we get info for many interfaces
return dict when we get info for specifies interface
raise vyos.opmode.UnconfiguredObject when specified interface don't exist

Copy link

CI integration ❌ failed!

Details

CI logs

  • CLI Smoketests ❌ failed
  • Config tests 👍 passed
  • RAID1 tests 👍 passed

@c-po c-po merged commit 150d7c8 into vyos:current Jul 22, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants