test/e2e: fix SkipIfNotActive()

If a unit is not active the exit code from systemctl is 3. Thus this
test always failed because it checked the error.

Fix this by checking the exit code and remove the unnecessary output
parsing.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2023-04-14 14:15:07 +02:00
parent 01d518a975
commit 525c27fe1d
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
1 changed files with 6 additions and 11 deletions

View File

@ -820,19 +820,14 @@ func SkipIfInContainer(reason string) {
func SkipIfNotActive(unit string, reason string) {
checkReason(reason)
var buffer bytes.Buffer
cmd := exec.Command("systemctl", "is-active", unit)
cmd.Stdout = &buffer
err := cmd.Start()
Expect(err).ToNot(HaveOccurred())
err = cmd.Wait()
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
if strings.TrimSpace(buffer.String()) != "active" {
Skip(fmt.Sprintf("[systemd]: unit %s is not active: %s", unit, reason))
cmd.Stdout = GinkgoWriter
cmd.Stderr = GinkgoWriter
err := cmd.Run()
if cmd.ProcessState.ExitCode() == 0 {
return
}
Skip(fmt.Sprintf("[systemd]: unit %s is not active (%v): %s", unit, err, reason))
}
func SkipIfCNI(p *PodmanTestIntegration) {