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 failures in TestNetplanValidateNetworkSchema #5804

Closed
palash-gandhi opened this issue Oct 8, 2024 · 1 comment
Closed

Unit test failures in TestNetplanValidateNetworkSchema #5804

palash-gandhi opened this issue Oct 8, 2024 · 1 comment
Labels
bug Something isn't working correctly

Comments

@palash-gandhi
Copy link

Bug report

We are seeing test failures, specifically in test_network_config_schema_validation_false_when_skipped. It seems like the test code expects that removing the netplan module from sys.modules will cause an ImportError while importing netplan. Here's a stack trace and some debug output from a debugging session:

$ git log -1
commit 0f77b3c13a2f44c224c5dea18d27bbfa4898e39a (HEAD -> main, origin/main, origin/HEAD)
Author: James Falcon <[email protected]>
Date:   Tue Oct 8 14:59:51 2024 -0500

    chore: Use devel release and no sbuild in integration CI (#5798)

$ python3 -m pytest -v tests/unittests cloudinit -k 'test_network_config_schema_validation_false_when_skipped' --pdb
===================================================== test session starts =====================================================
platform linux -- Python 3.12.3, pytest-7.4.4, pluggy-1.4.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/ubuntu/cloud-init-pstream
configfile: tox.ini
plugins: mock-3.12.0
collected 5142 items / 5138 deselected / 4 selected

tests/unittests/config/test_schema.py::TestNetplanValidateNetworkSchema::test_network_config_schema_validation_false_when_skipped[config0-] FAILED [ 25%]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> captured log >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2024-10-08 23:23:26 DEBUG     cloudinit.util:util.py:2290 Writing to /tmp/tmpr2kaczoy/etc/netplan/network-config.yaml - wb: [600] 20 bytes
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

self = <tests.unittests.config.test_schema.TestNetplanValidateNetworkSchema object at 0x7ea520414140>, config = {}
expected_log = '', caplog = <_pytest.logging.LogCaptureFixture object at 0x7ea51f363ef0>

    @pytest.mark.parametrize(
        "config,expected_log",
        (
            ({}, ""),
            ({"version": 1}, ""),
            (
                {"version": 2},
                "Skipping netplan schema validation. No netplan API available",
            ),
            (
                {"network": {"version": 2}},
                "Skipping netplan schema validation. No netplan API available",
            ),
        ),
    )
    def test_network_config_schema_validation_false_when_skipped(
        self, config, expected_log, caplog
    ):
        """netplan_validate_network_schema returns false when skipped."""
        with mock.patch.dict("sys.modules"):
            sys.modules.pop("netplan", None)
>           assert False is netplan_validate_network_schema(config)
E           assert False is True
E            +  where True = netplan_validate_network_schema({})

tests/unittests/config/test_schema.py:438: AssertionError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/ubuntu/cloud-init-pstream/tests/unittests/config/test_schema.py(438)test_network_config_schema_validation_false_when_skipped()
-> assert False is netplan_validate_network_schema(config)
(Pdb) "netplan" in sys.modules
False
(Pdb) from netplan import NetplanParserException
(Pdb) "netplan" in sys.modules
True
(Pdb) sys.modules.pop("netplan", None)
<module 'netplan' from '/usr/lib/python3/dist-packages/netplan/__init__.py'>
(Pdb) from netplan import NetplanParserException
(Pdb)

Steps to reproduce the problem

On Ubuntu 24.04, run make unittest or to run only the failing tests, run this command:

python3 -m pytest -v tests/unittests cloudinit -k 'test_network_config_schema_validation_false_when_skipped' --pdb

Environment details

  • Cloud-init version: Commit 0f77b3c13a2f44c224c5dea18d27bbfa4898e39a of branch main
  • Operating System Distribution: Ubuntu 24.04 LTS
  • Cloud provider, platform or installer type: AWS

cloud-init logs

Not applicable since these are unit test failures.

@palash-gandhi palash-gandhi added bug Something isn't working correctly new An issue that still needs triage labels Oct 8, 2024
TheRealFalcon added a commit to TheRealFalcon/cloud-init that referenced this issue Oct 9, 2024
The way the netplan API was being imported caused test issues.
Imports were moved and tests updated accordingly.

Fixes canonicalGH-5804
@TheRealFalcon
Copy link
Member

@palash-gandhi , thanks! I put up a fix at #5805

@TheRealFalcon TheRealFalcon removed the new An issue that still needs triage label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

2 participants