[config] Add vlan member only after checking RIF is not present#1513
[config] Add vlan member only after checking RIF is not present#1513ghost wants to merge 3 commits intosonic-net:masterfrom
Conversation
* Checking whether the interface port has RIF or not before setting it as a member of the vlan. Only ports and LAGs, which have not RIFs, assigned to them, can be a vlan members. Even if there is no L3 address assigned to the interface, the RIF could be still present, e.g, if static route had created before L3 address deleted. Due to this, data from ASIC_DB and COUNTERS_DB is used for checking. Signed-off-by: Maksym Belei <[email protected]>
* Updating unit tests according to the last changes in the source code. Mocking COUNTERS_DB and ASIC_DB for vlan_test.py from separated input to avoid dependencies between vlan test class and the other classes. Signed-off-by: Maksym Belei <[email protected]>
config/vlan.py
Outdated
|
|
||
| from time import sleep | ||
| from .utils import log | ||
| from swsssdk import port_util |
There was a problem hiding this comment.
no more swsssdk, it is deprecating.
There was a problem hiding this comment.
Got it. I am sorry, but I cannot find an alternate for port_util in swsscommon or any other places. Are there plans to implement something similar to port_util to swsscommon or somewhere else? I see the some scripts are still using port_util. I think the alternative will be useful.
If not, I am going to implement all the necessary directly inside vlan.py.
There was a problem hiding this comment.
As I said before, port_util is still can be useful, so, I decided to copy its implementation to utilities_common of sonic_utilities.
I have found all places in sonic_utilities, where port_util is imported from swsssdk and replaced them to import from utilities_common.
|
@prsunny - FYI |
* As swsssdk in deprecating process, copy port_util from swsssdk to utilities_common and replace all usages of swsssdk.port_util to its copy from utilities_common. Remove redundant parts of code from new port_util. Signed-off-by: Maksym Belei <[email protected]>
|
retest this please |
|
IMO, the existing check is sufficient. I think the reported issue must be handled differently. I've provided my comments in the issue - sonic-net/sonic-buildimage#7028 |
|
@prsunny, I think my changes will be a more robust solution to check whether the port is RIF of not, because it checks the result of deleting of the RIF(absence of the related record in ASIC_DB), rather then checking of records in CONFIG_DB, which represent desirable state of RIFs, but, not guarantee that the RIF is completely deleted, like in case with static route. |
|
Adding static route is not a typical use-case, as we already know that static route is not persisted across reboots. Also the fix cannot be considered complete, as adding such a port to portchannel should also be then returning failure. IMO, it is adding more overhead than simple checking for IP address in config_db. |
What I did
Resolves sonic-net/sonic-buildimage#7028
Updated mechanism how to check is the port has RIF or not before adding it the port to the Vlan.
The related unit tests updated.
Copied implementation of port_util from swsssdk to utilities_common of sonic_utilities. Replaced using of swsssdk to utilities_common.
How I did it
By using functionality of
port_util.pyto check whether a RIF is present for the port in the system.Now, the user can add a member to the Vlan only if there are no router records(
ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:) in ASIC_DB, linked to OID of the interface.How to verify it
The last command will return the next error:
Error: Ethernet0 is a router interface! Check assigned L3 addresses, a related static routes etc.This will delete the route and RIF for the port.
The port will be added successfully,
Previous command output
New command output
Output of command
config vlan member addfor the case is little bit clarified to help user to understand that is going on.