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

[generic-config-updater] Adding logging to config-{replace, rollback, checkpoint, list-checkpoints} #1885

Merged
merged 2 commits into from
Nov 11, 2021

Conversation

ghooo
Copy link
Contributor

@ghooo ghooo commented Oct 18, 2021

What I did

Adding more logging to other CLI commands config replace, config rollback, config checkpoint, config list-checkpoints and config delete-checkpoint

How I did it

How to verify it

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Example of config replace without and with -v option

admin@vlab-01:~$ sudo config replace target.json 
Config Replacer: Config replacement starting.
Config Replacer: Target config length: 56594.
Config Replacer: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Replacer: Getting current config db.
Config Replacer: Generating patch between target config and current config db.
Config Replacer: Applying patch using 'Patch Applier'.
Patch Applier: Patch application starting.
Patch Applier: Patch: []
Patch Applier: Validating patch is not making changes to tables without YANG models.
Patch Applier: Getting current config db.
Patch Applier: Simulating the target full config after applying the patch.
Patch Applier: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Patch Applier: Sorting patch updates.
... [logs from sonic-yang-mgmt]
Patch Applier: The patch was sorted into 0 changes.
Patch Applier: Applying changes in order.
Patch Applier: Verifying patch updates are reflected on ConfigDB.
Patch Applier: Patch application completed.
Config Replacer: Verifying config replacement is reflected on ConfigDB.
Config Replacer: Config replacement completed.
Config replaced successfully.
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config replace target.json -v
Config Replacer: Config replacement starting.
Config Replacer: Target config length: 56594.
Config Replacer: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Replacer: Getting current config db.
Config Replacer: Generating patch between target config and current config db.
Config Replacer: Generated patch: [].
Config Replacer: Applying patch using 'Patch Applier'.
Patch Applier: Patch application starting.
Patch Applier: Patch: []
Patch Applier: Validating patch is not making changes to tables without YANG models.
Patch Applier: Getting current config db.
Patch Applier: Simulating the target full config after applying the patch.
Patch Applier: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Patch Applier: Sorting patch updates.
... [logs from sonic-yang-mgmt]
Patch Applier: The patch was sorted into 0 changes.
Patch Applier: Applying changes in order.
Patch Applier: Verifying patch updates are reflected on ConfigDB.
Patch Applier: Patch application completed.
Config Replacer: Verifying config replacement is reflected on ConfigDB.
Config Replacer: Config replacement completed.
Config replaced successfully.
admin@vlab-01:~$

Examples of config checkpoint without and with -v option

admin@vlab-01:~$ sudo config checkpoint cp1
Config Rollbacker: Config checkpoint starting.
Config Rollbacker: Checkpoint name: cp1.
Config Rollbacker: Getting current config db.
Config Rollbacker: Validating current config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Rollbacker: Getting checkpoint full-path.
Config Rollbacker: Ensuring checkpoint directory exist.
Config Rollbacker: Saving config db content to /etc/sonic/checkpoints/cp1.cp.json.
Config Rollbacker: Config checkpoint completed.
Checkpoint created successfully.
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config checkpoint cp1 -v
Config Rollbacker: Config checkpoint starting.
Config Rollbacker: Checkpoint name: cp1.
Config Rollbacker: Getting current config db.
Config Rollbacker: Validating current config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Rollbacker: Getting checkpoint full-path.
Config Rollbacker: Ensuring checkpoint directory exist.
Config Rollbacker: Saving config db content to /etc/sonic/checkpoints/cp1.cp.json.
Config Rollbacker: Config checkpoint completed.
Checkpoint created successfully.
admin@vlab-01:~$ 

Examples of config rollback without and with -v option:

admin@vlab-01:~$ sudo config rollback cp1
Config Rollbacker: Config rollbacking starting.
Config Rollbacker: Checkpoint name: cp1.
Config Rollbacker: Verifying 'cp1' exists.
Config Rollbacker: Loading checkpoint into memory.
Config Rollbacker: Replacing config using 'Config Replacer'.
Config Replacer: Config replacement starting.
Config Replacer: Target config length: 56594.
Config Replacer: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Replacer: Getting current config db.
Config Replacer: Generating patch between target config and current config db.
Config Replacer: Applying patch using 'Patch Applier'.
Patch Applier: Patch application starting.
Patch Applier: Patch: []
Patch Applier: Validating patch is not making changes to tables without YANG models.
Patch Applier: Getting current config db.
Patch Applier: Simulating the target full config after applying the patch.
Patch Applier: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Patch Applier: Sorting patch updates.
... [logs from sonic-yang-mgmt]
Patch Applier: The patch was sorted into 0 changes.
Patch Applier: Applying changes in order.
Patch Applier: Verifying patch updates are reflected on ConfigDB.
Patch Applier: Patch application completed.
Config Replacer: Verifying config replacement is reflected on ConfigDB.
Config Replacer: Config replacement completed.
Config Rollbacker: Config rollbacking completed.
Config rolled back successfully.
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config rollback cp1 -v
Config Rollbacker: Config rollbacking starting.
Config Rollbacker: Checkpoint name: cp1.
Config Rollbacker: Verifying 'cp1' exists.
Config Rollbacker: Loading checkpoint into memory.
Config Rollbacker: Replacing config using 'Config Replacer'.
Config Replacer: Config replacement starting.
Config Replacer: Target config length: 56594.
Config Replacer: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Config Replacer: Getting current config db.
Config Replacer: Generating patch between target config and current config db.
Config Replacer: Generated patch: [].
Config Replacer: Applying patch using 'Patch Applier'.
Patch Applier: Patch application starting.
Patch Applier: Patch: []
Patch Applier: Validating patch is not making changes to tables without YANG models.
Patch Applier: Getting current config db.
Patch Applier: Simulating the target full config after applying the patch.
Patch Applier: Validating target config according to YANG models.
... [logs from sonic-yang-mgmt]
Patch Applier: Sorting patch updates.
... [logs from sonic-yang-mgmt]
Patch Applier: The patch was sorted into 0 changes.
Patch Applier: Applying changes in order.
Patch Applier: Verifying patch updates are reflected on ConfigDB.
Patch Applier: Patch application completed.
Config Replacer: Verifying config replacement is reflected on ConfigDB.
Config Replacer: Config replacement completed.
Config Rollbacker: Config rollbacking completed.
Config rolled back successfully.
admin@vlab-01:~$ 

Examples of list-checkpoints without and with -v option, and for different numbers of checkpoints:

admin@vlab-01:~$ sudo config list-checkpoints
[
    "cp1",
    "cp2"
]
admin@vlab-01:~$ sudo config list-checkpoints -v
Config Rollbacker: Listing checkpoints starting.
Config Rollbacker: Verifying checkpoints directory '/etc/sonic/checkpoints' exists.
Config Rollbacker: Getting checkpoints in checkpoints directory.
Config Rollbacker: Found 2 checkpoints:
Config Rollbacker:   * cp1
Config Rollbacker:   * cp2
Config Rollbacker: Listing checkpoints completed.
[
    "cp1",
    "cp2"
]
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config list-checkpoints
[
    "cp1"
]
admin@vlab-01:~$ sudo config list-checkpoints -v
Config Rollbacker: Listing checkpoints starting.
Config Rollbacker: Verifying checkpoints directory '/etc/sonic/checkpoints' exists.
Config Rollbacker: Getting checkpoints in checkpoints directory.
Config Rollbacker: Found 1 checkpoint:
Config Rollbacker:   * cp1
Config Rollbacker: Listing checkpoints completed.
[
    "cp1"
]
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config list-checkpoints
[]
admin@vlab-01:~$ 
admin@vlab-01:~$ sudo config list-checkpoints -v
Config Rollbacker: Listing checkpoints starting.
Config Rollbacker: Verifying checkpoints directory '/etc/sonic/checkpoints' exists.
Config Rollbacker: Getting checkpoints in checkpoints directory.
Config Rollbacker: Found 0 checkpoints.
Config Rollbacker: Listing checkpoints completed.
[]
admin@vlab-01:~$ 

Examples of delete-checkpoint without and with -v option:

admin@vlab-01:~$ sudo config delete-checkpoint cp1
Config Rollbacker: Deleting checkpoint starting.
Config Rollbacker: Checkpoint name: cp1.
Config Rollbacker: Checking checkpoint exists.
Config Rollbacker: Deleting checkpoint.
Config Rollbacker: Deleting checkpoint completed.
Checkpoint deleted successfully.
admin@vlab-01:~$
admin@vlab-01:~$ sudo config delete-checkpoint cp2 -v
Config Rollbacker: Deleting checkpoint starting.
Config Rollbacker: Checkpoint name: cp2.
Config Rollbacker: Checking checkpoint exists.
Config Rollbacker: Deleting checkpoint.
Config Rollbacker: Deleting checkpoint completed.
Checkpoint deleted successfully.
admin@vlab-01:~$ 

self.patch_applier = patch_applier if patch_applier is not None else PatchApplier()
self.config_wrapper = config_wrapper if config_wrapper is not None else ConfigWrapper()
self.patch_wrapper = patch_wrapper if patch_wrapper is not None else PatchWrapper()

def replace(self, target_config):
print_to_console=True
self.logger.log_notice("Config replacement starting.", print_to_console)
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 19, 2021

Choose a reason for hiding this comment

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

print_to_console

It seems that you often want to print_to_console consistently per class. I am wondering if you can add it as a get_logger optional prameter, and the default value is None. If provide True or False, it will override each log_* option. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

I simplified the flag to print_all_to_console which is passed to get_logger.

If print_all_to_console is True: all lines are printed regardless of the input flag to log_* methods.
If print_all_to_console is False: all lines are printed according to the input flag to log_* methods.

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

Minor issue. Others lgtm.

@qiluo-msft
Copy link
Contributor

Could you make "More logging" in title more descriptive?

@ghooo ghooo changed the title [generic-config-updater] More logging [generic-config-updater] Adding logging to config-{replace, rollback, checkpoint, list-checkpoints} Nov 11, 2021
@qiluo-msft qiluo-msft merged commit 4bcaa60 into sonic-net:master Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants