pyzfs: python3 support (library 1/2)

These changes are efficient and valid in python 2 and 3. For the
most part, they are also pythonic.

* 2to3 conversion
* add __future__ imports
* iterator changes
* integer division
* relative import fixes

Reviewed-by: John Ramsden <johnramsden@riseup.net>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
Closes #8096
This commit is contained in:
Antonio Russo 2018-08-22 06:59:51 -04:00 committed by Brian Behlendorf
parent 0b8e4418b6
commit 9de8c0cd7f
13 changed files with 141 additions and 122 deletions

View File

@ -38,6 +38,7 @@ please visit its `GitHub repository <https://github.com/zfsonlinux/zfs>`_.
Maximum length of any ZFS name. Maximum length of any ZFS name.
''' '''
from __future__ import absolute_import, division, print_function
from ._constants import ( from ._constants import (
MAXNAMELEN, MAXNAMELEN,

View File

@ -18,10 +18,12 @@
Important `libzfs_core` constants. Important `libzfs_core` constants.
""" """
from __future__ import absolute_import, division, print_function
# https://stackoverflow.com/a/1695250 # https://stackoverflow.com/a/1695250
def enum(*sequential, **named): def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named) enums = dict(((b, a) for a, b in enumerate(sequential)), **named)
return type('Enum', (), enums) return type('Enum', (), enums)

View File

@ -26,6 +26,7 @@ corresponding interface functions.
The parameters and exceptions are documented in the `libzfs_core` interfaces. The parameters and exceptions are documented in the `libzfs_core` interfaces.
""" """
from __future__ import absolute_import, division, print_function
import errno import errno
import re import re
@ -102,8 +103,9 @@ def lzc_snapshot_translate_errors(ret, errlist, snaps, props):
def _map(ret, name): def _map(ret, name):
if ret == errno.EXDEV: if ret == errno.EXDEV:
pool_names = map(_pool_name, snaps) pool_names = iter(map(_pool_name, snaps))
same_pool = all(x == pool_names[0] for x in pool_names) pool_name = next(pool_names, None)
same_pool = all(x == pool_name for x in pool_names)
if same_pool: if same_pool:
return lzc_exc.DuplicateSnapshots(name) return lzc_exc.DuplicateSnapshots(name)
else: else:
@ -270,7 +272,8 @@ def lzc_hold_translate_errors(ret, errlist, holds, fd):
def lzc_release_translate_errors(ret, errlist, holds): def lzc_release_translate_errors(ret, errlist, holds):
if ret == 0: if ret == 0:
return return
for _, hold_list in holds.iteritems(): for snap in holds:
hold_list = holds[snap]
if not isinstance(hold_list, list): if not isinstance(hold_list, list):
raise lzc_exc.TypeError('holds must be in a list') raise lzc_exc.TypeError('holds must be in a list')
@ -705,15 +708,17 @@ def _handle_err_list(ret, errlist, names, exception, mapper):
if len(errlist) == 0: if len(errlist) == 0:
suppressed_count = 0 suppressed_count = 0
names = list(zip(names, range(2)))
if len(names) == 1: if len(names) == 1:
name = names[0] name, _ = names[0]
else: else:
name = None name = None
errors = [mapper(ret, name)] errors = [mapper(ret, name)]
else: else:
errors = [] errors = []
suppressed_count = errlist.pop('N_MORE_ERRORS', 0) suppressed_count = errlist.pop('N_MORE_ERRORS', 0)
for name, err in errlist.iteritems(): for name in errlist:
err = errlist[name]
errors.append(mapper(err, name)) errors.append(mapper(err, name))
raise exception(errors, suppressed_count) raise exception(errors, suppressed_count)

View File

@ -26,6 +26,7 @@ increased convenience. Output parameters are not used and return values
are directly returned. Error conditions are signalled by exceptions are directly returned. Error conditions are signalled by exceptions
rather than by integer error codes. rather than by integer error codes.
""" """
from __future__ import absolute_import, division, print_function
import errno import errno
import functools import functools
@ -485,8 +486,8 @@ def lzc_hold(holds, fd=None):
errors.lzc_hold_translate_errors(ret, errlist, holds, fd) errors.lzc_hold_translate_errors(ret, errlist, holds, fd)
# If there is no error (no exception raised by _handleErrList), but errlist # If there is no error (no exception raised by _handleErrList), but errlist
# is not empty, then it contains missing snapshots. # is not empty, then it contains missing snapshots.
assert all(x == errno.ENOENT for x in errlist.itervalues()) assert all(errlist[x] == errno.ENOENT for x in errlist)
return errlist.keys() return list(errlist.keys())
def lzc_release(holds): def lzc_release(holds):
@ -521,7 +522,8 @@ def lzc_release(holds):
''' '''
errlist = {} errlist = {}
holds_dict = {} holds_dict = {}
for snap, hold_list in holds.iteritems(): for snap in holds:
hold_list = holds[snap]
if not isinstance(hold_list, list): if not isinstance(hold_list, list):
raise TypeError('holds must be in a list') raise TypeError('holds must be in a list')
holds_dict[snap] = {hold: None for hold in hold_list} holds_dict[snap] = {hold: None for hold in hold_list}
@ -531,8 +533,8 @@ def lzc_release(holds):
errors.lzc_release_translate_errors(ret, errlist, holds) errors.lzc_release_translate_errors(ret, errlist, holds)
# If there is no error (no exception raised by _handleErrList), but errlist # If there is no error (no exception raised by _handleErrList), but errlist
# is not empty, then it contains missing snapshots and tags. # is not empty, then it contains missing snapshots and tags.
assert all(x == errno.ENOENT for x in errlist.itervalues()) assert all(errlist[x] == errno.ENOENT for x in errlist)
return errlist.keys() return list(errlist.keys())
def lzc_get_holds(snapname): def lzc_get_holds(snapname):
@ -1873,9 +1875,9 @@ def lzc_get_props(name):
mountpoint_val = '/' + name mountpoint_val = '/' + name
else: else:
mountpoint_val = None mountpoint_val = None
result = {k: v['value'] for k, v in result.iteritems()} result = {k: result[k]['value'] for k in result}
if 'clones' in result: if 'clones' in result:
result['clones'] = result['clones'].keys() result['clones'] = list(result['clones'].keys())
if mountpoint_val is not None: if mountpoint_val is not None:
result['mountpoint'] = mountpoint_val result['mountpoint'] = mountpoint_val
return result return result

View File

@ -47,6 +47,7 @@ Format:
- a value can be a list of dictionaries that adhere to this format - a value can be a list of dictionaries that adhere to this format
- all elements of a list value must be of the same type - all elements of a list value must be of the same type
""" """
from __future__ import absolute_import, division, print_function
import numbers import numbers
from collections import namedtuple from collections import namedtuple

View File

@ -19,6 +19,7 @@ The package that contains a module per each C library that
`libzfs_core` uses. The modules expose CFFI objects required `libzfs_core` uses. The modules expose CFFI objects required
to make calls to functions in the libraries. to make calls to functions in the libraries.
""" """
from __future__ import absolute_import, division, print_function
import threading import threading
import importlib import importlib
@ -47,7 +48,7 @@ def _setup_cffi():
ffi = FFI() ffi = FFI()
for module_name in MODULES: for module_name in MODULES:
module = importlib.import_module("." + module_name, __package__) module = importlib.import_module("." + module_name, __name__)
ffi.cdef(module.CDEF) ffi.cdef(module.CDEF)
lib = LazyLibrary(ffi, module.LIBRARY) lib = LazyLibrary(ffi, module.LIBRARY)
setattr(module, "ffi", ffi) setattr(module, "ffi", ffi)

View File

@ -17,6 +17,7 @@
""" """
Python bindings for ``libnvpair``. Python bindings for ``libnvpair``.
""" """
from __future__ import absolute_import, division, print_function
CDEF = """ CDEF = """
typedef ... nvlist_t; typedef ... nvlist_t;

View File

@ -17,6 +17,7 @@
""" """
Python bindings for ``libzfs_core``. Python bindings for ``libzfs_core``.
""" """
from __future__ import absolute_import, division, print_function
CDEF = """ CDEF = """

View File

@ -17,6 +17,7 @@
""" """
Utility functions for casting to a specific C type. Utility functions for casting to a specific C type.
""" """
from __future__ import absolute_import, division, print_function
from .bindings.libnvpair import ffi as _ffi from .bindings.libnvpair import ffi as _ffi

View File

@ -17,6 +17,7 @@
""" """
Exceptions that can be raised by libzfs_core operations. Exceptions that can be raised by libzfs_core operations.
""" """
from __future__ import absolute_import, division, print_function
import errno import errno
from ._constants import ( from ._constants import (

View File

@ -21,6 +21,7 @@ These are mostly functional and conformance tests that validate
that the operations produce expected effects or fail with expected that the operations produce expected effects or fail with expected
exceptions. exceptions.
""" """
from __future__ import absolute_import, division, print_function
import unittest import unittest
import contextlib import contextlib
@ -44,8 +45,8 @@ from .._nvlist import packed_nvlist_out
def _print(*args): def _print(*args):
for arg in args: for arg in args:
print arg, print(arg, end=' ')
print print()
@contextlib.contextmanager @contextlib.contextmanager
@ -76,7 +77,7 @@ def _zfs_mount(fs):
with suppress(): with suppress():
subprocess.check_output(unmount_cmd, stderr=subprocess.STDOUT) subprocess.check_output(unmount_cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print 'failed to mount %s @ %s : %s' % (fs, mntdir, e.output) print('failed to mount %s @ %s : %s' % (fs, mntdir, e.output))
raise raise
finally: finally:
os.rmdir(mntdir) os.rmdir(mntdir)
@ -444,10 +445,10 @@ class ZFSTest(unittest.TestCase):
} }
key = os.urandom(lzc.WRAPPING_KEY_LEN) key = os.urandom(lzc.WRAPPING_KEY_LEN)
lzc.lzc_create(name, 'zfs', props=props, key=key) lzc.lzc_create(name, 'zfs', props=props, key=key)
self.assertEquals(fs.getProperty("encryption"), "aes-256-ccm") self.assertEqual(fs.getProperty("encryption"), "aes-256-ccm")
self.assertEquals(fs.getProperty("encryptionroot"), name) self.assertEqual(fs.getProperty("encryptionroot"), name)
self.assertEquals(fs.getProperty("keylocation"), filename) self.assertEqual(fs.getProperty("keylocation"), filename)
self.assertEquals(fs.getProperty("keyformat"), "raw") self.assertEqual(fs.getProperty("keyformat"), "raw")
def test_snapshot(self): def test_snapshot(self):
snapname = ZFSTest.pool.makeName("@snap") snapname = ZFSTest.pool.makeName("@snap")
@ -475,7 +476,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps, props) lzc.lzc_snapshot(snaps, props)
self.assertEquals(len(ctx.exception.errors), len(snaps)) self.assertEqual(len(ctx.exception.errors), len(snaps))
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.PropertyInvalid) self.assertIsInstance(e, lzc_exc.PropertyInvalid)
self.assertNotExists(snapname) self.assertNotExists(snapname)
@ -489,7 +490,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# NB: one common error is reported. # NB: one common error is reported.
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.ReadOnlyPool) self.assertIsInstance(e, lzc_exc.ReadOnlyPool)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -502,7 +503,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.FilesystemNotFound) self.assertIsInstance(e, lzc_exc.FilesystemNotFound)
@ -513,7 +514,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.FilesystemNotFound) self.assertIsInstance(e, lzc_exc.FilesystemNotFound)
@ -525,7 +526,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.FilesystemNotFound) self.assertIsInstance(e, lzc_exc.FilesystemNotFound)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -540,7 +541,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# XXX two errors should be reported but alas # XXX two errors should be reported but alas
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.DuplicateSnapshots) self.assertIsInstance(e, lzc_exc.DuplicateSnapshots)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -554,7 +555,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 2) self.assertEqual(len(ctx.exception.errors), 2)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.FilesystemNotFound) self.assertIsInstance(e, lzc_exc.FilesystemNotFound)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -569,7 +570,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.SnapshotExists) self.assertIsInstance(e, lzc_exc.SnapshotExists)
@ -581,7 +582,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.DuplicateSnapshots) self.assertIsInstance(e, lzc_exc.DuplicateSnapshots)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -662,7 +663,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# NB: one common error is reported. # NB: one common error is reported.
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.PoolsDiffer) self.assertIsInstance(e, lzc_exc.PoolsDiffer)
self.assertNotExists(snapname1) self.assertNotExists(snapname1)
@ -677,7 +678,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# NB: one common error is reported. # NB: one common error is reported.
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
# NB: depending on whether the first attempted snapshot is # NB: depending on whether the first attempted snapshot is
# for the read-only pool a different error is reported. # for the read-only pool a different error is reported.
@ -696,7 +697,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# NB: one common error is reported. # NB: one common error is reported.
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
self.assertIsNone(e.name) self.assertIsNone(e.name)
@ -710,7 +711,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotFailure) as ctx:
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
self.assertEquals(len(ctx.exception.errors), 2) self.assertEqual(len(ctx.exception.errors), 2)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertIsNotNone(e.name) self.assertIsNotNone(e.name)
@ -725,7 +726,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot(snaps) lzc.lzc_snapshot(snaps)
# NB: one common error is reported. # NB: one common error is reported.
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertIsNone(e.name) self.assertIsNone(e.name)
@ -914,7 +915,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotDestructionFailure) as ctx: with self.assertRaises(lzc_exc.SnapshotDestructionFailure) as ctx:
lzc.lzc_destroy_snaps(snaps, False) lzc.lzc_destroy_snaps(snaps, False)
self.assertEquals(len(ctx.exception.errors), 1) self.assertEqual(len(ctx.exception.errors), 1)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.SnapshotIsCloned) self.assertIsInstance(e, lzc_exc.SnapshotIsCloned)
for snap in snaps: for snap in snaps:
@ -1229,19 +1230,19 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_destroy_snaps([snap1, snap2], defer=False) lzc.lzc_destroy_snaps([snap1, snap2], defer=False)
bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1')) bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1'))
self.assertEquals(len(bmarks), 3) self.assertEqual(len(bmarks), 3)
for b in 'bmark', 'bmark1', 'bmark2': for b in 'bmark', 'bmark1', 'bmark2':
self.assertIn(b, bmarks) self.assertIn(b, bmarks)
self.assertIsInstance(bmarks[b], dict) self.assertIsInstance(bmarks[b], dict)
self.assertEquals(len(bmarks[b]), 0) self.assertEqual(len(bmarks[b]), 0)
bmarks = lzc.lzc_get_bookmarks( bmarks = lzc.lzc_get_bookmarks(
ZFSTest.pool.makeName('fs1'), ['guid', 'createtxg', 'creation']) ZFSTest.pool.makeName('fs1'), ['guid', 'createtxg', 'creation'])
self.assertEquals(len(bmarks), 3) self.assertEqual(len(bmarks), 3)
for b in 'bmark', 'bmark1', 'bmark2': for b in 'bmark', 'bmark1', 'bmark2':
self.assertIn(b, bmarks) self.assertIn(b, bmarks)
self.assertIsInstance(bmarks[b], dict) self.assertIsInstance(bmarks[b], dict)
self.assertEquals(len(bmarks[b]), 3) self.assertEqual(len(bmarks[b]), 3)
@skipUnlessBookmarksSupported @skipUnlessBookmarksSupported
def test_get_bookmarks_invalid_property(self): def test_get_bookmarks_invalid_property(self):
@ -1254,11 +1255,11 @@ class ZFSTest(unittest.TestCase):
bmarks = lzc.lzc_get_bookmarks( bmarks = lzc.lzc_get_bookmarks(
ZFSTest.pool.makeName('fs1'), ['badprop']) ZFSTest.pool.makeName('fs1'), ['badprop'])
self.assertEquals(len(bmarks), 1) self.assertEqual(len(bmarks), 1)
for b in ('bmark', ): for b in ('bmark', ):
self.assertIn(b, bmarks) self.assertIn(b, bmarks)
self.assertIsInstance(bmarks[b], dict) self.assertIsInstance(bmarks[b], dict)
self.assertEquals(len(bmarks[b]), 0) self.assertEqual(len(bmarks[b]), 0)
@skipUnlessBookmarksSupported @skipUnlessBookmarksSupported
def test_get_bookmarks_nonexistent_fs(self): def test_get_bookmarks_nonexistent_fs(self):
@ -1277,7 +1278,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_destroy_bookmarks( lzc.lzc_destroy_bookmarks(
[bmark, ZFSTest.pool.makeName('fs1#nonexistent')]) [bmark, ZFSTest.pool.makeName('fs1#nonexistent')])
bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1')) bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1'))
self.assertEquals(len(bmarks), 0) self.assertEqual(len(bmarks), 0)
@skipUnlessBookmarksSupported @skipUnlessBookmarksSupported
def test_destroy_bookmarks_invalid_name(self): def test_destroy_bookmarks_invalid_name(self):
@ -1295,7 +1296,7 @@ class ZFSTest(unittest.TestCase):
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1')) bmarks = lzc.lzc_get_bookmarks(ZFSTest.pool.makeName('fs1'))
self.assertEquals(len(bmarks), 1) self.assertEqual(len(bmarks), 1)
self.assertIn('bmark', bmarks) self.assertIn('bmark', bmarks)
@skipUnlessBookmarksSupported @skipUnlessBookmarksSupported
@ -1316,11 +1317,11 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot([snap3]) lzc.lzc_snapshot([snap3])
space = lzc.lzc_snaprange_space(snap1, snap2) space = lzc.lzc_snaprange_space(snap1, snap2)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_snaprange_space(snap2, snap3) space = lzc.lzc_snaprange_space(snap2, snap3)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_snaprange_space(snap1, snap3) space = lzc.lzc_snaprange_space(snap1, snap3)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
def test_snaprange_space_2(self): def test_snaprange_space_2(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1355,7 +1356,7 @@ class ZFSTest(unittest.TestCase):
space = lzc.lzc_snaprange_space(snap, snap) space = lzc.lzc_snaprange_space(snap, snap)
self.assertGreater(space, 1024 * 1024) self.assertGreater(space, 1024 * 1024)
self.assertAlmostEqual(space, 1024 * 1024, delta=1024 * 1024 / 20) self.assertAlmostEqual(space, 1024 * 1024, delta=1024 * 1024 // 20)
def test_snaprange_space_wrong_order(self): def test_snaprange_space_wrong_order(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1395,11 +1396,11 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_snaprange_space(snap1, snap2) lzc.lzc_snaprange_space(snap1, snap2)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_snaprange_space(snap2, snap1) lzc.lzc_snaprange_space(snap2, snap1)
self.assertEquals(ctx.exception.name, snap1) self.assertEqual(ctx.exception.name, snap1)
def test_snaprange_space_invalid_name(self): def test_snaprange_space_invalid_name(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1442,17 +1443,17 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot([snap3]) lzc.lzc_snapshot([snap3])
space = lzc.lzc_send_space(snap2, snap1) space = lzc.lzc_send_space(snap2, snap1)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_send_space(snap3, snap2) space = lzc.lzc_send_space(snap3, snap2)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_send_space(snap3, snap1) space = lzc.lzc_send_space(snap3, snap1)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_send_space(snap1) space = lzc.lzc_send_space(snap1)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_send_space(snap2) space = lzc.lzc_send_space(snap2)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
space = lzc.lzc_send_space(snap3) space = lzc.lzc_send_space(snap3)
self.assertIsInstance(space, (int, long)) self.assertIsInstance(space, (int, int))
def test_send_space_2(self): def test_send_space_2(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1481,7 +1482,7 @@ class ZFSTest(unittest.TestCase):
self.assertGreater(space, 1024 * 1024) self.assertGreater(space, 1024 * 1024)
space = lzc.lzc_send_space(snap3) space = lzc.lzc_send_space(snap3)
self.assertEquals(space, space_empty) self.assertEqual(space, space_empty)
def test_send_space_same_snap(self): def test_send_space_same_snap(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1527,15 +1528,15 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send_space(snap1, snap2) lzc.lzc_send_space(snap1, snap2)
self.assertEquals(ctx.exception.name, snap1) self.assertEqual(ctx.exception.name, snap1)
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send_space(snap2, snap1) lzc.lzc_send_space(snap2, snap1)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send_space(snap2) lzc.lzc_send_space(snap2)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
def test_send_space_invalid_name(self): def test_send_space_invalid_name(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1545,13 +1546,13 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send_space(snap2, snap1) lzc.lzc_send_space(snap2, snap1)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send_space(snap2) lzc.lzc_send_space(snap2)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send_space(snap1, snap2) lzc.lzc_send_space(snap1, snap2)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
def test_send_space_not_snap(self): def test_send_space_not_snap(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1594,7 +1595,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_send(snap, None, fd) lzc.lzc_send(snap, None, fd)
st = os.fstat(fd) st = os.fstat(fd)
# 5%, arbitrary. # 5%, arbitrary.
self.assertAlmostEqual(st.st_size, estimate, delta=estimate / 20) self.assertAlmostEqual(st.st_size, estimate, delta=estimate // 20)
def test_send_incremental(self): def test_send_incremental(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1615,7 +1616,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_send(snap2, snap1, fd) lzc.lzc_send(snap2, snap1, fd)
st = os.fstat(fd) st = os.fstat(fd)
# 5%, arbitrary. # 5%, arbitrary.
self.assertAlmostEqual(st.st_size, estimate, delta=estimate / 20) self.assertAlmostEqual(st.st_size, estimate, delta=estimate // 20)
def test_send_flags(self): def test_send_flags(self):
flags = ['embedded_data', 'large_blocks', 'compress', 'raw'] flags = ['embedded_data', 'large_blocks', 'compress', 'raw']
@ -1688,15 +1689,15 @@ class ZFSTest(unittest.TestCase):
fd = output.fileno() fd = output.fileno()
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send(snap1, snap2, fd) lzc.lzc_send(snap1, snap2, fd)
self.assertEquals(ctx.exception.name, snap1) self.assertEqual(ctx.exception.name, snap1)
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send(snap2, snap1, fd) lzc.lzc_send(snap2, snap1, fd)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx: with self.assertRaises(lzc_exc.SnapshotNotFound) as ctx:
lzc.lzc_send(snap2, None, fd) lzc.lzc_send(snap2, None, fd)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
def test_send_invalid_name(self): def test_send_invalid_name(self):
snap1 = ZFSTest.pool.makeName("fs1@snap1") snap1 = ZFSTest.pool.makeName("fs1@snap1")
@ -1708,13 +1709,13 @@ class ZFSTest(unittest.TestCase):
fd = output.fileno() fd = output.fileno()
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send(snap2, snap1, fd) lzc.lzc_send(snap2, snap1, fd)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send(snap2, None, fd) lzc.lzc_send(snap2, None, fd)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
with self.assertRaises(lzc_exc.NameInvalid) as ctx: with self.assertRaises(lzc_exc.NameInvalid) as ctx:
lzc.lzc_send(snap1, snap2, fd) lzc.lzc_send(snap1, snap2, fd)
self.assertEquals(ctx.exception.name, snap2) self.assertEqual(ctx.exception.name, snap2)
# XXX Although undocumented the API allows to create an incremental # XXX Although undocumented the API allows to create an incremental
# or full stream for a filesystem as if a temporary unnamed snapshot # or full stream for a filesystem as if a temporary unnamed snapshot
@ -1784,7 +1785,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.StreamIOError) as ctx: with self.assertRaises(lzc_exc.StreamIOError) as ctx:
lzc.lzc_send(snap, None, bad_fd) lzc.lzc_send(snap, None, bad_fd)
self.assertEquals(ctx.exception.errno, errno.EBADF) self.assertEqual(ctx.exception.errno, errno.EBADF)
def test_send_bad_fd_2(self): def test_send_bad_fd_2(self):
snap = ZFSTest.pool.makeName("fs1@snap") snap = ZFSTest.pool.makeName("fs1@snap")
@ -1792,7 +1793,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.StreamIOError) as ctx: with self.assertRaises(lzc_exc.StreamIOError) as ctx:
lzc.lzc_send(snap, None, -2) lzc.lzc_send(snap, None, -2)
self.assertEquals(ctx.exception.errno, errno.EBADF) self.assertEqual(ctx.exception.errno, errno.EBADF)
def test_send_bad_fd_3(self): def test_send_bad_fd_3(self):
snap = ZFSTest.pool.makeName("fs1@snap") snap = ZFSTest.pool.makeName("fs1@snap")
@ -1805,7 +1806,7 @@ class ZFSTest(unittest.TestCase):
bad_fd = hard + 1 bad_fd = hard + 1
with self.assertRaises(lzc_exc.StreamIOError) as ctx: with self.assertRaises(lzc_exc.StreamIOError) as ctx:
lzc.lzc_send(snap, None, bad_fd) lzc.lzc_send(snap, None, bad_fd)
self.assertEquals(ctx.exception.errno, errno.EBADF) self.assertEqual(ctx.exception.errno, errno.EBADF)
def test_send_to_broken_pipe(self): def test_send_to_broken_pipe(self):
snap = ZFSTest.pool.makeName("fs1@snap") snap = ZFSTest.pool.makeName("fs1@snap")
@ -1815,7 +1816,7 @@ class ZFSTest(unittest.TestCase):
proc.wait() proc.wait()
with self.assertRaises(lzc_exc.StreamIOError) as ctx: with self.assertRaises(lzc_exc.StreamIOError) as ctx:
lzc.lzc_send(snap, None, proc.stdin.fileno()) lzc.lzc_send(snap, None, proc.stdin.fileno())
self.assertEquals(ctx.exception.errno, errno.EPIPE) self.assertEqual(ctx.exception.errno, errno.EPIPE)
def test_send_to_broken_pipe_2(self): def test_send_to_broken_pipe_2(self):
snap = ZFSTest.pool.makeName("fs1@snap") snap = ZFSTest.pool.makeName("fs1@snap")
@ -1845,7 +1846,7 @@ class ZFSTest(unittest.TestCase):
with self.assertRaises(lzc_exc.StreamIOError) as ctx: with self.assertRaises(lzc_exc.StreamIOError) as ctx:
lzc.lzc_send(snap, None, fd) lzc.lzc_send(snap, None, fd)
os.close(fd) os.close(fd)
self.assertEquals(ctx.exception.errno, errno.EBADF) self.assertEqual(ctx.exception.errno, errno.EBADF)
def test_recv_full(self): def test_recv_full(self):
src = ZFSTest.pool.makeName("fs1@snap") src = ZFSTest.pool.makeName("fs1@snap")
@ -2038,7 +2039,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_receive(dst, stream.fileno(), origin=origin1) lzc.lzc_receive(dst, stream.fileno(), origin=origin1)
origin = ZFSTest.pool.getFilesystem("fs2/received-30").getProperty( origin = ZFSTest.pool.getFilesystem("fs2/received-30").getProperty(
'origin') 'origin')
self.assertEquals(origin, origin1) self.assertEqual(origin, origin1)
stream.seek(0) stream.seek(0)
# because origin snap does not exist can't receive as a clone of it # because origin snap does not exist can't receive as a clone of it
with self.assertRaises(( with self.assertRaises((
@ -2745,8 +2746,8 @@ class ZFSTest(unittest.TestCase):
(header, c_header) = lzc.receive_header(stream.fileno()) (header, c_header) = lzc.receive_header(stream.fileno())
lzc.lzc_receive_one(tosnap, stream.fileno(), c_header, props=props) lzc.lzc_receive_one(tosnap, stream.fileno(), c_header, props=props)
self.assertExists(tosnap) self.assertExists(tosnap)
self.assertEquals(fs.getProperty("compression", "received"), "on") self.assertEqual(fs.getProperty("compression", "received"), "on")
self.assertEquals(fs.getProperty("ns:prop", "received"), "val") self.assertEqual(fs.getProperty("ns:prop", "received"), "val")
def test_recv_one_invalid_prop(self): def test_recv_one_invalid_prop(self):
fromsnap = ZFSTest.pool.makeName("fs1@snap1") fromsnap = ZFSTest.pool.makeName("fs1@snap1")
@ -2766,10 +2767,10 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_receive_one( lzc.lzc_receive_one(
tosnap, stream.fileno(), c_header, props=props) tosnap, stream.fileno(), c_header, props=props)
self.assertExists(tosnap) self.assertExists(tosnap)
self.assertEquals(fs.getProperty("atime", "received"), "off") self.assertEqual(fs.getProperty("atime", "received"), "off")
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.PropertyInvalid) self.assertIsInstance(e, lzc_exc.PropertyInvalid)
self.assertEquals(e.name, "exec") self.assertEqual(e.name, "exec")
def test_recv_with_cmdprops(self): def test_recv_with_cmdprops(self):
fromsnap = ZFSTest.pool.makeName("fs1@snap1") fromsnap = ZFSTest.pool.makeName("fs1@snap1")
@ -2790,8 +2791,8 @@ class ZFSTest(unittest.TestCase):
tosnap, stream.fileno(), c_header, props=props, tosnap, stream.fileno(), c_header, props=props,
cmdprops=cmdprops) cmdprops=cmdprops)
self.assertExists(tosnap) self.assertExists(tosnap)
self.assertEquals(fs.getProperty("compression"), "on") self.assertEqual(fs.getProperty("compression"), "on")
self.assertEquals(fs.getProperty("ns:prop"), "val") self.assertEqual(fs.getProperty("ns:prop"), "val")
def test_recv_with_cmdprops_and_recvprops(self): def test_recv_with_cmdprops_and_recvprops(self):
fromsnap = ZFSTest.pool.makeName("fs1@snap1") fromsnap = ZFSTest.pool.makeName("fs1@snap1")
@ -2817,12 +2818,12 @@ class ZFSTest(unittest.TestCase):
tosnap, stream.fileno(), c_header, props=props, tosnap, stream.fileno(), c_header, props=props,
cmdprops=cmdprops) cmdprops=cmdprops)
self.assertExists(tosnap) self.assertExists(tosnap)
self.assertEquals(fs.getProperty("atime", True), "on") self.assertEqual(fs.getProperty("atime", True), "on")
self.assertEquals(fs.getProperty("exec", True), "off") self.assertEqual(fs.getProperty("exec", True), "off")
self.assertEquals(fs.getProperty("ns:prop", True), "abc") self.assertEqual(fs.getProperty("ns:prop", True), "abc")
self.assertEquals(fs.getProperty("compression"), "on") self.assertEqual(fs.getProperty("compression"), "on")
self.assertEquals(fs.getProperty("ns:prop"), "def") self.assertEqual(fs.getProperty("ns:prop"), "def")
self.assertEquals(fs.getProperty("exec"), "on") self.assertEqual(fs.getProperty("exec"), "on")
def test_recv_incr_across_clone_branch_point_no_origin(self): def test_recv_incr_across_clone_branch_point_no_origin(self):
origfs = ZFSTest.pool.makeName("fs2") origfs = ZFSTest.pool.makeName("fs2")
@ -3059,7 +3060,7 @@ class ZFSTest(unittest.TestCase):
snap = ZFSTest.pool.getRoot().getFilesystem().getSnap() snap = ZFSTest.pool.getRoot().getFilesystem().getSnap()
snaps = lzc.lzc_hold({snap: 'tag'}) snaps = lzc.lzc_hold({snap: 'tag'})
self.assertEquals([snap], snaps) self.assertEqual([snap], snaps)
def test_hold_missing_fs_auto_cleanup(self): def test_hold_missing_fs_auto_cleanup(self):
# XXX skip pre-created filesystems # XXX skip pre-created filesystems
@ -3072,7 +3073,7 @@ class ZFSTest(unittest.TestCase):
with cleanup_fd() as fd: with cleanup_fd() as fd:
snaps = lzc.lzc_hold({snap: 'tag'}, fd) snaps = lzc.lzc_hold({snap: 'tag'}, fd)
self.assertEquals([snap], snaps) self.assertEqual([snap], snaps)
def test_hold_duplicate(self): def test_hold_duplicate(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
@ -3107,7 +3108,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: tag}, fd) lzc.lzc_hold({snap: tag}, fd)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertEquals(e.name, tag) self.assertEqual(e.name, tag)
# Apparently the full snapshot name is not checked for length # Apparently the full snapshot name is not checked for length
# and this snapshot is treated as simply missing. # and this snapshot is treated as simply missing.
@ -3119,7 +3120,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag'}, fd) lzc.lzc_hold({snap: 'tag'}, fd)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_hold_too_long_snap_name_2(self): def test_hold_too_long_snap_name_2(self):
snap = ZFSTest.pool.getRoot().getTooLongSnap(True) snap = ZFSTest.pool.getRoot().getTooLongSnap(True)
@ -3128,7 +3129,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag'}, fd) lzc.lzc_hold({snap: 'tag'}, fd)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_hold_invalid_snap_name(self): def test_hold_invalid_snap_name(self):
snap = ZFSTest.pool.getRoot().getSnap() + '@bad' snap = ZFSTest.pool.getRoot().getSnap() + '@bad'
@ -3137,7 +3138,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag'}, fd) lzc.lzc_hold({snap: 'tag'}, fd)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_hold_invalid_snap_name_2(self): def test_hold_invalid_snap_name_2(self):
snap = ZFSTest.pool.getRoot().getFilesystem().getName() snap = ZFSTest.pool.getRoot().getFilesystem().getName()
@ -3146,7 +3147,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag'}, fd) lzc.lzc_hold({snap: 'tag'}, fd)
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_get_holds(self): def test_get_holds(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
@ -3157,10 +3158,10 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag2'}, fd) lzc.lzc_hold({snap: 'tag2'}, fd)
holds = lzc.lzc_get_holds(snap) holds = lzc.lzc_get_holds(snap)
self.assertEquals(len(holds), 2) self.assertEqual(len(holds), 2)
self.assertIn('tag1', holds) self.assertIn('tag1', holds)
self.assertIn('tag2', holds) self.assertIn('tag2', holds)
self.assertIsInstance(holds['tag1'], (int, long)) self.assertIsInstance(holds['tag1'], (int, int))
def test_get_holds_after_auto_cleanup(self): def test_get_holds_after_auto_cleanup(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
@ -3171,7 +3172,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag2'}, fd) lzc.lzc_hold({snap: 'tag2'}, fd)
holds = lzc.lzc_get_holds(snap) holds = lzc.lzc_get_holds(snap)
self.assertEquals(len(holds), 0) self.assertEqual(len(holds), 0)
self.assertIsInstance(holds, dict) self.assertIsInstance(holds, dict)
def test_get_holds_nonexistent_snap(self): def test_get_holds_nonexistent_snap(self):
@ -3208,11 +3209,11 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap: 'tag'}) lzc.lzc_hold({snap: 'tag'})
ret = lzc.lzc_release({snap: ['tag']}) ret = lzc.lzc_release({snap: ['tag']})
self.assertEquals(len(ret), 0) self.assertEqual(len(ret), 0)
def test_release_hold_empty(self): def test_release_hold_empty(self):
ret = lzc.lzc_release({}) ret = lzc.lzc_release({})
self.assertEquals(len(ret), 0) self.assertEqual(len(ret), 0)
def test_release_hold_complex(self): def test_release_hold_complex(self):
snap1 = ZFSTest.pool.getRoot().getSnap() snap1 = ZFSTest.pool.getRoot().getSnap()
@ -3228,11 +3229,11 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_hold({snap3: 'tag2'}) lzc.lzc_hold({snap3: 'tag2'})
holds = lzc.lzc_get_holds(snap1) holds = lzc.lzc_get_holds(snap1)
self.assertEquals(len(holds), 2) self.assertEqual(len(holds), 2)
holds = lzc.lzc_get_holds(snap2) holds = lzc.lzc_get_holds(snap2)
self.assertEquals(len(holds), 1) self.assertEqual(len(holds), 1)
holds = lzc.lzc_get_holds(snap3) holds = lzc.lzc_get_holds(snap3)
self.assertEquals(len(holds), 2) self.assertEqual(len(holds), 2)
release = { release = {
snap1: ['tag1', 'tag2'], snap1: ['tag1', 'tag2'],
@ -3240,19 +3241,19 @@ class ZFSTest(unittest.TestCase):
snap3: ['tag2'], snap3: ['tag2'],
} }
ret = lzc.lzc_release(release) ret = lzc.lzc_release(release)
self.assertEquals(len(ret), 0) self.assertEqual(len(ret), 0)
holds = lzc.lzc_get_holds(snap1) holds = lzc.lzc_get_holds(snap1)
self.assertEquals(len(holds), 0) self.assertEqual(len(holds), 0)
holds = lzc.lzc_get_holds(snap2) holds = lzc.lzc_get_holds(snap2)
self.assertEquals(len(holds), 0) self.assertEqual(len(holds), 0)
holds = lzc.lzc_get_holds(snap3) holds = lzc.lzc_get_holds(snap3)
self.assertEquals(len(holds), 1) self.assertEqual(len(holds), 1)
ret = lzc.lzc_release({snap3: ['tag1']}) ret = lzc.lzc_release({snap3: ['tag1']})
self.assertEquals(len(ret), 0) self.assertEqual(len(ret), 0)
holds = lzc.lzc_get_holds(snap3) holds = lzc.lzc_get_holds(snap3)
self.assertEquals(len(holds), 0) self.assertEqual(len(holds), 0)
def test_release_hold_before_auto_cleanup(self): def test_release_hold_before_auto_cleanup(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
@ -3261,7 +3262,7 @@ class ZFSTest(unittest.TestCase):
with cleanup_fd() as fd: with cleanup_fd() as fd:
lzc.lzc_hold({snap: 'tag'}, fd) lzc.lzc_hold({snap: 'tag'}, fd)
ret = lzc.lzc_release({snap: ['tag']}) ret = lzc.lzc_release({snap: ['tag']})
self.assertEquals(len(ret), 0) self.assertEqual(len(ret), 0)
def test_release_hold_and_snap_destruction(self): def test_release_hold_and_snap_destruction(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
@ -3301,22 +3302,22 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_snapshot([snap]) lzc.lzc_snapshot([snap])
ret = lzc.lzc_release({snap: ['tag']}) ret = lzc.lzc_release({snap: ['tag']})
self.assertEquals(len(ret), 1) self.assertEqual(len(ret), 1)
self.assertEquals(ret[0], snap + '#tag') self.assertEqual(ret[0], snap + '#tag')
def test_release_hold_missing_snap(self): def test_release_hold_missing_snap(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
ret = lzc.lzc_release({snap: ['tag']}) ret = lzc.lzc_release({snap: ['tag']})
self.assertEquals(len(ret), 1) self.assertEqual(len(ret), 1)
self.assertEquals(ret[0], snap) self.assertEqual(ret[0], snap)
def test_release_hold_missing_snap_2(self): def test_release_hold_missing_snap_2(self):
snap = ZFSTest.pool.getRoot().getSnap() snap = ZFSTest.pool.getRoot().getSnap()
ret = lzc.lzc_release({snap: ['tag', 'another']}) ret = lzc.lzc_release({snap: ['tag', 'another']})
self.assertEquals(len(ret), 1) self.assertEqual(len(ret), 1)
self.assertEquals(ret[0], snap) self.assertEqual(ret[0], snap)
def test_release_hold_across_pools(self): def test_release_hold_across_pools(self):
snap1 = ZFSTest.pool.getRoot().getSnap() snap1 = ZFSTest.pool.getRoot().getSnap()
@ -3358,7 +3359,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_release({snap: ['tag']}) lzc.lzc_release({snap: ['tag']})
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameTooLong) self.assertIsInstance(e, lzc_exc.NameTooLong)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_release_hold_invalid_snap_name(self): def test_release_hold_invalid_snap_name(self):
snap = ZFSTest.pool.getRoot().getSnap() + '@bad' snap = ZFSTest.pool.getRoot().getSnap() + '@bad'
@ -3366,7 +3367,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_release({snap: ['tag']}) lzc.lzc_release({snap: ['tag']})
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_release_hold_invalid_snap_name_2(self): def test_release_hold_invalid_snap_name_2(self):
snap = ZFSTest.pool.getRoot().getFilesystem().getName() snap = ZFSTest.pool.getRoot().getFilesystem().getName()
@ -3374,7 +3375,7 @@ class ZFSTest(unittest.TestCase):
lzc.lzc_release({snap: ['tag']}) lzc.lzc_release({snap: ['tag']})
for e in ctx.exception.errors: for e in ctx.exception.errors:
self.assertIsInstance(e, lzc_exc.NameInvalid) self.assertIsInstance(e, lzc_exc.NameInvalid)
self.assertEquals(e.name, snap) self.assertEqual(e.name, snap)
def test_sync_missing_pool(self): def test_sync_missing_pool(self):
pool = "nonexistent" pool = "nonexistent"
@ -4062,7 +4063,7 @@ class _TempPool(object):
if 'permission denied' in e.output: if 'permission denied' in e.output:
raise unittest.SkipTest( raise unittest.SkipTest(
'insufficient privileges to run libzfs_core tests') 'insufficient privileges to run libzfs_core tests')
print 'command failed: ', e.output print('command failed: ', e.output)
raise raise
except Exception: except Exception:
self.cleanUp() self.cleanUp()
@ -4108,7 +4109,7 @@ class _TempPool(object):
time.sleep(1) time.sleep(1)
continue continue
else: else:
print 'command failed: ', e.output print('command failed: ', e.output)
raise raise
for fs in self._filesystems: for fs in self._filesystems:
lzc.lzc_create(self.makeName(fs)) lzc.lzc_create(self.makeName(fs))

View File

@ -21,6 +21,7 @@ and verify that no information is lost and value types are correct.
The tests also check that various error conditions like unsupported The tests also check that various error conditions like unsupported
value types or out of bounds values are detected. value types or out of bounds values are detected.
""" """
from __future__ import absolute_import, division, print_function
import unittest import unittest

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
from __future__ import absolute_import, division, print_function
from setuptools import setup, find_packages from setuptools import setup, find_packages