Skip to content

Commit

Permalink
replacing the command that extract libvirtd's pid
Browse files Browse the repository at this point in the history
`ps -x`      ->      `pidof <LIBVIRTD_PID>`

Signed-off-by: Barak Mordehai <[email protected]>
  • Loading branch information
Barakmor1 committed Nov 17, 2021
1 parent ade9afb commit 6389fdb
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions tests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,32 +318,14 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:[email protected]][leve
}

getLibvirtdPid := func(pod *k8sv1.Pod) string {
stdout, stderr, errPsCmd := tests.ExecuteCommandOnPodV2(virtClient, pod, "compute",
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "compute",
[]string{
"ps",
"-x",
"pidof",
"libvirtd",
})
errorMassageFormat := "faild after running `ps -x` with stdout:\n %v \n stderr:\n %v \n err: \n %v \n extracted pid of libvirtd: `%v` should have been numeric\n"

pid := ""
for _, str := range strings.Split(stdout, "\n") {
if !strings.Contains(str, "libvirtd") {
continue
}
words := strings.Fields(str)

Expect(len(words)).To(Equal(7), fmt.Sprintf("Found %s", words))

// verify it is numeric
_, err = strconv.Atoi(words[0])
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(errorMassageFormat, stdout, stderr, errPsCmd, pid))
pid = words[0]

break

}
Expect(pid).ToNot(BeEmpty(), fmt.Sprintf(errorMassageFormat, stdout, stderr, errPsCmd, pid))

errorMassageFormat := "faild after running `pidof libvirtd` with stdout:\n %v \n stderr:\n %v \n err: \n %v \n"
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(errorMassageFormat, stdout, stderr, err))
pid := strings.TrimSuffix(stdout, "\n")
return pid
}

Expand Down Expand Up @@ -680,13 +662,14 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:[email protected]][leve

// kill libvirtd
By(fmt.Sprintf("Killing libvirtd with pid %s", pid))
_, _, err = tests.ExecuteCommandOnPodV2(virtClient, &pods.Items[0], "compute",
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, &pods.Items[0], "compute",
[]string{
"kill",
"-9",
pid,
})
Expect(err).ToNot(HaveOccurred())
errorMassageFormat := "faild after running `kill -9 %v` with stdout:\n %v \n stderr:\n %v \n err: \n %v \n"
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(errorMassageFormat, pid, stdout, stderr, err))

// wait for both libvirt to respawn and all connections to re-establish
time.Sleep(30 * time.Second)
Expand Down

0 comments on commit 6389fdb

Please sign in to comment.