avoid resource leaks in keypairs tests

this does some code refactor, uses addCleanup to
avoid resource leaks. and import the module test
instead of attr.

Change-Id: I188bec7dda2cd0f180252a9844e378bb2f8ff6da
2 files changed