Update parsing of ip addr show (SC-723)#1183
Conversation
Newer versions of "ip addr show" include a metric on the inet line. Parse this while also keeping backwards compatibility.
|
pytest parametrization doesn't work with the base class, so I removed the base class from the tests. The only functional test change is in |
| @@ -0,0 +1,12 @@ | |||
| 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 | |||
| link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
| inet 127.0.0.1/8 scope host lo\ valid_lft forever preferred_lft forever | |||
There was a problem hiding this comment.
Are the backslashes on lines 3 and 4 a typo?
There was a problem hiding this comment.
I just copied the sample-ipaddrshow-output file and added the metric part
There was a problem hiding this comment.
I see, nevermind. It doesn't matter what it says after scope since the regex ends with .*.
| r"\s+inet\s(?P<cidr4>\S+)(\sbrd\s(?P<bcast>\S+))?\sscope\s" | ||
| r"(?P<scope>\S+).*", | ||
| r"\s+inet\s(?P<cidr4>\S+)" | ||
| r"(\smetric\s(?P<metric>\d+))?" |
There was a problem hiding this comment.
I did a little bit of manual testing with this regex and didn't spot any issues.
There was a problem hiding this comment.
The bigger this regex gets, the more it makes me question whether we should really be extending a fragile regex parsing of human-readable output of ip. While I originally weighed in to the contrary because cloud-init is supported even more broadly than just Ubuntu, I think it would probably be preferable given that we attempt to try ip -json format first, and fallback to the legacy parsing if -json param is not present. This way most of the latest *nix distros with recent ip tooling can benefit from simple parsing of machine-readable output and any older distributions will continue to parse correctly with the older ip tooling and output formats.
|
Is there a reason you are not parsing the output of 'ip -json addr show' instead? |
|
@mwhudson It was proposed, but we decided against it due to lack of availability everywhere. |
Ah yes I see it's not supported in xenial. |
|
Closing in favor of #1210 |
Proposed Commit Message
Additional Context
Example
ip addr showon Jammy:Notice the
metric 100on the inet line.Test Steps
Can be seen in jammy integration tests on LXD as a new unexpected warning.
Checklist: