libvirt: Fix setmaxmem from changing mem size

The test setmaxmem backup the vm's max memory and restore it by calling
`virsh setmaxmem` after test.

This will cause problem when test shinking the max memory. The current
memory will also shrink to adapt the max memory. After restore the max
memory, this shrinked current memory will remain.

* To ensure the fully restoration of guest, we change back to
  backup by new_from_inactive_dumpxml and sync after test.

* Use `try ... finally ...` to make sure restoration even bad thing
  happens.

* Fix some pylint complaints.

Signed-off-by: Hao Liu <hliu@redhat.com>
libvirt: Fix attach-device itertools backports

Calling backported itertools using 'from ... import ...' will cause
following error.

ERROR| Traceback (most recent call last):
ERROR|   File "virttest/standalone_test.py", line 182, in run_once
ERROR|     test_modules[t_type] = imp.load_module(t_type, f, p, d)
ERROR|   File "libvirt/tests/src/virsh_cmd/domain/virsh_attach_device.py", line 14, in <module>
ERROR|     from virttest.staging.backports.itertools import product, islice, count
ERROR| ImportError: No module named itertools

Signed-off-by: Hao Liu <hliu@redhat.com>
Merge pull request #1265 from Hao-Liu/fix_setmaxmem

libvirt: Fix setmaxmem from changing mem size
Merge pull request #1287 from Hao-Liu/fix_attach_device

libvirt: Fix attach-device itertools backports