'``StoragePool.change_owner()`` doesn\'t delete the contents of the
original mountpoint, if it is non-empty.
ZFS doesn\'t like to mount volumes over non-empty directories. To test
this, we change the original mount to be a legacy mount (mounted using
manpage:`mount(8)`).'

def test_change_owner_does_not_remove_non_empty_mountpoint(self):

    pool = StoragePool(reactor, create_zfs_pool(self), FilePath(self.mktemp()))
    service = service_for_pool(self, pool)
    volume = service.get(MY_VOLUME)
    new_volume = Volume(node_id=u'other-uuid', name=MY_VOLUME2, service=service)
    original_mount = volume.get_filesystem().get_path()
    d = pool.create(volume)
    def created_filesystems(ignored):
        filesystem_name = volume.get_filesystem().name
        subprocess.check_call(['zfs', 'unmount', filesystem_name])
        original_mount.child('file').setContent('content')
        subprocess.check_call(['zfs', 'set', 'mountpoint=legacy', filesystem_name])
        subprocess.check_call(['mount', '-t', 'zfs', filesystem_name, original_mount.path])
        return pool.change_owner(volume, new_volume)
    d.addCallback(created_filesystems)
    self.assertFailure(d, OSError)
    def changed_owner(filesystem):
        self.assertEqual(original_mount.child('file').getContent(), 'content')
    d.addCallback(changed_owner)
    return d
