image-info: Add workaround for listing services by status

`image-info` tools parses output of `systemctl list-unit-files` run on a
different tree (with `--root` option), to determine the list of enabled
and disabled services on the inspected image. However since Fedora 33
(and presumably since systemd v246), the output of `systemctl
list-unit-files` changed. Some units previously reported as "enabled" or
"disabled" are now reported as "alias", which means, that they are just
a symlink to a different unit.

There is no systemd command, that would take an "alias" unit and would
report its state as "enabled" or "disabled" and could run on a different
tree (with "--root" option).

To make the list of reported services in the given state consistent on
systems with older and new (v246+) systemd version, check all "alias"
units and append them to the list of services with a specific status,
if their target is also listed in in the list.

Example of the `systemctl list-unit-files` output change:

~]# rpm -q systemd
systemd-246.6-3.fc33.x86_64
~]# systemctl list-unit-files ctrl-alt-del.target
UNIT FILE           STATE VENDOR PRESET
ctrl-alt-del.target alias -

~]# rpm -q systemd
systemd-245.8-2.fc32.x86_64
~]# systemctl list-unit-files ctrl-alt-del.target
UNIT FILE           STATE   VENDOR PRESET
ctrl-alt-del.target enabled disabled

This change makes it possible to produce consistent output for an
inspected image, regardless if the `image-info` tool is run on Fedora
32, Fedora 33 or RHEL-8.

Also regenerate all Fedora 33 test cases, since this commit changes the
content of produced list of enabled / disabled services since Fedora 33.
The list is now consistent with what would be produced by `image-info`
for an image on older Fedora (e.g. 32) or RHEL-8.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-01-28 18:03:50 +01:00 committed by Ondřej Budai
parent 9b7fb4fb63
commit 1a3cbb282a
9 changed files with 137 additions and 8 deletions

View file

@ -9711,12 +9711,12 @@
"version": "5.8.15-301.fc33.x86_64"
}
],
"default-target": "graphical.target",
"firewall-enabled": [
"ssh",
"mdns",
"dhcpv6-client"
],
"default-target": "graphical.target",
"fstab": [
[
"UUID=76a22bf4-f153-4541-b6c7-0332c0dfaeac",
@ -10235,6 +10235,7 @@
"rdisc.service",
"rdma.service",
"remote-cryptsetup.target",
"runlevel0.target",
"serial-getty@.service",
"sshd-keygen@.service",
"sshd.socket",
@ -10260,12 +10261,19 @@
"NetworkManager-wait-online.service",
"NetworkManager.service",
"auditd.service",
"autovt@.service",
"chronyd.service",
"cloud-config.service",
"cloud-final.service",
"cloud-init-local.service",
"cloud-init.service",
"ctrl-alt-del.target",
"dbus-broker.service",
"dbus-org.fedoraproject.FirewallD1.service",
"dbus-org.freedesktop.home1.service",
"dbus-org.freedesktop.nm-dispatcher.service",
"dbus-org.freedesktop.resolve1.service",
"dbus.service",
"dbus.socket",
"dnf-makecache.timer",
"firewalld.service",
@ -10276,6 +10284,7 @@
"reboot.target",
"remote-fs.target",
"rpmdb-rebuild.service",
"runlevel6.target",
"selinux-autorelabel-mark.service",
"sshd.service",
"sssd-kcm.socket",