493 lines
13 KiB
Python
Raw Permalink Normal View History

# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later
import pytest
from ovirt_imageio._internal import nbd
from ovirt_imageio._internal import nbdutil
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
from ovirt_imageio._internal.nbd import (
STATE_HOLE,
STATE_ZERO,
EXTENT_DIRTY,
EXTENT_BACKING,
)
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
MiB = 1024**2
GiB = 1024**3
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def extents_length(extents):
return sum(e.length for e in extents)
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
class FakeClient:
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def __init__(self, alloc, depth=None, dirty=None, max_extents=None):
"""
alloc, depth, and dirty are list of extents of same length. The export
size is set to the length of the extents.
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
max_extents is maximum number of extents return in one extents() call
per meta contenxt.
"""
# Check extents total length matches.
alloc_length = extents_length(alloc)
if depth:
assert extents_length(depth) == alloc_length
if dirty:
assert extents_length(dirty) == alloc_length
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
self.export_size = alloc_length
self.alloc = alloc
self.depth = depth
self.dirty = dirty
self.max_extents = max_extents
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
if self.dirty:
self.dirty_bitmap = nbd.QEMU_DIRTY_BITMAP + "name"
else:
self.dirty_bitmap = None
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def extents(self, offset, length):
"""
Simulate real NBD server extents reply.
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
Return extents overlapping the requested range. The first and last
extents may be clipped to the requested range.
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
If max_extents is set, may return short reply not coverting the entire
requested range. In this case the length of differnet meta context may
be different.
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
If export_size is shorter than the configured extents, the last extent
may exceed the export size.
"""
assert length > 0
assert length <= nbd.MAX_LENGTH
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
res = {
nbd.BASE_ALLOCATION: list(
self.lookup(offset, length, self.alloc))
}
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
if self.depth:
res[nbd.QEMU_ALLOCATION_DEPTH] = list(
self.lookup(offset, length, self.depth))
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
if self.dirty:
res[self.dirty_bitmap] = list(
self.lookup(offset, length, self.dirty))
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
return res
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def lookup(self, offset, length, extents):
end = offset + length
start = 0
count = 0
for e in extents:
# Skip before the requested range:
# request: [ ]
# extent: |----|
if start + e.length <= offset:
start += e.length
continue
length = e.length
# Clip extent before offset:
# request: [ ]
# extent: |-------|
# result: |===|
if start < offset:
clip = offset - start
length -= clip
start += clip
# Clip extent after end:
# request: [ ]
# extent: |-------|
# result: |====|
if start + length > end:
clip = start + length - end
length -= clip
yield nbd.Extent(length, e.flags)
# NBD server is allowed to return short reply with one or more
# extents.
count += 1
if self.max_extents and count == self.max_extents:
break
start += length
# Stop lookup after the requested range:
# request: [ ]
# extent: |----|
if start >= end:
break
def fake_client(n, max_extents=0):
"""
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
A client simulating few interesting cases:
- 3 alloction types: data, zero cluster, and unallocated extent.
- dirty extents convering both data and zero cluster.
- extents of different meta context of different length.
- server returning short reply.
"""
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
return FakeClient(
alloc=[
nbd.Extent(2 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
],
depth=[
nbd.Extent(3 * n, 0), # depth=1
nbd.Extent(1 * n, 0), # depth=2
nbd.Extent(2 * n, EXTENT_BACKING), # depth=0
],
dirty=[
nbd.Extent(1 * n, 0),
nbd.Extent(3 * n, EXTENT_DIRTY),
nbd.Extent(2 * n, 0)
],
max_extents=max_extents,
)
# Testing FakeClient
def test_fake_client_simple():
n = MiB
c = fake_client(n)
res = c.extents(0, 6 * n)
assert res == {
nbd.BASE_ALLOCATION: c.alloc,
nbd.QEMU_ALLOCATION_DEPTH: c.depth,
c.dirty_bitmap: c.dirty,
}
def test_fake_client_clip_start():
n = MiB
c = fake_client(n)
res = c.extents(n, 5 * n)
assert res == {
nbd.BASE_ALLOCATION: [
nbd.Extent(1 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
],
nbd.QEMU_ALLOCATION_DEPTH: [
nbd.Extent(2 * n, 0), # depth=1
nbd.Extent(1 * n, 0), # depth=2
nbd.Extent(2 * n, EXTENT_BACKING), # depth=0
],
c.dirty_bitmap: [
nbd.Extent(3 * n, EXTENT_DIRTY),
nbd.Extent(2 * n, 0)
],
}
def test_fake_client_clip_end():
n = MiB
c = fake_client(n)
res = c.extents(0, 5 * n)
assert res == {
nbd.BASE_ALLOCATION: [
nbd.Extent(2 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE),
],
nbd.QEMU_ALLOCATION_DEPTH: [
nbd.Extent(3 * n, 0), # depth=1
nbd.Extent(1 * n, 0), # depth=2
nbd.Extent(1 * n, EXTENT_BACKING), # depth=0
],
c.dirty_bitmap: [
nbd.Extent(1 * n, 0),
nbd.Extent(3 * n, EXTENT_DIRTY),
nbd.Extent(1 * n, 0)
],
}
def test_fake_client_clip_both():
n = MiB
c = fake_client(n)
res = c.extents(2 * n, 2 * n)
assert res == {
nbd.BASE_ALLOCATION: [
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
],
nbd.QEMU_ALLOCATION_DEPTH: [
nbd.Extent(1 * n, 0), # depth=1
nbd.Extent(1 * n, 0), # depth=2
],
c.dirty_bitmap: [
nbd.Extent(2 * n, EXTENT_DIRTY),
],
}
def test_fake_client_max_extents():
n = MiB
c = fake_client(n, max_extents=1)
res = c.extents(0, 6 * n)
assert res == {
nbd.BASE_ALLOCATION: [
nbd.Extent(2 * n, 0),
],
nbd.QEMU_ALLOCATION_DEPTH: [
nbd.Extent(3 * n, 0), # depth=1
],
c.dirty_bitmap: [
nbd.Extent(1 * n, 0),
],
}
c = fake_client(n, max_extents=2)
res = c.extents(n, 4 * n)
assert res == {
nbd.BASE_ALLOCATION: [
nbd.Extent(1 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
],
nbd.QEMU_ALLOCATION_DEPTH: [
nbd.Extent(2 * n, 0), # depth=1
nbd.Extent(1 * n, 0), # depth=2
],
c.dirty_bitmap: [
nbd.Extent(3 * n, EXTENT_DIRTY),
nbd.Extent(1 * n, 0)
],
}
# Testing nbdutil.extents()
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_all(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c))
assert extents == [
nbd.Extent(2 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE | EXTENT_BACKING),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_all_dirty(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, dirty=True))
assert extents == [
nbd.Extent(1 * n, 0),
nbd.Extent(1 * n, EXTENT_DIRTY),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE | EXTENT_DIRTY),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_all_no_depth(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
# Simulate the case when server does not report allocation depth.
c.depth = None
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
extents = list(nbdutil.extents(c))
assert extents == [
nbd.Extent(2 * n, 0),
nbd.Extent(4 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_offset(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, offset=3 * n))
assert extents == [
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE | EXTENT_BACKING),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_offset_dirty(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, offset=3 * n, dirty=True))
assert extents == [
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE | EXTENT_DIRTY),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_length(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, length=3 * n))
assert extents == [
nbd.Extent(2 * n, 0),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_length_dirty(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, length=3 * n, dirty=True))
assert extents == [
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
nbd.Extent(1 * n, 0),
nbd.Extent(1 * n, EXTENT_DIRTY),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE | EXTENT_DIRTY),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_offset_length(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, offset=n, length=4 * n))
assert extents == [
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
nbd.Extent(1 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE | EXTENT_BACKING),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
@pytest.mark.parametrize("max_extents", [None, 1, 2])
def test_extents_offset_length_dirty(max_extents):
n = GiB
c = fake_client(n, max_extents=max_extents)
extents = list(nbdutil.extents(c, offset=n, length=4 * n, dirty=True))
assert extents == [
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
nbd.Extent(1 * n, EXTENT_DIRTY),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE | EXTENT_DIRTY),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def test_extents_last_extent_excceeds_export_size():
n = GiB
c = fake_client(n)
# Clip export size so we get extra extent info exceeding the request
# length.
c.export_size -= GiB
# Merge base:allocation and qemu:allocation-depth.
extents = list(nbdutil.extents(c))
assert extents == [
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
nbd.Extent(2 * n, 0),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE | EXTENT_BACKING),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
def test_extents_last_extent_excceeds_export_size_dirty():
n = GiB
c = fake_client(n)
# Clip export size so we get extra extent info exceeding the request
# length.
c.export_size -= GiB
extents = list(nbdutil.extents(c, dirty=True))
assert extents == [
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
nbd.Extent(1 * n, 0),
nbd.Extent(1 * n, EXTENT_DIRTY),
nbd.Extent(2 * n, STATE_ZERO | STATE_HOLE | EXTENT_DIRTY),
nbd.Extent(1 * n, STATE_ZERO | STATE_HOLE),
]
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
# Testing nbdutil.merged()
def test_merge_simple():
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
n = GiB
a = [nbd.Extent(n, 0)]
b = [nbd.Extent(n, 0)]
merged = list(nbdutil.merged(a, b))
assert merged == a
def test_merge_split_one():
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
n = GiB
a = [
nbd.Extent(n, 1),
nbd.Extent(n, 2),
nbd.Extent(n, 4),
]
b = [
nbd.Extent(n * 3, 8)
]
merged1 = list(nbdutil.merged(a, b))
assert merged1 == [
nbd.Extent(n, 1 | 8),
nbd.Extent(n, 2 | 8),
nbd.Extent(n, 4 | 8),
]
merged2 = list(nbdutil.merged(b, a))
assert merged2 == merged1
def test_merge_split_both():
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
n = GiB
a = [
nbd.Extent(n * 1, 1),
nbd.Extent(n * 2, 2),
]
b = [
nbd.Extent(n * 2, 4),
nbd.Extent(n * 1, 8),
]
merged1 = list(nbdutil.merged(a, b))
assert merged1 == [
nbd.Extent(n, 1 | 4),
nbd.Extent(n, 2 | 4),
nbd.Extent(n, 2 | 8),
]
merged2 = list(nbdutil.merged(b, a))
assert merged2 == merged1
def test_merge_clip():
tests: Rewrite nbdutil extents tests The previous tests were complicated and rigid, and I cold not find any way to test allocation depth and dirty bitmaps. This change introduce a much simpler client that can be configured with extents lists for base:allocation, qemu:allocation-depth, and qemu:dirty-bitmap:name. Unfortunately, to return extent reply from the configured extents, the client need to be pretty smart. It have to search in the extent list and return the extents overlapping the requested range. This includes also clipping extents starting before the requested range, or extents ending after the requested range. Additionally, the client can be configured to return short reply. I'm not sure qemu NBD server returns short replies, but the NBD protocol allows it, so we must be prepared to handle this. Since the client code is pretty tricky, we have new tests verifying that that the client behaves correctly. These tests also demonstrate why merging extents from different meta contexts is tricky. All the client and extents tests use the same client, configured to test several interesting uses cases that were not tested before. This client is tested with all the combinations tested before - getting all extents, getting extents at the start, middle and end of the image, and getting zero and dirty extents. Change-Id: Ibc7c9a59a3f64b6727075a453b55eee74b81a8e6 Bug-Url: https://bugzilla.redhat.com/1971185 Bug-Url: https://bugzilla.redhat.com/1971182 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2021-06-17 01:45:57 +03:00
n = GiB
a = [
nbd.Extent(n * 1, 1),
nbd.Extent(n * 1, 2),
]
b = [
nbd.Extent(n * 1, 4),
nbd.Extent(n * 2, 8),
]
merged1 = list(nbdutil.merged(a, b))
assert merged1 == [
nbd.Extent(n * 1, 1 | 4),
nbd.Extent(n * 1, 2 | 8),
]
merged2 = list(nbdutil.merged(b, a))
assert merged2 == merged1