Skip to content

Commit 93ab723

Browse files
KKoukioumartinpitt
authored andcommitted
machines: Fix default volume format detection in Disk Add dialog
Previously we were correctly calling the getDefaultVolumeFormat when opening the dialog, thus the default format for the preselected pool was correctly detected. However, when a user changed so some other pool, we didn't re-detect the default format, which was problematic if the user didn't change the preseleted format afterwards. This commit also adjusts the relevant test which didn't fail before because the problematic pool was first on the list so the getDefaultVolumeFormat was correctly called in the dialog constructor. Relevant to https://bugzilla.redhat.com/show_bug.cgi?id=1833198 Closes #14201 Cherry-picked from master commit 2cd9bf.
1 parent 0eb98c4 commit 93ab723

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/machines/components/diskAdd.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,19 @@ class AddDiskModalBody extends React.Component {
428428

429429
onValueChanged(key, value) {
430430
let stateDelta = {};
431+
const { storagePools, vm } = this.props;
431432

432433
switch (key) {
433434
case 'storagePoolName': {
435+
const currentPool = storagePools.find(pool => pool.name === value && pool.connectionName === vm.connectionName);
436+
const prevPool = storagePools.find(pool => pool.name === this.state.storagePoolName && pool.connectionName === vm.connectionName);
437+
434438
this.setState({ storagePoolName: value });
439+
// Reset the format only when the Format selection dropdown changes entries - otherwise just keep the old selection
440+
// All pool types apart from 'disk' have either 'raw' or 'qcow2' format
441+
if ((currentPool.type == 'disk' && prevPool.type != 'disk') || (currentPool.type != 'disk' && prevPool.type == 'disk'))
442+
this.onValueChanged('format', this.getDefaultVolumeFormat(value));
443+
435444
if (this.state.mode === USE_EXISTING) { // user changed pool
436445
this.onValueChanged('existingVolumeName', this.getDefaultVolumeName(value));
437446
}
@@ -440,7 +449,6 @@ class AddDiskModalBody extends React.Component {
440449
case 'existingVolumeName': {
441450
stateDelta.existingVolumeName = value;
442451
this.setState(prevState => { // to prevent asynchronous for recursive call with existingVolumeName as a key
443-
const { storagePools, vm } = this.props;
444452
const pool = storagePools.find(pool => pool.name === prevState.storagePoolName && pool.connectionName === vm.connectionName);
445453
stateDelta.diskFileFormat = this.getDefaultVolumeFormat(pool);
446454
if (['dir', 'fs', 'netfs', 'gluster', 'vstorage'].indexOf(pool.type) > -1) {

test/verify/machineslib.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,11 @@ def verify_disk_added(self):
664664
# Guess by the name of the pool it's format to avoid passing more parameters
665665
if self.pool_type == 'iscsi':
666666
expected_format = 'unknown'
667+
elif self.pool_type == 'disk':
668+
expected_format = 'none'
667669
else:
668670
expected_format = 'qcow2'
671+
669672
self.test_obj.assertEqual(
670673
m.execute(detect_format_cmd).rstrip(),
671674
'<format type="{0}"/>'.format(self.volume_format or expected_format)
@@ -843,23 +846,22 @@ def verify_disk_added(self):
843846

844847
prepareDisk(self.machine)
845848
cmds = [
846-
"virsh pool-define-as disk-pool disk - - /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1 - /tmp/poolDiskImages",
847-
"virsh pool-build disk-pool --overwrite",
848-
"virsh pool-start disk-pool",
849+
"virsh pool-define-as pool-disk disk - - /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1 - /tmp/poolDiskImages",
850+
"virsh pool-build pool-disk --overwrite",
851+
"virsh pool-start pool-disk",
849852
]
850853
self.machine.execute(" && ".join(cmds))
851854

852855
partition = str(self.machine.execute("readlink -f /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1 | cut -d '/' -f 3").strip()) + "1"
853856

854857
VMAddDiskDialog(
855858
self,
856-
pool_name='disk-pool',
859+
pool_name='pool-disk',
857860
pool_type='disk',
858861
volume_name=partition,
859862
volume_size=10,
860863
volume_size_unit='MiB',
861864
expected_target='vdc',
862-
volume_format='none',
863865
).execute()
864866

865867
def testNetworks(self):

0 commit comments

Comments
 (0)