Skip to content

Commit be49d0d

Browse files
bgreenbbsanders
authored andcommitted
BUGFIX: Fix set vm storage name changing all disk names with the same backing regardless of host
1 parent eeeda22 commit be49d0d

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

common/src/stack/command/stack/commands/set/vm/storage/name/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ def run(self, params, args):
5858
"""
5959
UPDATE virtual_machine_disks
6060
SET disk_name=%s
61-
WHERE virtual_machine_disks.image_file_name = %s
62-
OR virtual_machine_disks.mount_disk = %s
63-
AND virtual_machine_disks.virtual_machine_id = %s
61+
WHERE (
62+
virtual_machine_disks.image_file_name = %s
63+
OR virtual_machine_disks.mount_disk = %s
64+
) AND virtual_machine_disks.virtual_machine_id = %s
6465
""",
6566
(disk_name, backing, backing, vm_id)
6667
)
68+

test-framework/test-suites/integration/tests/set/test_set_vm_storage_disk_name.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,49 @@ def test_disk_swap(self, add_hypervisor, add_vm_multiple, host):
157157
'Pending Deletion': False
158158
}
159159
]
160+
161+
def test_disk_same_image(self, add_hypervisor, add_vm_multiple, create_image_files, host):
162+
"""
163+
Test when a disk image is used for multiple hosts, only the
164+
given host's disk name is changed
165+
"""
166+
167+
temp_dir = TemporaryDirectory()
168+
disks = create_image_files(temp_dir)
169+
170+
# Add image1.raw to vmbackend-0-3 and vm-backend-0-4
171+
add_storage = host.run(f'stack add vm storage vm-backend-0-3 disks={disks["image1.raw"]} storage_pool=/export/pools/stacki')
172+
assert add_storage.rc == 0
173+
174+
add_storage = host.run(f'stack add vm storage vm-backend-0-4 disks={disks["image1.raw"]} storage_pool=/export/pools/stacki')
175+
assert add_storage.rc == 0
176+
177+
# Set only vm-backend-0-4's disk name to vdc
178+
result = host.run(f'stack set vm storage name vm-backend-0-4 backing={disks["image1.raw"]} name=vdc')
179+
assert result.rc == 0
180+
181+
# Check vm-backend-0-3 doesn't have the disk name change
182+
result = host.run('stack list vm storage vm-backend-0-3 output-format=json')
183+
assert result.rc == 0
184+
assert json.loads(result.stdout) == [
185+
{
186+
'Virtual Machine': 'vm-backend-0-3',
187+
'Name': 'sda',
188+
'Type': 'disk',
189+
'Location': '/export/pools/stacki/vm-backend-0-3',
190+
'Size': 100,
191+
'Image Name': 'vm-backend-0-3_disk1.qcow2',
192+
'Mountpoint': None,
193+
'Pending Deletion': False
194+
},
195+
{
196+
'Virtual Machine': 'vm-backend-0-3',
197+
'Name': 'sdb',
198+
'Type': 'image',
199+
'Location': '/export/pools/stacki/vm-backend-0-3',
200+
'Size': None,
201+
'Image Name': f'{disks["image1.raw"]}',
202+
'Mountpoint': None,
203+
'Pending Deletion': False
204+
}
205+
]

0 commit comments

Comments
 (0)