Skip to content

Enable pkg tests for systemd status on upgrade #67968

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

Draft
wants to merge 16 commits into
base: 3006.x
Choose a base branch
from

Conversation

barneysowood
Copy link
Collaborator

What does this PR do?

Enables tests for systemd status (enabled, active etc). These were added in #66218 but disabled. We should actually be testing this.

Spotted this when reviewing #66688 - I was surprised that wasn't breaking tests. Assume the intent was that this should be enabled once #66218 was merged and pkg tests were running again

Previous Behavior

Tests for maintaining status of systemd services on upgrade were not being run

New Behavior

Tests are now being run

Merge requirements satisfied?

N/A

Commits signed with GPG?

Yes/No

@barneysowood barneysowood self-assigned this Apr 17, 2025
@barneysowood barneysowood force-pushed the enable-pkg-systemd-tests branch from 31382c6 to ebdaa0c Compare May 6, 2025 14:11
@barneysowood barneysowood force-pushed the enable-pkg-systemd-tests branch from ebdaa0c to a02bdef Compare May 7, 2025 17:06
@barneysowood barneysowood force-pushed the enable-pkg-systemd-tests branch from a02bdef to e514927 Compare May 7, 2025 19:28
Enables tests for systemd status (enabled, active etc). These were added
in saltstack#66218 but disabled. We should actually be testing this.
Updates the check for inactive state having been preserved to expect a
non-zero exit code - "systemctl is-active" actually returns 3 and the
docs just say that if the service isn't active the return code is
non-zero
Fixes use of salt_systemd_setup fixture - we need to call it for each
test function otherwise state will persist across tests. Made it a
function scoped fixture and removed the attempts to call it in the
functions, which wouldn't work.

Updated the fixture to also install the previous package version for
each test run. Without this, after the first test, the calls to
install_salt.install(upgrade=True) were upgrading from the new version
to the new version - which isn't what we need to test.
Fixes issues with services in the pkg upgrade systemd tests:

* Stopping a salt service that is using the log engine from
pytest-salt-factories fails if systemd is set to KillMode=process, which
is the current setup in salt's packages. Added a fixture to override
for these tests, otherwise we end up with services in a failed state.

* SaltPkgInstall.install() stops services on ubuntu/debian after install
which is the right thing to do in most cases, but in these tests we need
to check the state of services immeadiately after install. Added a
stop_services arg to install()
Cleans up the apt preferences file that is generated by
install_previous(), otherwise integration tests call apt upgrade and try
to revert the packages.
Re-orders test when doing upgrade tests. Ensures that
test_salt_upgrade.py runs last. The integration tests that are run after
upgrade tests expect that there has been a clean upgrade just done, so
this ensures that is the case.
Ensures that the version of salt is downgraded to the previous version
after each systemd upgrade test. This ensures we are resetting state
correctly and have the right state for the main upgrade test.
Ensures services are started on ubuntu/debian - install_previous stops
them, but test_salt_upgrade expects them to be running
Removes tests for services maintaing active/inactive states over
upgrades as this functionality was removed from the packages (saltstack#66688)
Adds a fixture to disable /usr/sbin/policy-rc.d - on the container
images we're using this returns an exitcode of 1001, which prevents dpkg
from running service restarts on installs/upgrades, which makes the
system behave differently to a real system.
Adds test for masking services to ensure that is preserved on upgrade.
Fixes test_salt_ownership_permission tests - these were previously
failing because they were looking at ownership of /run/salt/salt-minion.
The ownership of that get's messed - /run/salt-minion.pid is a more
reliable way of checking what user the minion is running as.

Also simplified the tests slightly to remove some of the duplication.
Splits out the systemd permissions tests and systemd service status
preservation tests into seperate files as they were quite long. Also
moves fixtures into conftest.py to allow sharing those.

test_systemd_permissions could still do with some more simplification.
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.

1 participant