Service.is_valid always returns invalid because of unrelated issues
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- linux, python
- Área
- infrastructure, testing
Línea de trabajo
Start in testinfra/modules/service.py and inspect the service.is_valid path that runs systemd-analyze verify; reproduce the reported stderr behavior with the example unit output. Done means validation no longer fails on unrelated systemd messages while still detecting the service's own invalid-unit message, with coverage for both cases.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On a system with some systemd issues, the outcome of host.service('myservice').is_valid is always False, even if my service is actually good.
On further investigation the original pull request to add this https://github.com/pytest-dev/pytest-testinfra/pull/265 added a check to make sure STDOUT and STDERR were emtpy, as the call to systemd-analyze verify %s always returns 0. However, in come cases, STDERR can contain unrelated information which trips up the comparison.
As an example, I have a deliberate typo in my service unit. The output of systemd-analyze verify myservice.service is as follows (all on STDERR):
snap-core18-2632.mount: Unit is bound to inactive unit dev-loop1.device. Stopping, too.
snap-snapd-18357.mount: Unit is bound to inactive unit dev-loop5.device. Stopping, too.
snap-snapd-17883.mount: Unit is bound to inactive unit dev-loop4.device. Stopping, too.
snap-core20-1828.mount: Unit is bound to inactive unit dev-loop7.device. Stopping, too.
/lib/systemd/system/myservice.service:17: Missing '=', ignoring line.
If I correct the typo, then the last line of this output goes away, but the others remain (actually, on my system the others seem to change every time I run the verify, but I always get at least a couple of lines out of it).
I'm not sure what's up with my system that it should do this (or why systemd would behave this way) but I'm wondering what the best solution to the testinfra problem is. I'm thinking a sort of "grep" of the output for myservice.service would suffice? Something like:
stderr = "".join(filter(lambda x: name in x, cmd.stderr.split()))
Or in place in the function in testinfra/modules/service.py (also taking the opportunity to add some output to explain the reason for the failure):
@property
def is_valid(self):
# systemd-analyze requires a full path.
if self.name.endswith(".service"):
name = self.name
else:
name = self.name + ".service"
cmd = self.run("systemd-analyze verify %s", name)
# A bad unit file still returns a rc of 0, so check the
# stdout for anything. Nothing means no warns/errors.
# Docs at https://www.freedesktop.org/software/systemd/man/systemd
# -analyze.html#Examples%20for%20verify
stderr = "".join(filter(lambda x: name in x, cmd.stderr.split()))
assert (cmd.stdout, stderr) == ("", ""), "service %s is not valid (see 'systemd-analyze verify %s' for details)" % (name, name)
return True
Happy to hear other suggestions or ideas etc :-)
- Lenguaje dominante
- Python
- Estrellas
- 2.5k
- Forks
- 358
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytest-dev/pytest-testinfra
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 58/100
pytest-dev/pytest-testinfra#815 ·
-
service is_enabled does not work with exit code 4Posiblemente ocupada @pfuntner la tomó hace 581 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
pytest-dev/pytest-testinfra#801 · 1 comentario ·
-
Chroot backendAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
pytest-dev/pytest-testinfra#789 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
pytest-dev/pytest-testinfra#788 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
pytest-dev/pytest-testinfra#786 ·
Todos los issues de pytest-dev/pytest-testinfra
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
jejjohnson/gaussx#752 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
521xueweihan/HelloGitHub#4270 ·
-
enhancement owner: den-haag
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 6 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ok-oldking/ok-wuthering-waves#1828 ·
Los mantenedores suelen responder en 1 día
-
lesson-submission pending-review
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
Ikalus1988/MisakaNet#4512 ·
Los mantenedores suelen responder en 1 día