-
Notifications
You must be signed in to change notification settings - Fork 669
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
[generic-config-updater] Handling empty tables while sorting a patch #1923
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,6 +573,35 @@ def _find_ref_paths(self, paths, config): | |
refs.extend(self.path_addressing.find_ref_paths(path, config)) | ||
return refs | ||
|
||
class NoEmptyTableMoveValidator: | ||
""" | ||
A class to validate that a move will not result in an empty table, because empty table do not show up in ConfigDB. | ||
""" | ||
def __init__(self, path_addressing): | ||
self.path_addressing = path_addressing | ||
|
||
def validate(self, move, diff): | ||
simulated_config = move.apply(diff.current_config) | ||
op_path = move.path | ||
|
||
if op_path == "": # If updating whole file | ||
tables_to_check = simulated_config.keys() | ||
else: | ||
tokens = self.path_addressing.get_path_tokens(op_path) | ||
tables_to_check = [tokens[0]] | ||
|
||
return self._validate_tables(tables_to_check, simulated_config) | ||
|
||
def _validate_tables(self, tables, config): | ||
for table in tables: | ||
if not(self._validate_table(table, config)): | ||
return False | ||
return True | ||
|
||
def _validate_table(self, table, config): | ||
is_empty = table in config and not(config[table]) | ||
return not(is_empty) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will look like this: def _validate_table(self, table, config):
return table not in config or config[table] This means the table is either not in config, or table has content. Why does this mean the table is not empty? It will take future developer a while to understand it. I think it is easier to have a flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either way is okay to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [offline discussion] will update and add a small comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
||
class LowLevelMoveGenerator: | ||
""" | ||
A class to generate the low level moves i.e. moves corresponding to differences between current/target config | ||
|
@@ -969,7 +998,8 @@ def create(self, algorithm=Algorithm.DFS): | |
FullConfigMoveValidator(self.config_wrapper), | ||
NoDependencyMoveValidator(self.path_addressing, self.config_wrapper), | ||
UniqueLanesMoveValidator(), | ||
CreateOnlyMoveValidator(self.path_addressing) ] | ||
CreateOnlyMoveValidator(self.path_addressing), | ||
NoEmptyTableMoveValidator(self.path_addressing)] | ||
|
||
move_wrapper = MoveWrapper(move_generators, move_extenders, move_validators) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not need to return bool, you can check
len(empty_tables)
. #ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated