[ovs-dev] [PATCH] testsuite: exit gracefully if it fails.

Ben Pfaff blp at ovn.org
Thu Jun 8 17:53:05 UTC 2017


On Thu, Jun 08, 2017 at 02:30:48PM -0300, Flavio Leitner wrote:
> The daemon is killed leaving resources behind when a test fails.
> This fixes to first signal the daemon to exit gracefully.
> 
> Suggested-by: Joe Stringer <joe at ovn.org>
> Fixes: 0f28164be02ac ("netdev-linux: make tap devices persistent")
> Signed-off-by: Flavio Leitner <fbl at redhat.com>
> ---
>  tests/ofproto-macros.at | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
> index faff5b0..5ac5d05 100644
> --- a/tests/ofproto-macros.at
> +++ b/tests/ofproto-macros.at
> @@ -323,6 +323,9 @@ m4_define([_OVS_VSWITCHD_START],
>     AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
>     AT_CAPTURE_FILE([ovs-vswitchd.log])
>     on_exit "kill `cat ovs-vswitchd.pid`"
> +   dnl Wait for the daemon to exit gracefully
> +   on_exit "for i in 1 2 3 4 5 6 7 8 9; do kill -0 `cat ovs-vswitchd.pid` || break; sleep 0.1 || sleep 1; done"
> +   on_exit "ovs-appctl -t ovs-vswitchd exit --cleanup"

Thanks for the patch.

At first, I thought that this did the steps in the wrong order, but
"on_exit" reverses the order.

It would be less surprising to do this with just one call to on_exit,
e.g.

on_exit '
    ovs-appctl -t ovs-vswitchd exit --cleanup
    for i in 1 2 3 4 5 6 7 8 9; do
        kill -0 `cat ovs-vswitchd.pid` || break
        sleep 0.1 || sleep 1
    done
    kill `cat ovs-vswitchd.pid`
'

Actually, I think that all of this could be put in a shell function:

kill_ovs_vswitchd() {
    ovs-appctl -t ovs-vswitchd exit --cleanup
    for i in 1 2 3 4 5 6 7 8 9; do
        kill -0 `cat ovs-vswitchd.pid` || break
        sleep 0.1 || sleep 1
    done
    kill `cat ovs-vswitchd.pid`
}

and then just "on_exit kill_ovs_vswitchd".  Maybe that is the best
approach.

Thanks,

Ben.


More information about the dev mailing list