-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for ignoring vdis when snapshoting a VM
See: xapi-project/xen-api#4563 Signed-off-by: BenjiReis <[email protected]>
- Loading branch information
1 parent
c342349
commit 1db6c19
Showing
4 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
import pytest | ||
|
||
@pytest.fixture(scope='module') | ||
def vdis(host, local_sr_on_hostA1): | ||
sr = local_sr_on_hostA1 | ||
|
||
logging.info('> Creating VDIs') | ||
vdi_A = host.xe('vdi-create', {'name-label': 'VDI_A', 'virtual-size': '64', 'sr-uuid': sr.uuid}) | ||
vdi_B = host.xe('vdi-create', {'name-label': 'VDI_B', 'virtual-size': '64', 'sr-uuid': sr.uuid}) | ||
vdi_C = host.xe('vdi-create', {'name-label': 'VDI_C', 'virtual-size': '64', 'sr-uuid': sr.uuid}) | ||
|
||
yield vdi_A, vdi_B, vdi_C | ||
|
||
logging.info('< Destroying VDIs') | ||
for vdi in [vdi_A, vdi_B, vdi_C]: | ||
host.xe('vdi-destroy', {'uuid': vdi}) | ||
|
||
@pytest.fixture(scope='module') | ||
def vm_with_vbds(host, vdis, imported_vm): | ||
vm = imported_vm | ||
vdi_A, vdi_B, vdi_C = vdis | ||
|
||
host.xe('vbd-create', { | ||
'vm-uuid': vm.uuid, 'mode': 'RW', 'type': 'Disk', 'device': 'xvda1', 'vdi-uuid': vdi_A | ||
}) | ||
host.xe('vbd-create', { | ||
'vm-uuid': vm.uuid, 'mode': 'RW', 'type': 'Disk', 'device': 'xvdb1', 'vdi-uuid': vdi_B | ||
}) | ||
host.xe('vbd-create', { | ||
'vm-uuid': vm.uuid, 'mode': 'RW', 'type': 'Disk', 'device': 'xvdc', 'vdi-uuid': vdi_C | ||
}) | ||
|
||
vm.start() | ||
yield vm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import logging | ||
|
||
# Requirements: | ||
# - an XCP-ng host (--hosts) > 8.2 | ||
# - a VM (--vm) | ||
|
||
def test_snapshot(host, vdis, vm_with_vbds): | ||
vm = vm_with_vbds | ||
|
||
snapshot = vm.snapshot() | ||
|
||
snap_vbds = snapshot.param_get('VBDs') | ||
snap_vbds = snap_vbds.split('; ') | ||
|
||
snap_vdis = list(map( | ||
lambda vbd: host.xe('vbd-param-get', {'uuid': vbd, 'param-name': 'vdi-uuid'}), | ||
snap_vbds | ||
)) | ||
snap_vdis = [vdi for vdi in snap_vdis if vdi != '<not in database>'] | ||
|
||
orig_vdis = list(map( | ||
lambda vdi: host.xe('vdi-param-get', {'uuid': vdi, 'param-name': 'snapshot-of'}), | ||
snap_vdis | ||
)) | ||
|
||
for vdi in vdis: | ||
assert vdi in orig_vdis | ||
|
||
snapshot.destroy() | ||
|
||
def test_snapshot_ignore_vdi(host, vdis, vm_with_vbds): | ||
vdi_A, vdi_B, vdi_C = vdis | ||
vm = vm_with_vbds | ||
|
||
snapshot = vm.snapshot(ignore_vdis=[vdi_B]) | ||
|
||
snap_vbds = snapshot.param_get('VBDs') | ||
snap_vbds = snap_vbds.split('; ') | ||
|
||
snap_vdis = list(map( | ||
lambda vbd: host.xe('vbd-param-get', {'uuid': vbd, 'param-name': 'vdi-uuid'}), | ||
snap_vbds | ||
)) | ||
snap_vdis = [vdi for vdi in snap_vdis if vdi != '<not in database>'] | ||
|
||
orig_vdis = list(map( | ||
lambda vdi: host.xe('vdi-param-get', {'uuid': vdi, 'param-name': 'snapshot-of'}), | ||
snap_vdis | ||
)) | ||
|
||
assert vdi_A in orig_vdis | ||
assert vdi_B not in orig_vdis | ||
assert vdi_C in orig_vdis | ||
|
||
snapshot.destroy() | ||
|
||
def test_snapshot_ignore_multiple_vdis(host, vdis, vm_with_vbds): | ||
vdi_A, vdi_B, vdi_C = vdis | ||
vm = vm_with_vbds | ||
|
||
snapshot = vm.snapshot(ignore_vdis=[vdi_B, vdi_C]) | ||
|
||
snap_vbds = snapshot.param_get('VBDs') | ||
snap_vbds = snap_vbds.split('; ') | ||
|
||
snap_vdis = list(map( | ||
lambda vbd: host.xe('vbd-param-get', {'uuid': vbd, 'param-name': 'vdi-uuid'}), | ||
snap_vbds | ||
)) | ||
snap_vdis = [vdi for vdi in snap_vdis if vdi != '<not in database>'] | ||
|
||
orig_vdis = list(map( | ||
lambda vdi: host.xe('vdi-param-get', {'uuid': vdi, 'param-name': 'snapshot-of'}), | ||
snap_vdis | ||
)) | ||
|
||
assert vdi_A in orig_vdis | ||
assert vdi_B not in orig_vdis | ||
assert vdi_C not in orig_vdis | ||
|
||
snapshot.destroy() |