35ab656 ipatests: fix race condition in finalizer of encrypted backup test

Authored and Committed by abbra 3 years ago
    ipatests: fix race condition in finalizer of encrypted backup test
    
    When using a fixture, we get a temporary directory created and then
    removed by pytest. Pytest uses `shutil.rmtree` call which collects all
    files in the directory being removed and then removes them one by one.
    At the point of removal of our GNUPGHOME directory, gpg daemon is being
    shut down and there might still be an agent UNIX domain socket. The
    removal actually overlaps in time with shut down of the gpg daemon, thus
    causing `shutil.rmtree()` to fail when an agent UNIX domain socket is
    removed by the daemon.
    
    Change the way how we run the gpg agent to use a temporary systemd
    service. Stop the service in the finalizer method so that systemd would
    send SIGTERM signal and the gpg agent would clean itself up.
    
    Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
    Reviewed-By: Stanislav Levin <slev@altlinux.org>