Skip to content

[breakout] Fix the check when port is not present in BREAKOUT_CFG table #1765

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

Merged
merged 1 commit into from
Dec 24, 2021

Conversation

samaity
Copy link
Contributor

@samaity samaity commented Aug 16, 2021

Signed-off-by: Sangita Maity [email protected]

What I did

This PR fixed issue for show interface breakout issue

Before this fix
removed Ethernet60 from breakout_cfg table for unit testing and got the issue

 
admin@lnos-x1-a-asw04:~$ sudo redis-cli -n 4 del "BREAKOUT_CFG|Ethernet60"
(integer) 1
admin@lnos-x1-a-asw04:~$ sudo redis-cli -n 4 hgetall "BREAKOUT_CFG|Ethernet60"
(empty array)
admin@lnos-x1-a-asw04:~$ show int breakout
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1114, in invoke
    return Command.invoke(self, ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/show/interfaces/__init__.py", line 181, in breakout
    cur_brkout_mode = cur_brkout_tbl[port_name]["brkout_mode"]
KeyError: 'Ethernet60'

After the fix


admin@lnos-x1-a-asw04:~$ show int breakout current-mode Ethernet60
+-------------+-------------------------+
| Interface   | Current Breakout Mode   |
+=============+=========================+
| Ethernet60  | Not Available           |
+-------------+-------------------------+

How I did it

Gracefully handle the error when port/interface is not present in BREAKOUT_CFG table.

How to verify it

show interface breakout 
show int interface current-mode

Added unit test case for negetive Test case

@lgtm-com
Copy link

lgtm-com bot commented Aug 16, 2021

This pull request introduces 1 alert when merging 66e72005a19202f3567e829f68b10a4931f494d8 into 7821a3f - view on LGTM.com

new alerts:

  • 1 for Syntax error

@samaity samaity force-pushed the show_breakout_fix branch from 66e7200 to edf5885 Compare August 16, 2021 21:23
@dprital
Copy link
Collaborator

dprital commented Dec 16, 2021

@zhenggen-xu Can you please review ?

@dprital dprital requested a review from lguohan December 16, 2021 16:06
@dgsudharsan
Copy link
Collaborator

@lguohan @zhenggen-xu Can you please review and signoff?
@samaity Please sync to the latest

zhenggen-xu
zhenggen-xu previously approved these changes Dec 21, 2021
@samaity
Copy link
Contributor Author

samaity commented Dec 21, 2021

@lguohan @zhenggen-xu Can you please review and signoff? @samaity Please sync to the latest

done 👍

@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft merged commit 8c81ae3 into sonic-net:master Dec 24, 2021
judyjoseph pushed a commit that referenced this pull request Jan 9, 2022
…le (#1765)

#### What I did

This PR fixed issue for [show interface breakout](sonic-net/sonic-buildimage#7957) issue

**Before this fix**
removed `Ethernet60` from breakout_cfg table for unit testing and got the issue
```
 
admin@lnos-x1-a-asw04:~$ sudo redis-cli -n 4 del "BREAKOUT_CFG|Ethernet60"
(integer) 1
admin@lnos-x1-a-asw04:~$ sudo redis-cli -n 4 hgetall "BREAKOUT_CFG|Ethernet60"
(empty array)
admin@lnos-x1-a-asw04:~$ show int breakout
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1114, in invoke
    return Command.invoke(self, ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/show/interfaces/__init__.py", line 181, in breakout
    cur_brkout_mode = cur_brkout_tbl[port_name]["brkout_mode"]
KeyError: 'Ethernet60'

```

**After the fix**
```

admin@lnos-x1-a-asw04:~$ show int breakout current-mode Ethernet60
+-------------+-------------------------+
| Interface   | Current Breakout Mode   |
+=============+=========================+
| Ethernet60  | Not Available           |
+-------------+-------------------------+
```
#### How I did it
Gracefully handle the error when port/interface is not present in `BREAKOUT_CFG` table.

#### How to verify it
```
show interface breakout 
show int interface current-mode

```
**_Added unit test case for negetive Test case_**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants