Open rgarrigue opened 5 years ago
Hi,
You can run py.test with -vvs
flags to enable debug output and see what command is actually run by testinfra.
In this case I think testinfra run systemctl is-enabled caddy
what is the output of this command ?
Ok, I found why. https://github.com/philpep/testinfra/blob/master/testinfra/modules/service.py#L54
We are running tests in a docker container and systemd is lauched by docker, so there is no /sbin/init link and testinfra fallback to SysVinit which can't work.
I got around by adding the missing link in our containers.
Maybe we should look for /proc/1/exe instead of /sbin/init That being said, IIRC, some commands work with systemd not being pid 1 (like systemctl is-enabled).
That's also an issue I get with a container based on Archlinux.
The link /sbin/init
doesn't exist and Testinfra falls back to SysVinit.
cat
ing /proc/1/comm
seems to give good results (here are some tests I did on vagrant boxes):
init
(+ rc-service
exists) => OpenRCService
;init
(+ initctl
exists) => UpstartService
;systemd
=> SystemdService
;systemd
=> SystemdService
;systemd
=> SystemdService
.Also, wouldn't it be a better idea to fall back to SystemdService
?
I'm volunteering to write a PR if the above sounds OK to you :-)
Ok, I found why. https://github.com/philpep/testinfra/blob/master/testinfra/modules/service.py#L54
We are running tests in a docker container and systemd is lauched by docker, so there is no /sbin/init link and testinfra fallback to SysVinit which can't work.
I got around by adding the missing link in our containers.
I have this exact same problem when running tests using a systemd-enabled Debian 9 image. In my case, though, I'm running systemd inside of a Docker container, and so my systemd process is not PID 1.
Ok, I found why. https://github.com/philpep/testinfra/blob/master/testinfra/modules/service.py#L54 We are running tests in a docker container and systemd is lauched by docker, so there is no /sbin/init link and testinfra fallback to SysVinit which can't work. I got around by adding the missing link in our containers.
I have this exact same problem when running tests using a systemd-enabled Debian 9 image. In my case, though, I'm running systemd inside of a Docker container, and so my systemd process is not PID 1.
In case anyone else encounters this issue when exercising testinfra via molecule, I was able to get around it by creating molecule/default/prepare.yml
with the following content:
- name: Group hosts by OS distribution
hosts: all
tasks:
- name: Group hosts by OS distribution
group_by:
key: os_{{ ansible_facts['distribution'] }}
- name: Install init (Debian)
hosts: os_Debian
tasks:
- name: Install init (Debian)
package:
name:
- init
Hi, it seems that adding the systemd-sysv
package to docker resolves the problem.
See: https://github.com/geerlingguy/docker-debian10-ansible/pull/4
So I can confirm that testinfra (3.4.0) test now passes with those services:
assert host.service("postfix").is_enabled
assert host.service("mariadb").is_enabled
assert host.service("nftables").is_enabled
assert host.service("ntp").is_enabled
assert host.service("rsync").is_enabled
assert host.service("ssh").is_enabled
assert host.service("zabbix-agent").is_enabled
Hi
I'm testing a salt formula via kitchen, installing and enabling caddy service. As you can see, the service is enabled
But testinfra thinks otherwise
Here's the kitchen verifier command if that might help