Skip to content

Commit 1723206

Browse files
authored
[GCU] Turning port admin down before some critical port changes (sonic-net#1998)
#### What I did Fixes sonic-net#1930 Issue can be summarized into these 2 case: * A patch can contain an operation to turn port `admin up` -- do at the end * A patch that modifies config that needs the port to be down -- start by bringing the port down then do the update then bring it back up #### How I did it The configs that need the port to be down, we will call them `critical-port` configs. * Added a move validator to validate `critical-port` configs, which does the following * If a port is up, make sure the move does not make changes to related `critical-port` configs * If the move is turning a port up, make sure there is no `critical-port` config are still left in the patch * Added a move extender to `critical-port` changes: * If a port is up, bring down if there are critical-port changes * If the move is turning a port up, flip it to down if there are still `critical-port` configs left. In other words, do not turn the port back up until all `critical-port` changes are in done. #### How to verify it * Added `AddRack` unit-test to `tests/generic_config_updater/files/patch_sorter_test_success.json` * Other unit-tests #### Previous command output (if the output of a command-line utility has changed) Check issue sonic-net#1930 for old sorting order #### New command output (if the output of a command-line utility has changed) Check `AddRack` unit-test to `tests/generic_config_updater/files/patch_sorter_test_success.json` for new sorting-order
1 parent 15670bf commit 1723206

File tree

5 files changed

+3162
-43
lines changed

5 files changed

+3162
-43
lines changed

generic_config_updater/gu_common.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ def create_path(self, tokens):
273273
return JsonPointer.from_parts(tokens).path
274274

275275
def has_path(self, doc, path):
276-
return JsonPointer(path).get(doc, default=None) is not None
276+
return self.get_from_path(doc, path) is not None
277+
278+
def get_from_path(self, doc, path):
279+
return JsonPointer(path).get(doc, default=None)
280+
281+
def is_config_different(self, path, current, target):
282+
return self.get_from_path(current, path) != self.get_from_path(target, path)
277283

278284
def get_xpath_tokens(self, xpath):
279285
"""
@@ -548,7 +554,8 @@ def _get_xpath_tokens_from_leaf(self, model, token_index, path_tokens, config):
548554
# Source: Check examples in https://netopeer.liberouter.org/doc/libyang/master/html/howto_x_path.html
549555
return [f"{token}[.='{value}']"]
550556

551-
raise ValueError("Token not found")
557+
raise ValueError(f"Path token not found.\n model: {model}\n token_index: {token_index}\n " + \
558+
f"path_tokens: {path_tokens}\n config: {config}")
552559

553560
def _extractKey(self, tableKey, keys):
554561
keyList = keys.split()
@@ -712,7 +719,8 @@ def _get_path_tokens_from_leaf(self, model, token_index, xpath_tokens, config):
712719
list_idx = list_config.index(leaf_list_value)
713720
return [leaf_list_name, list_idx]
714721

715-
raise Exception("no leaf")
722+
raise ValueError(f"Xpath token not found.\n model: {model}\n token_index: {token_index}\n " + \
723+
f"xpath_tokens: {xpath_tokens}\n config: {config}")
716724

717725
def _extract_key_dict(self, list_token):
718726
# Example: VLAN_MEMBER_LIST[name='Vlan1000'][port='Ethernet8']

0 commit comments

Comments
 (0)