Hmmm, this seems like a somewhat common operation.  I think I've seen a similar function in another libvirt test.  What about combining them and putting in utils_libvirt or utils_test?