Skip to content

Fix UT failed cause by change pycommon to use swsscommon #246

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

Conversation

liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Feb 28, 2022

Fix UT failed cause by change sonic_py_common to use swss_common

Description

Fix UT failed cause by change sonic_py_common to use swss_common:

    In current UT, we implement swsscommon mock class under sonic-pcied/tests/mocked_libs/swsscommon and load these mock libs by add the mock path in front of real swsscommon lib path with following code:

          # Add mocked_libs path so that the file under test can load mocked modules from there
          mocked_libs_path = os.path.join(tests_path, "mocked_libs")
          sys.path.insert(0, mocked_libs_path)

    However, because we change sonic_py_common to use swsscommon, so real version of swsscommon been load before we load mock lib. then the UT break with following error message:
          
          ______________ TestDaemonPcied.test_update_pcie_devices_status_db ______________
          self = <tests.test_DaemonPcied.TestDaemonPcied object at 0x7f29542655d0>
              @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock())
              def test_update_pcie_devices_status_db(self):
           >       daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER)
          tests/test_DaemonPcied.py:160: 
          _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
          scripts/pcied:93: in __init__
              self.device_table = swsscommon.Table(self.state_db, PCIE_DEVICE_TABLE_NAME)
          _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
          self = <swsscommon.swsscommon.Table;  >
          args = (<MagicMock name='mock()' id='139815470171344'>, 'PCIE_DEVICE')
              def __init__(self, *args):
           >       this = _swsscommon.new_Table(*args)
           E       NotImplementedError: Wrong number or type of arguments for overloaded function 'new_Table'.
           E         Possible C/C++ prototypes are:
           E           swss::Table::Table(swss::DBConnector const *,std::string const &)
           E           swss::Table::Table(swss::RedisPipeline *,std::string const &,bool)

Motivation and Context

pyswss will be deprecate, so sonic_py_common will changed to use swss_common.
Some UT in this project failed because this change.

How Has This Been Tested?

Pass all UT and sonic-buildimage E2E test.

Additional Information (Optional)

@liuh-80
Copy link
Contributor Author

liuh-80 commented Feb 28, 2022

Code in this PR will be test in another PR:
sonic-net/sonic-buildimage#10099

@liuh-80 liuh-80 marked this pull request as ready for review March 4, 2022 07:04
@liuh-80 liuh-80 requested a review from qiluo-msft March 4, 2022 07:04
@qiluo-msft
Copy link
Contributor

Could you add "UT failed" message into PR description?

@liuh-80
Copy link
Contributor Author

liuh-80 commented Mar 14, 2022

Could you add "UT failed" message into PR description?

Fixed, Add UT error message to PR description.

The original error log can be found here:
https://dev.azure.com/mssonic/be1b070f-be15-4154-aade-b1d3bfb17054/_apis/build/builds/81153/logs/27

@liuh-80
Copy link
Contributor Author

liuh-80 commented Mar 15, 2022

Will push a update later, the UT issue is:
In current UT, we implement swsscommon mock class under sonic-pcied/tests/mocked_libs/swsscommon and load these mock libs by add the mock path in front of real swsscommon lib path with following code:

# Add mocked_libs path so that the file under test can load mocked modules from there
mocked_libs_path = os.path.join(tests_path, "mocked_libs")
sys.path.insert(0, mocked_libs_path)

However, because we change sonic_py_common to use swsscommon, so real version of swsscommon been load before we load mock lib. then the UT break.

So will check if can load mock lib first by change the code orider.

@@ -18,6 +18,7 @@
# Add mocked_libs path so that the file under test can load mocked modules from there
mocked_libs_path = os.path.join(tests_path, "mocked_libs")
sys.path.insert(0, mocked_libs_path)
from sonic_py_common import daemon_base, device_info
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 17, 2022

Choose a reason for hiding this comment

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

This line is same as L13. I think it will be ignored.
Do you want to remove L13? #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.

Fixed, this is a mistake.

@liuh-80 liuh-80 merged commit f09bd31 into sonic-net:master Mar 17, 2022
vdahiya12 pushed a commit to vdahiya12/sonic-platform-daemons that referenced this pull request Apr 4, 2022
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