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

LNDENG-636 (Shutdown/Reboot to DBus) #195

Merged
merged 15 commits into from Dec 5, 2023

Conversation

mcw-work
Copy link
Contributor

Changed shutdown manager to use dbus calls instead of direct executables.
Changed reboot logic in package changer to also use dbus.
Removed unit tests that use old shutdown logic.

@mcw-work
Copy link
Contributor Author

Unit tests added for Shutdown/Restart logic. These don't test the dbus calls directly but ensure we are calling the necessary methods, or at least queuing them for the bus.

Copy link
Contributor

@Perfect5th Perfect5th left a comment

Choose a reason for hiding this comment

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

Tiny inline comment.

Don't worry about the coverage failure. Codecov is being dumb and isn't comparing to the correct previous commit. If you push another commit it should be fine.

landscape/client/manager/tests/test_shutdownmanager.py Outdated Show resolved Hide resolved
Removed unnecessary teardown method
@Perfect5th
Copy link
Contributor

Actually, looking at the coverage report was helpful. I assumed codecov was bad because it was using the wrong base commit, but there is also a real coverage issue.

Because you're patching _Reboot and the reactor, neither _Reboot nor _Shutdown ever actually get called by the tests, leading to coverage gaps. Here's what you likely want to do instead in your test class:

from unittest.mock import Mock, patch

...

    def setUp(self):
        super().setUp()
        ... # broker_service-related stuff
        self.dbus_mock = patch("landscape.client.manager.shutdownmanager.dbus").start()
        self.addCleanup(patch.stopall)

    def test_reboot(self):
        bus_object = Mock()
        self.dbus_mock.SystemBus.return_value = bus_object
        
        ... # actually run stuff, resulting in deferred

        def check(_):
            bus_object.get_object.assert_called_once()
            bus_object.Reboot.assert_called_once()  # or assert specific args, if you want to be safe

        return deferred

Similar for test_shutdown.

assert calls on dbus object
added clock advance for shutdown delay
@mcw-work
Copy link
Contributor Author

Thanks Mitch, tests have been updated to mock at the lower layer as recommended. Seems much neater to me as well. For the shutdown test I had to add a clock to ensure the delayed call got triggered. That needed a small tweak to the actual shutdown code but nothing too disconcerting. Hopefully covcheck will pass now.

@Perfect5th
Copy link
Contributor

Apologies. Forgot to mention in my prev comment that the check callback needs to be added to the deferred:

deferred.addCallback(check)
return deferred

mcw-work and others added 3 commits November 22, 2023 17:28
Add callback to the shutdown tests
Tweaks to shutdownmanager to use deferLater.
Refactored reboot test in package/changer.py
@mcw-work
Copy link
Contributor Author

mcw-work commented Dec 4, 2023

Tests seem to be sensible and full coverage now.

Copy link
Contributor

@Perfect5th Perfect5th left a comment

Choose a reason for hiding this comment

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

LGTM, good work!

@Perfect5th Perfect5th merged commit 04b74b7 into canonical:master Dec 5, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants