python: PEP 8: adapt whitespaces in lines

Add (after comma) or remove (before opening round bracket, and around
'=' in arguments) whitespaces according to the PEP 8 specification.

This is just code reformatting, with no behaviour changes; no content
changed beside whitespaces, so "git diff -w" gives an empty diff.
This commit is contained in:
Pino Toscano
2016-05-04 12:38:44 +02:00
parent 839a17ff04
commit 6105ee0c71
18 changed files with 370 additions and 370 deletions

View File

@@ -8,56 +8,56 @@ output = "disk.img"
# to the constructor. It indicates that your program wants
# to receive Python dicts for methods in the API that return
# hashtables.
g = guestfs.GuestFS (python_return_dict=True)
g = guestfs.GuestFS(python_return_dict=True)
# Create a raw-format sparse disk image, 512 MB in size.
g.disk_create (output, "raw", 512 * 1024 * 1024);
g.disk_create(output, "raw", 512 * 1024 * 1024);
# Set the trace flag so that we can see each libguestfs call.
g.set_trace (1)
g.set_trace(1)
# Attach the disk image to libguestfs.
g.add_drive_opts (output, format = "raw", readonly = 0)
g.add_drive_opts(output, format="raw", readonly=0)
# Run the libguestfs back-end.
g.launch ()
g.launch()
# Get the list of devices. Because we only added one drive
# above, we expect that this list should contain a single
# element.
devices = g.list_devices ()
assert (len (devices) == 1)
devices = g.list_devices()
assert(len(devices) == 1)
# Partition the disk as one single MBR partition.
g.part_disk (devices[0], "mbr")
g.part_disk(devices[0], "mbr")
# Get the list of partitions. We expect a single element, which
# is the partition we have just created.
partitions = g.list_partitions ()
assert (len (partitions) == 1)
partitions = g.list_partitions()
assert(len(partitions) == 1)
# Create a filesystem on the partition.
g.mkfs ("ext4", partitions[0])
g.mkfs("ext4", partitions[0])
# Now mount the filesystem so that we can add files.
g.mount (partitions[0], "/")
g.mount(partitions[0], "/")
# Create some files and directories.
g.touch ("/empty")
g.touch("/empty")
message = "Hello, world\n"
g.write ("/hello", message)
g.mkdir ("/foo")
g.write("/hello", message)
g.mkdir("/foo")
# This one uploads the local file /etc/resolv.conf into
# the disk image.
g.upload ("/etc/resolv.conf", "/foo/resolv.conf")
g.upload("/etc/resolv.conf", "/foo/resolv.conf")
# Because we wrote to the disk and we want to detect write
# errors, call g.shutdown. You don't need to do this:
# g.close will do it implicitly.
g.shutdown ()
g.shutdown()
# Note also that handles are automatically closed if they are
# reaped by reference counting. You only need to call close
# if you want to close the handle right away.
g.close ()
g.close()

View File

@@ -3,55 +3,55 @@
import sys
import guestfs
assert (len (sys.argv) == 2)
assert(len(sys.argv) == 2)
disk = sys.argv[1]
# All new Python code should pass python_return_dict=True
# to the constructor. It indicates that your program wants
# to receive Python dicts for methods in the API that return
# hashtables.
g = guestfs.GuestFS (python_return_dict=True)
g = guestfs.GuestFS(python_return_dict=True)
# Attach the disk image read-only to libguestfs.
g.add_drive_opts (disk, readonly=1)
g.add_drive_opts(disk, readonly=1)
# Run the libguestfs back-end.
g.launch ()
g.launch()
# Ask libguestfs to inspect for operating systems.
roots = g.inspect_os ()
if len (roots) == 0:
raise (Error ("inspect_vm: no operating systems found"))
roots = g.inspect_os()
if len(roots) == 0:
raise(Error("inspect_vm: no operating systems found"))
for root in roots:
print "Root device: %s" % root
# Print basic information about the operating system.
print " Product name: %s" % (g.inspect_get_product_name (root))
print " Product name: %s" % (g.inspect_get_product_name(root))
print " Version: %d.%d" % \
(g.inspect_get_major_version (root),
g.inspect_get_minor_version (root))
print " Type: %s" % (g.inspect_get_type (root))
print " Distro: %s" % (g.inspect_get_distro (root))
(g.inspect_get_major_version(root),
g.inspect_get_minor_version(root))
print " Type: %s" % (g.inspect_get_type(root))
print " Distro: %s" % (g.inspect_get_distro(root))
# Mount up the disks, like guestfish -i.
#
# Sort keys by length, shortest first, so that we end up
# mounting the filesystems in the correct order.
mps = g.inspect_get_mountpoints (root)
def compare (a, b): return len(a) - len(b)
for device in sorted (mps.keys(), compare):
mps = g.inspect_get_mountpoints(root)
def compare(a, b): return len(a) - len(b)
for device in sorted(mps.keys(), compare):
try:
g.mount_ro (mps[device], device)
g.mount_ro(mps[device], device)
except RuntimeError as msg:
print "%s (ignored)" % msg
# If /etc/issue.net file exists, print up to 3 lines.
filename = "/etc/issue.net"
if g.is_file (filename):
if g.is_file(filename):
print "--- %s ---" % filename
lines = g.head_n (3, filename)
lines = g.head_n(3, filename)
for line in lines: print line
# Unmount everything.
g.umount_all ()
g.umount_all()

View File

@@ -18,45 +18,45 @@
from distutils.core import setup, Extension
setup (name='guestfs',
version='@PACKAGE_VERSION@',
setup(name='guestfs',
version='@PACKAGE_VERSION@',
description='access and modify virtual machine disk images',
long_description="""
description='access and modify virtual machine disk images',
long_description="""
libguestfs is a library and set of tools for accessing and modifying
virtual machine (VM) disk images.
This package contains the Python bindings for libguestfs.
""",
author='The @PACKAGE_NAME@ team',
author_email='libguestfs@redhat.com',
url='http://libguestfs.org',
author='The @PACKAGE_NAME@ team',
author_email='libguestfs@redhat.com',
url='http://libguestfs.org',
license='LGPLv2+',
license='LGPLv2+',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
'Operating System :: POSIX :: Linux',
'Programming Language :: C',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Utilities',
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
'Operating System :: POSIX :: Linux',
'Programming Language :: C',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Utilities',
],
py_modules=['guestfs'],
ext_modules=[
Extension (
'libguestfsmod',
['guestfs-py-byhand.c', 'guestfs-py.c', 'utils.c'],
py_modules=['guestfs'],
ext_modules=[
Extension(
'libguestfsmod',
['guestfs-py-byhand.c', 'guestfs-py.c', 'utils.c'],
include_dirs=['.', '../src'],
libraries=['guestfs'],
define_macros=[('GUESTFS_PRIVATE', '1')],
)
]
)
include_dirs=['.', '../src'],
libraries=['guestfs'],
define_macros=[('GUESTFS_PRIVATE', '1')],
)
]
)

View File

@@ -17,6 +17,6 @@
import unittest
class Test010Load (unittest.TestCase):
def test_import (self):
class Test010Load(unittest.TestCase):
def test_import(self):
import guestfs

View File

@@ -19,18 +19,18 @@ import unittest
import os
import guestfs
class Test070OptArgs (unittest.TestCase):
def setUp (self):
self.g = guestfs.GuestFS (python_return_dict=True)
class Test070OptArgs(unittest.TestCase):
def setUp(self):
self.g = guestfs.GuestFS(python_return_dict=True)
def test_no_optargs (self):
self.g.add_drive ("/dev/null")
def test_no_optargs(self):
self.g.add_drive("/dev/null")
def test_one_optarg (self):
self.g.add_drive ("/dev/null", readonly = True)
def test_one_optarg(self):
self.g.add_drive("/dev/null", readonly=True)
def test_two_optargs (self):
self.g.add_drive ("/dev/null", iface = "virtio", format = "raw")
def test_two_optargs(self):
self.g.add_drive("/dev/null", iface="virtio", format="raw")
def tearDown (self):
self.g.close ()
def tearDown(self):
self.g.close()

View File

@@ -21,19 +21,19 @@ import os
import guestfs
from .tests_helper import *
class Test080Version (unittest.TestCase):
def setUp (self):
self.g = guestfs.GuestFS (python_return_dict=True)
self.version = self.g.version ()
class Test080Version(unittest.TestCase):
def setUp(self):
self.g = guestfs.GuestFS(python_return_dict=True)
self.version = self.g.version()
def test_major (self):
self.assertEqual (self.version['major'], 1)
def test_major(self):
self.assertEqual(self.version['major'], 1)
def test_minor (self):
self.assertIsInstance (self.version['minor'], int_type)
def test_minor(self):
self.assertIsInstance(self.version['minor'], int_type)
def test_release (self):
self.assertIsInstance (self.version['release'], int_type)
def test_release(self):
self.assertIsInstance(self.version['release'], int_type)
def test_extra (self):
self.assertIsInstance (self.version['extra'], str)
def test_extra(self):
self.assertIsInstance(self.version['extra'], str)

View File

@@ -22,114 +22,114 @@ import guestfs
from .tests_helper import *
class Test090PythonRetValues (unittest.TestCase):
def test_rint (self):
g = guestfs.GuestFS ()
class Test090PythonRetValues(unittest.TestCase):
def test_rint(self):
g = guestfs.GuestFS()
self.assertAlmostEqual (g.internal_test_rint ("10"), 10, places=1)
self.assertAlmostEqual(g.internal_test_rint("10"), 10, places=1)
self.assertRaises (RuntimeError, g.internal_test_rinterr)
self.assertRaises(RuntimeError, g.internal_test_rinterr)
def test_rint64 (self):
g = guestfs.GuestFS ()
def test_rint64(self):
g = guestfs.GuestFS()
self.assertAlmostEqual (g.internal_test_rint64 ("10"), int_type (10), places=1)
self.assertAlmostEqual(g.internal_test_rint64("10"), int_type(10), places=1)
self.assertRaises (RuntimeError, g.internal_test_rint64err)
self.assertRaises(RuntimeError, g.internal_test_rint64err)
def test_rbool (self):
g = guestfs.GuestFS ()
def test_rbool(self):
g = guestfs.GuestFS()
self.assertTrue (g.internal_test_rbool ("true"))
self.assertFalse (g.internal_test_rbool ("false"))
self.assertTrue(g.internal_test_rbool("true"))
self.assertFalse(g.internal_test_rbool("false"))
self.assertRaises (RuntimeError, g.internal_test_rboolerr)
self.assertRaises(RuntimeError, g.internal_test_rboolerr)
def test_rconststring (self):
g = guestfs.GuestFS ()
def test_rconststring(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rconststring ("test"), "static string")
self.assertEqual(g.internal_test_rconststring("test"), "static string")
self.assertRaises (RuntimeError, g.internal_test_rconststringerr)
self.assertRaises(RuntimeError, g.internal_test_rconststringerr)
def test_rconstoptstring (self):
g = guestfs.GuestFS ()
def test_rconstoptstring(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rconstoptstring ("test"), "static string")
self.assertEqual(g.internal_test_rconstoptstring("test"), "static string")
# this never fails
self.assertIsNone (g.internal_test_rconstoptstringerr ())
self.assertIsNone(g.internal_test_rconstoptstringerr())
def test_rstring (self):
g = guestfs.GuestFS ()
def test_rstring(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rstring ("test"), "test")
self.assertEqual(g.internal_test_rstring("test"), "test")
self.assertRaises (RuntimeError, g.internal_test_rstringerr)
self.assertRaises(RuntimeError, g.internal_test_rstringerr)
def test_rstringlist (self):
g = guestfs.GuestFS ()
def test_rstringlist(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rstringlist ("0"), [])
self.assertEqual (g.internal_test_rstringlist ("5"), ["0", "1", "2", "3", "4"])
self.assertEqual(g.internal_test_rstringlist("0"), [])
self.assertEqual(g.internal_test_rstringlist("5"), ["0", "1", "2", "3", "4"])
self.assertRaises (RuntimeError, g.internal_test_rstringlisterr)
self.assertRaises(RuntimeError, g.internal_test_rstringlisterr)
def test_rstruct (self):
g = guestfs.GuestFS ()
def test_rstruct(self):
g = guestfs.GuestFS()
s = g.internal_test_rstruct ("unused")
self.assertIsInstance (s, dict)
self.assertEqual (s["pv_name"], "pv0")
s = g.internal_test_rstruct("unused")
self.assertIsInstance(s, dict)
self.assertEqual(s["pv_name"], "pv0")
self.assertRaises (RuntimeError, g.internal_test_rstructerr)
self.assertRaises(RuntimeError, g.internal_test_rstructerr)
def test_rstructlist (self):
g = guestfs.GuestFS ()
def test_rstructlist(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rstructlist ("0"), [])
l = g.internal_test_rstructlist ("5")
self.assertIsInstance (l, list)
self.assertEqual (len (l), 5)
for i in range (0, 5):
self.assertIsInstance (l[i], dict)
self.assertEqual (l[i]["pv_name"], "pv%d" % i)
self.assertEqual(g.internal_test_rstructlist("0"), [])
l = g.internal_test_rstructlist("5")
self.assertIsInstance(l, list)
self.assertEqual(len(l), 5)
for i in range(0, 5):
self.assertIsInstance(l[i], dict)
self.assertEqual(l[i]["pv_name"], "pv%d" % i)
self.assertRaises (RuntimeError, g.internal_test_rstructlisterr)
self.assertRaises(RuntimeError, g.internal_test_rstructlisterr)
def test_rhashtable_list (self):
g = guestfs.GuestFS (python_return_dict=False)
def test_rhashtable_list(self):
g = guestfs.GuestFS(python_return_dict=False)
self.assertEqual (g.internal_test_rhashtable ("0"), [])
r = g.internal_test_rhashtable ("5")
self.assertEqual (r, [ ("0","0"), ("1","1"), ("2","2"),
("3","3"), ("4","4") ])
self.assertEqual(g.internal_test_rhashtable("0"), [])
r = g.internal_test_rhashtable("5")
self.assertEqual(r, [("0", "0"), ("1", "1"), ("2", "2"),
("3", "3"), ("4", "4")])
self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
self.assertRaises(RuntimeError, g.internal_test_rhashtableerr)
def test_rhashtable_dict (self):
g = guestfs.GuestFS (python_return_dict=True)
def test_rhashtable_dict(self):
g = guestfs.GuestFS(python_return_dict=True)
self.assertEqual (g.internal_test_rhashtable ("0"), {})
r = g.internal_test_rhashtable ("5")
self.assertEqual (r, {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4"})
self.assertEqual(g.internal_test_rhashtable("0"), {})
r = g.internal_test_rhashtable("5")
self.assertEqual(r, {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4"})
self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
self.assertRaises(RuntimeError, g.internal_test_rhashtableerr)
def test_rbufferout (self):
g = guestfs.GuestFS ()
def test_rbufferout(self):
g = guestfs.GuestFS()
self.assertEqual (g.internal_test_rbufferout ("test"), b'test')
self.assertEqual(g.internal_test_rbufferout("test"), b'test')
self.assertRaises (RuntimeError, g.internal_test_rbufferouterr)
self.assertRaises(RuntimeError, g.internal_test_rbufferouterr)

View File

@@ -19,16 +19,16 @@ import unittest
import os
import guestfs
class Test100Launch (unittest.TestCase):
def test_launch (self):
g = guestfs.GuestFS (python_return_dict=True)
g.add_drive_scratch (500 * 1024 * 1024)
g.launch ()
class Test100Launch(unittest.TestCase):
def test_launch(self):
g = guestfs.GuestFS(python_return_dict=True)
g.add_drive_scratch(500 * 1024 * 1024)
g.launch()
g.pvcreate ("/dev/sda")
g.vgcreate ("VG", ["/dev/sda"])
g.lvcreate ("LV1", "VG", 200)
g.lvcreate ("LV2", "VG", 200)
self.assertEqual (g.lvs (), ["/dev/VG/LV1", "/dev/VG/LV2"])
g.shutdown ()
g.close ()
g.pvcreate("/dev/sda")
g.vgcreate("VG", ["/dev/sda"])
g.lvcreate("LV1", "VG", 200)
g.lvcreate("LV2", "VG", 200)
self.assertEqual(g.lvs(), ["/dev/VG/LV1", "/dev/VG/LV2"])
g.shutdown()
g.close()

View File

@@ -21,18 +21,18 @@ import guestfs
close_invoked = 0
def close_callback (ev, eh, buf, array):
def close_callback(ev, eh, buf, array):
global close_invoked
close_invoked += 1
class Test410CloseEvent (unittest.TestCase):
def test_close_event (self):
g = guestfs.GuestFS (python_return_dict=True)
class Test410CloseEvent(unittest.TestCase):
def test_close_event(self):
g = guestfs.GuestFS(python_return_dict=True)
# Register a callback for the close event.
g.set_event_callback (close_callback, guestfs.EVENT_CLOSE)
g.set_event_callback(close_callback, guestfs.EVENT_CLOSE)
# Close the handle. The close callback should be invoked.
self.assertEqual (close_invoked, 0)
g.close ()
self.assertEqual (close_invoked, 1)
self.assertEqual(close_invoked, 0)
g.close()
self.assertEqual(close_invoked, 1)

View File

@@ -21,7 +21,7 @@ import guestfs
log_invoked = 0
def log_callback (ev,eh,buf,array):
def log_callback(ev, eh, buf, array):
global log_invoked
log_invoked += 1
@@ -29,26 +29,26 @@ def log_callback (ev,eh,buf,array):
buf = buf.rstrip()
# Log what happened.
print ("python event logged: event=%s eh=%d buf='%s' array=%s" %
(guestfs.event_to_string (ev), eh, buf, array))
print("python event logged: event=%s eh=%d buf='%s' array=%s" %
(guestfs.event_to_string(ev), eh, buf, array))
class Test420LogMessages (unittest.TestCase):
def test_log_messages (self):
g = guestfs.GuestFS (python_return_dict=True)
class Test420LogMessages(unittest.TestCase):
def test_log_messages(self):
g = guestfs.GuestFS(python_return_dict=True)
# Register an event callback for all log messages.
events = guestfs.EVENT_APPLIANCE | guestfs.EVENT_LIBRARY \
| guestfs.EVENT_WARNING | guestfs.EVENT_TRACE
g.set_event_callback (log_callback, events)
g.set_event_callback(log_callback, events)
# Now make sure we see some messages.
g.set_trace (1)
g.set_verbose (1)
g.set_trace(1)
g.set_verbose(1)
# Do some stuff.
g.add_drive_ro ("/dev/null")
g.set_autosync (1)
g.add_drive_ro("/dev/null")
g.set_autosync(1)
g.close ()
g.close()
self.assertNotEqual (log_invoked, 0)
self.assertNotEqual(log_invoked, 0)

View File

@@ -23,32 +23,32 @@ import guestfs
close_invoked = 0
def close_callback (ev, eh, buf, array):
def close_callback(ev, eh, buf, array):
global close_invoked
close_invoked += 1
class Test800ExplicitClose (unittest.TestCase):
def test_explicit_close (self):
g = guestfs.GuestFS (python_return_dict=True)
class Test800ExplicitClose(unittest.TestCase):
def test_explicit_close(self):
g = guestfs.GuestFS(python_return_dict=True)
g.close () # explicit close
g.close() # explicit close
del g # implicit close - should be no error/warning
# Expect an exception if we call a method on a closed handle.
g = guestfs.GuestFS (python_return_dict=True)
g.close ()
self.assertRaises (guestfs.ClosedHandle, g.set_memsize, 512)
g = guestfs.GuestFS(python_return_dict=True)
g.close()
self.assertRaises(guestfs.ClosedHandle, g.set_memsize, 512)
del g
# Verify that the handle is really being closed by g.close, by
# setting up a close event and testing that it happened.
g = guestfs.GuestFS (python_return_dict=True)
g = guestfs.GuestFS(python_return_dict=True)
g.set_event_callback (close_callback, guestfs.EVENT_CLOSE)
g.set_event_callback(close_callback, guestfs.EVENT_CLOSE)
self.assertEqual (close_invoked, 0)
g.close ()
self.assertEqual (close_invoked, 1)
self.assertEqual(close_invoked, 0)
g.close()
self.assertEqual(close_invoked, 1)
del g
self.assertEqual (close_invoked, 1)
self.assertEqual(close_invoked, 1)

View File

@@ -19,19 +19,19 @@ import unittest
import os
import guestfs
class Test810RHBZ811650 (unittest.TestCase):
def test_rhbz811650 (self):
g = guestfs.GuestFS (python_return_dict=True)
class Test810RHBZ811650(unittest.TestCase):
def test_rhbz811650(self):
g = guestfs.GuestFS(python_return_dict=True)
g.disk_create ("rhbz811650.img", "raw", 500 * 1024 * 1024)
g.disk_create("rhbz811650.img", "raw", 500 * 1024 * 1024)
# Deliberate error: the disk format is supposed to be raw.
g.add_drive ("rhbz811650.img", format="qcow2");
g.add_drive("rhbz811650.img", format="qcow2");
# Because error() wasn't being called, guestfs_last_error
# would return NULL, causing a segfault in the Python bindings
# (RHBZ#811650).
self.assertRaises (RuntimeError, g.launch)
self.assertRaises(RuntimeError, g.launch)
def tearDown (self):
os.unlink ("rhbz811650.img")
def tearDown(self):
os.unlink("rhbz811650.img")

View File

@@ -28,19 +28,19 @@ import sys
import guestfs
from .tests_helper import *
@skipUnlessArchMatches ("(i.86|x86_64)") # If the architecture doesn't support IDE, skip the test.
@skipUnlessGuestfsBackendIs ('libvirt')
@skipUnlessLibvirtHasCPointer ()
class Test820RHBZ912499 (unittest.TestCase):
def setUp (self):
@skipUnlessArchMatches("(i.86|x86_64)") # If the architecture doesn't support IDE, skip the test.
@skipUnlessGuestfsBackendIs('libvirt')
@skipUnlessLibvirtHasCPointer()
class Test820RHBZ912499(unittest.TestCase):
def setUp(self):
# Create a test disk.
self.filename = os.getcwd () + "/820-rhbz912499.img"
guestfs.GuestFS().disk_create (self.filename, "raw", 1024*1024*1024)
self.filename = os.getcwd() + "/820-rhbz912499.img"
guestfs.GuestFS().disk_create(self.filename, "raw", 1024*1024*1024)
# Create a new domain. This won't work, it will just hang when
# booted. But that's sufficient for the test.
self.domname = ''.join (random.choice (string.ascii_uppercase)
for _ in range (8))
self.domname = ''.join(random.choice(string.ascii_uppercase)
for _ in range(8))
self.domname = "tmp-" + self.domname
self.xml = """
@@ -62,33 +62,33 @@ class Test820RHBZ912499 (unittest.TestCase):
</domain>
""" % (self.domname, self.filename)
def test_rhbz912499 (self):
def test_rhbz912499(self):
import libvirt
conn = libvirt.open (None)
dom = conn.createXML (self.xml,
libvirt.VIR_DOMAIN_START_AUTODESTROY)
self.assertIsNotNone (dom)
conn = libvirt.open(None)
dom = conn.createXML(self.xml,
libvirt.VIR_DOMAIN_START_AUTODESTROY)
self.assertIsNotNone(dom)
print ("temporary domain %s is running" % self.domname)
print("temporary domain %s is running" % self.domname)
# Libvirt should have labelled the disk.
print ("before starting libguestfs")
before = check_output (["ls", "-Z", self.filename])
print ("disk label = %s" % before)
print("before starting libguestfs")
before = check_output(["ls", "-Z", self.filename])
print("disk label = %s" % before)
# Now see if we can open the domain with libguestfs without
# disturbing the label.
g = guestfs.GuestFS ()
r = g.add_libvirt_dom (dom, readonly = 1)
self.assertEqual (r, 1)
g.launch ()
g = guestfs.GuestFS()
r = g.add_libvirt_dom(dom, readonly=1)
self.assertEqual(r, 1)
g.launch()
print ("after starting libguestfs")
after = check_output (["ls", "-Z", self.filename])
print ("disk label = %s" % after)
print("after starting libguestfs")
after = check_output(["ls", "-Z", self.filename])
print("disk label = %s" % after)
self.assertEqual (before, after)
self.assertEqual(before, after)
def tearDown (self):
os.unlink (self.filename)
def tearDown(self):
os.unlink(self.filename)

View File

@@ -28,15 +28,15 @@ from .tests_helper import *
guestsdir = os.environ['guestsdir']
@skipUnlessLibvirtHasCPointer ()
class Test910Libvirt (unittest.TestCase):
def test_libvirt (self):
@skipUnlessLibvirtHasCPointer()
class Test910Libvirt(unittest.TestCase):
def test_libvirt(self):
import libvirt
conn = libvirt.open ("test:///%s/guests.xml" % guestsdir)
dom = conn.lookupByName ("blank-disk")
conn = libvirt.open("test:///%s/guests.xml" % guestsdir)
dom = conn.lookupByName("blank-disk")
g = guestfs.GuestFS ()
g = guestfs.GuestFS()
r = g.add_libvirt_dom (dom, readonly=1)
self.assertEqual (r, 1)
r = g.add_libvirt_dom(dom, readonly=1)
self.assertEqual(r, 1)

View File

@@ -27,7 +27,7 @@ else:
int_type = long
def skipUnlessLibvirtHasCPointer ():
def skipUnlessLibvirtHasCPointer():
"""
Skip the current class/method if:
(a) libvirt cannot be imported (e.g. not installed)
@@ -36,35 +36,35 @@ def skipUnlessLibvirtHasCPointer ():
try:
import libvirt
except:
return unittest.skip ("could not import libvirt")
return unittest.skip("could not import libvirt")
# Check we're using the version of libvirt-python that has c_pointer() methods.
if not "c_pointer" in dir (libvirt.open (None)):
return unittest.skip ("libvirt-python doesn't support c_pointer()")
if not "c_pointer" in dir(libvirt.open(None)):
return unittest.skip("libvirt-python doesn't support c_pointer()")
return lambda func: func
def skipUnlessGuestfsBackendIs (wanted):
def skipUnlessGuestfsBackendIs(wanted):
"""
Skip the current class/method if the default backend of libguestfs
is not 'wanted'.
"""
import guestfs
backend = guestfs.GuestFS ().get_backend ()
backend = guestfs.GuestFS().get_backend()
# Match both "backend" and "backend:etc"
if not (backend == wanted or backend.startswith (wanted + ":")):
return unittest.skip ("the current backend is not %s" % wanted)
if not (backend == wanted or backend.startswith(wanted + ":")):
return unittest.skip("the current backend is not %s" % wanted)
return lambda func: func
def skipUnlessArchMatches (arch_re):
def skipUnlessArchMatches(arch_re):
"""
Skip the current class/method if the current architecture does not match
the regexp specified.
"""
import platform
import re
machine = platform.machine ()
rex = re.compile (arch_re)
if not rex.match (machine):
return unittest.skip ("the current architecture (%s) does not match '%s'" % (machine, arch_re))
machine = platform.machine()
rex = re.compile(arch_re)
if not rex.match(machine):
return unittest.skip("the current architecture (%s) does not match '%s'" % (machine, arch_re))
return lambda func: func