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

[unit test][pfcwd] Fix tests that require sudo access #1340

Merged
merged 2 commits into from
Dec 29, 2020

Conversation

smaheshm
Copy link
Contributor

@smaheshm smaheshm commented Dec 28, 2020

- What I did
The 'config' tests that require sudo access were failing. Fixed it by mocking os.geteuid.

- How I did it
Fixed it my mocking os.geteuid.

- How to verify it
Unit tests and manual verification

before:

samaddik@856d790db1d1:/sonic/src/sonic-utilities/tests$ pytest-3 pfcwd_test.py  -k test_pfcwd_start_actions_masic
>       assert result.exit_code == 0                                                                                                                                                                                                         |
E       AssertionError: assert 1 == 0                                                                                                                                                                                                        |
E        +  where 1 = <Result SystemExit('Root privileges are required for this operation')>.exit_code                                                                                                                                       |
                                                                                                                                                                                                                                             |
pfcwd_test.py:335: AssertionError                                                                                                                                                                                                            |
----------------------------------------------------------------------------------------------------------- Captured stdout setup -----------------------------------------------------------------------------------------------------------|
SETUP                                                                                                                                                                                                                                        |
----------------------------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------------------------|
Changed polling interval to 199ms on asic0                                                                                                                                                                                                   |
BIG_RED_SWITCH status is enable on asic0                                                                                                                                                                                                     |
Changed polling interval to 199ms on asic1                                                                                                                                                                                                   |
BIG_RED_SWITCH status is enable on asic1                                                                                                                                                                                                     |
          PORT    ACTION    DETECTION TIME    RESTORATION TIME                                                                                                                                                                               |
--------------  --------  ----------------  ------------------                                                                                                                                                                               |
     Ethernet0      drop               200                 200                                                                                                                                                                               |
     Ethernet4      drop               200                 200                                                                                                                                                                               |
  Ethernet-BP0      drop               200                 200                                                                                                                                                                               |
  Ethernet-BP4      drop               200                 200                                                                                                                                                                               |
Ethernet-BP256      drop               200                 200                                                                                                                                                                               |
Ethernet-BP260      drop               200                 200                                                                                                                                                                               |
                                                                                                                                                                                                                                             |
Root privileges are required for this operation                                                                                                                                                                                              |
                                                                                                                                                                                                                                             |
--------------------------------------------------------------------------------------------------------- Captured stdout teardown ----------------------------------------------------------------------------------------------------------|
TEARDOWN                                                                                                                                                                                                                                     |
================================================================================================== 1 failed, 17 deselected in 0.18 seconds ==================================================================================================|

After:
============================================================================================================ test session starts ============================================================================================================|
platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /sonic/src/sonic-utilities/tests, inifile: pytest.ini
plugins: cov-2.6.0
collected 18 items / 17 deselected                                                                                                                                                                                                          

pfcwd_test.py .                                                                                                                                                                                                                       [100%]

================================================================================================== 1 passed, 17 deselected in 0.22 seconds ==================================================================================================

samaddik@856d790db1d1:/sonic/src/sonic-utilities/tests$ pytest-3 pfcwd_test.py -k test_pfcwd_start_actions_masic

- 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)

lguohan
lguohan previously approved these changes Dec 28, 2020
@@ -3,6 +3,8 @@
import sys

from click.testing import CliRunner
from unittest.mock import patch
Copy link
Contributor

Choose a reason for hiding this comment

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

unittest is part of the standard library. Please move this line to the bottom of the first group of imports, e.g.,

import imp
import os
import sys
from unittest.mock import patch

@smaheshm
Copy link
Contributor Author

retest this please

1 similar comment
@smaheshm
Copy link
Contributor Author

retest this please

@smaheshm smaheshm merged commit 3fa55a4 into sonic-net:master Dec 29, 2020
@smaheshm smaheshm deleted the sudo-fix branch February 26, 2021 22:33
anand-kumar-subramanian pushed a commit to anand-kumar-subramanian/sonic-utilities that referenced this pull request Mar 2, 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.

4 participants