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

The devname referenced in your traceback should be the result of get_devicelist(), which should be mocked. #1356

Merged
merged 6 commits into from
Mar 31, 2022

Conversation

yangzz-97
Copy link
Contributor

@yangzz-97 yangzz-97 commented Mar 29, 2022

Hello
I am executing the cloud-init test case and the testcase has occasionally failed.
The failure testcases are:
FAILED tests/unittests/test_net.py::TestGetInterfaces::test_gi_excludes_any_without_mac_address
FAILED tests/unittests/test_net.py::TestGetInterfaces::test_gi_excludes_stolen_macs
FAILED tests/unittests/test_net.py::TestGetInterfaces::test_gi_includes_duplicate_macs

The error log for each failed use case is similar as follows:


    def test_gi_excludes_any_without_mac_address(self):
        self._mock_setup()
>       ret = net.get_interfaces()

tests/unittests/test_net.py:5431:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cloudinit/net/__init__.py:941: in get_interfaces
    if is_netfailover(name):
cloudinit/net/__init__.py:204: in is_netfailover
    if is_netfail_primary(devname, driver) or is_netfail_standby(devname,
cloudinit/net/__init__.py:279: in is_netfail_primary
    master_driver = device_driver(master_devname)
/usr/lib64/python3.9/unittest/mock.py:1092: in __call__
    return self._mock_call(*args, **kwargs)
/usr/lib64/python3.9/unittest/mock.py:1096: in _mock_call
    return self._execute_mock_call(*args, **kwargs)
/usr/lib64/python3.9/unittest/mock.py:1157: in _execute_mock_call
    result = effect(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tests.unittests.test_net.TestGetInterfaces testMethod=test_gi_excludes_any_without_mac_address>
name = 'bond0'

    def _se_device_driver(self, name):
>       return self.data['drivers'][name]
E       KeyError: 'bond0'

tests/unittests/test_net.py:5390: KeyError

Note: The file line number in the preceding log information may not match the latest code.

When the test case fails, the bond0 network adapter exists in my environment. 

According to the error log "KeyError: 'bond0'", I think that the data dictionary defined in the test case does not contain the bond keyword.

SO,I tried to add the bond0 keyword to the data dictionary. The test case was successfully executed.
Please help me to check whether the modification is feasible. Thank you.

Signed-off-by: yangzz-97 <yangzz-97@1162011203@qq.com>
@yangzz-97 yangzz-97 changed the title add bond0 to data dictionary in test_net.pt testcase add bond0 to data dictionary in test_net.py testcase Mar 29, 2022
@TheRealFalcon
Copy link
Member

@yangzz-97 , I'm not exactly sure what's going on. The devname referenced in your traceback should be the result of get_devicelist(), which should be mocked.

I think there might be a bigger mocking issue that your change doesn't address.

Does a patch like this work for you?

diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index fa8b99a0..6844c329 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -7454,6 +7454,12 @@ class TestGetInterfaces(CiTestCase):
     def _se_interface_has_own_mac(self, name):
         return name in self.data["own_macs"]
 
+    def _se_is_bond(self, name):
+        return name in self.data["bonds"]
+
+    def _se_is_netfailover(self, name):
+        return False
+
     def _mock_setup(self):
         self.data = copy.deepcopy(self._data)
         self.data["devices"] = set(list(self.data["macs"].keys()))
@@ -7465,6 +7471,8 @@ class TestGetInterfaces(CiTestCase):
             "is_vlan",
             "device_driver",
             "device_devid",
+            "is_bond",
+            "is_netfailover",
         )
         self.mocks = {}
         for n in mocks:

yangzz-97 added 5 commits March 31, 2022 20:45
…devicelist(), which should be mocked.

Signed-off-by: yangzz-97 <yangzz-97@1162011203@qq.com>
…devicelist(), which should be mocked.

Signed-off-by: yangzz-97 <yangzz-97@1162011203@qq.com>
@yangzz-97
Copy link
Contributor Author

@TheRealFalcon
Thank you very much! This patch works for me.I have resubmitted it

@yangzz-97
Copy link
Contributor Author

Maybe I didn't do it right and made a lot of commits

@yangzz-97 yangzz-97 changed the title add bond0 to data dictionary in test_net.py testcase The devname referenced in your traceback should be the result of get_devicelist(), which should be mocked. Mar 31, 2022
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Thanks!

@TheRealFalcon TheRealFalcon merged commit d8f39d7 into canonical:main Mar 31, 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