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

[consutil] Remove actual baud and refactor lib for future change #1130

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

Blueve
Copy link
Contributor

@Blueve Blueve commented Sep 24, 2020

- What I did

  • [update] removed actual baud from consutil show result table
  • [refine] ensure only 1 db querying per command
  • [refine] refactor code for better reusing in future
  • [new] add a new return value ERR_CFG for indicating configuration issue

- How I did it

  1. Add new constant ERR_CFG as the bad/missing configuration caused return code
  2. Refactor code structure, include standardize the method naming/remove unnecessary methods/extract methods for future reusing

- How to verify it

Build a deb and test it on a physical DUT with following CONSOLE_PORT configuration:

    "CONSOLE_PORT": {
        "1": {
            "remote_device": "switch1",
            "baud_rate": "9600",
            "flow_control": "1"
        }
    }

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

admin@sonic:~$ sudo consutil show
  Line    Actual/Configured Baud    PID    Start Time    Device
------  ------------------------  -----  ------------  --------
     0      9600/-                                            -
     1      9600/9600                                   switch1
     2      9600/-                                            -
     3      9600/-                                            -
     4      9600/-                                            -
     5      9600/-                                            -
     6      9600/-                                            -
     7      9600/-                                            -
     8      9600/-                                            -
     9      9600/-                                            -
    10      9600/-                                            -
    11      9600/-                                            -
    12      9600/-                                            -
    13      9600/-                                            -
    14      9600/-                                            -
    15      9600/-                                            -
    16      9600/-                                            -
    17      9600/-                                            -
    18      9600/-                                            -
    19      9600/-                                            -
    20      9600/-                                            -
    21      9600/-                                            -
    22      9600/-                                            -
    23      9600/-                                            -
    24      9600/-                                            -
    25      9600/-                                            -
    26      9600/-                                            -
    27      9600/-                                            -
    28      9600/-                                            -
    29      9600/-                                            -
    30      9600/-                                            -
    31      9600/-                                            -
    32      9600/-                                            -
    33      9600/-                                            -
    34      9600/-                                            -
    35      9600/-                                            -
    36      9600/-                                            -
    37      9600/-                                            -
    38      9600/-                                            -
    39      9600/-                                            -
    40      9600/-                                            -
    41      9600/-                                            -
    42      9600/-                                            -
    43      9600/-                                            -
    44      9600/-                                            -
    45      9600/-                                            -
    46      9600/-                                            -
    47      9600/-                                            -

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

admin@sonic:~$ sudo consutil show
  Line    Baud    PID    Start Time    Device
------  ------  -----  ------------  --------
     0       -                              -
     1    9600                        switch1
     2       -                              -
     3       -                              -
     4       -                              -
     5       -                              -
     6       -                              -
     7       -                              -
     8       -                              -
     9       -                              -
    10       -                              -
    11       -                              -
    12       -                              -
    13       -                              -
    14       -                              -
    15       -                              -
    16       -                              -
    17       -                              -
    18       -                              -
    19       -                              -
    20       -                              -
    21       -                              -
    22       -                              -
    23       -                              -
    24       -                              -
    25       -                              -
    26       -                              -
    27       -                              -
    28       -                              -
    29       -                              -
    30       -                              -
    31       -                              -
    32       -                              -
    33       -                              -
    34       -                              -
    35       -                              -
    36       -                              -
    37       -                              -
    38       -                              -
    39       -                              -
    40       -                              -
    41       -                              -
    42       -                              -
    43       -                              -
    44       -                              -
    45       -                              -
    46       -                              -
    47       -                              -

@Blueve Blueve requested a review from yxieca September 24, 2020 05:54
pid, _ = busyDevices[linenum]
busyLines = getBusyLines()
if lineNumber in busyLines:
pid, _ = busyLines[lineNumber]
cmd = "sudo kill -SIGTERM " + pid
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we need to add some more check there before sending that kill signal.

What if we have a pid logged in db but somehow process quit didn't clear the db. However, some critical process took the PID. Blindly sending the kill could be dangerous. @jleveque what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

This comments doesn't block this PR. If change needed, the change can come with a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yxieca: Adding a check to ensure the PID is still assigned to the expected process is probably a good idea to add in a future PR. It definitely wouldn't hurt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, totally agree.

Currently, it is safe to clear it by the PID because the PID were extract from PS command.
The check will be necessary after I introduced STATE_DB.
I will add checks in future PR. Thanks for comments

@Blueve Blueve merged commit 49f1634 into sonic-net:master Sep 25, 2020
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.

3 participants