Skip to content

Commit 28ac8ef

Browse files
authored
Merge pull request #91 from stackhpc/upstream/2023.1-2024-08-05
Synchronise 2023.1 with upstream
2 parents 50dcd60 + 99a8cf4 commit 28ac8ef

File tree

14 files changed

+187
-31
lines changed

14 files changed

+187
-31
lines changed

nova/api/openstack/compute/aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def images(self, req, id, body):
289289
for image_req in body.get('cache'):
290290
image_ids.append(image_req['id'])
291291

292-
if image_ids != list(set(image_ids)):
292+
if sorted(image_ids) != sorted(list(set(image_ids))):
293293
raise exc.HTTPBadRequest(
294294
explanation=_('Duplicate images in request'))
295295

nova/network/neutron.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,12 +1595,13 @@ def _get_vf_pci_device_profile(self, pci_dev):
15951595
pf_mac = pci_dev.sriov_cap.get('pf_mac_address')
15961596
vf_num = pci_dev.sriov_cap.get('vf_num')
15971597
card_serial_number = pci_dev.card_serial_number
1598-
if all((pf_mac, vf_num, card_serial_number)):
1599-
vf_profile.update({
1600-
'card_serial_number': card_serial_number,
1601-
'pf_mac_address': pf_mac,
1602-
'vf_num': vf_num,
1603-
})
1598+
1599+
if card_serial_number is not None:
1600+
vf_profile['card_serial_number'] = card_serial_number
1601+
if pf_mac is not None:
1602+
vf_profile['pf_mac_address'] = pf_mac
1603+
if vf_num is not None:
1604+
vf_profile['vf_num'] = vf_num
16041605

16051606
# Update port binding capabilities using PCI device's network
16061607
# capabilities if they exist.

nova/tests/functional/libvirt/test_pci_sriov_servers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ def fake_create(cls, xml, host):
521521
'pci_vendor_info': '8086:1515',
522522
'pci_slot': '0000:81:00.2',
523523
'physical_network': 'physnet4',
524+
'pf_mac_address': '52:54:00:1e:59:c6',
525+
'vf_num': 1
524526
},
525527
port['binding:profile'],
526528
)
@@ -1017,6 +1019,8 @@ def test_live_migrate_server_with_neutron(self):
10171019
# matching one)
10181020
'pci_slot': '0000:81:00.4',
10191021
'physical_network': 'physnet4',
1022+
'pf_mac_address': '52:54:00:1e:59:c6',
1023+
'vf_num': 1
10201024
},
10211025
port['binding:profile'],
10221026
)
@@ -1062,6 +1066,8 @@ def test_live_migrate_server_with_neutron(self):
10621066
'pci_vendor_info': '8086:1515',
10631067
'pci_slot': '0000:81:00.2',
10641068
'physical_network': 'physnet4',
1069+
'pf_mac_address': '52:54:00:1e:59:c6',
1070+
'vf_num': 1,
10651071
},
10661072
port['binding:profile'],
10671073
)

nova/tests/unit/api/openstack/compute/test_aggregates.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,28 @@ def test_images_with_invalid_id(self):
738738
version='2.81')
739739
self.assertRaises(exc.HTTPBadRequest, self.controller.images,
740740
req, 'foo', body=body)
741+
742+
def test_images_with_duplicate_id(self):
743+
body = {"cache": [{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"},
744+
{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"}]}
745+
req = fakes.HTTPRequest.blank('/v2/os-aggregates',
746+
use_admin_context=True,
747+
version='2.81')
748+
self.assertRaises(exc.HTTPBadRequest, self.controller.images,
749+
req, '1', body=body)
750+
751+
def test_images_with_disorder_id(self):
752+
body = {"cache": [{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"},
753+
{"id": "290de658-cf55-4cce-b025-9a1a9f93676a"},
754+
{"id": "896f7f54-4e4e-4c21-a2b7-47cff4e99ab0"},
755+
{"id": "d982bb82-04a0-4e9b-b40e-470f20a7b5d1"}]}
756+
req = fakes.HTTPRequest.blank('/v2/os-aggregates',
757+
use_admin_context=True,
758+
version='2.81')
759+
context = req.environ['nova.context']
760+
with mock.patch.object(self.controller.api,
761+
'get_aggregate') as mock_get:
762+
with mock.patch.object(self.controller.conductor_tasks,
763+
'cache_images'):
764+
self.controller.images(req, '1', body=body)
765+
mock_get.assert_called_once_with(context, '1')

nova/tests/unit/image/test_format_inspector.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,16 @@ def _create_allocated_vmdk(self, size_mb, subformat=None):
179179
shell=True)
180180

181181
# Convert it to VMDK
182-
subprocess.check_output(
183-
'qemu-img convert -f raw -O vmdk -o subformat=%s -S 0 %s %s' % (
184-
subformat, raw, fn),
185-
shell=True)
182+
# these tests depend on qemu-img
183+
# being installed and in the path,
184+
# if it is not installed, skip
185+
try:
186+
subprocess.check_output(
187+
'qemu-img convert -f raw -O vmdk -o subformat=%s -S 0 %s %s'
188+
% (subformat, raw, fn),
189+
shell=True)
190+
except Exception:
191+
self.skipTest("qemu-img not installed")
186192
return fn
187193

188194
def _test_format_at_block_size(self, format_name, img, block_size):

nova/tests/unit/network/test_neutron.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8627,6 +8627,73 @@ def test_unbind_ports_clean_arq(self, mock_neutron, mock_show,
86278627
self.assertEqual(call_args['port']['binding:profile'],
86288628
{'key': 'val'})
86298629

8630+
def test__get_vf_pci_device_profile_without_serial_num(self):
8631+
mydev = objects.PciDevice(
8632+
address='foo',
8633+
compute_node_id='123',
8634+
extra_info={
8635+
'capabilities': jsonutils.dumps({
8636+
'sriov': {
8637+
'pf_mac_address': '52:54:00:1e:59:c6',
8638+
'vf_num': 1,
8639+
},
8640+
'network': ['gso', 'sg', 'tso', 'tx'],
8641+
}),
8642+
},
8643+
)
8644+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8645+
{'pf_mac_address': '52:54:00:1e:59:c6',
8646+
'vf_num': 1,
8647+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8648+
8649+
def test__get_vf_pci_device_profile_without_pf_mac_addr(self):
8650+
mydev = objects.PciDevice(
8651+
address='foo',
8652+
compute_node_id='123',
8653+
extra_info={
8654+
'capabilities': jsonutils.dumps({
8655+
'vpd': {'card_serial_number': 'MT2113X00000'},
8656+
'sriov': {'vf_num': 1},
8657+
'network': ['gso', 'sg', 'tso', 'tx'],
8658+
}),
8659+
},
8660+
)
8661+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8662+
{'card_serial_number': 'MT2113X00000',
8663+
'vf_num': 1,
8664+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8665+
8666+
def test__get_vf_pci_device_profile_without_vf_num(self):
8667+
mydev = objects.PciDevice(
8668+
address='foo',
8669+
compute_node_id='123',
8670+
extra_info={
8671+
'capabilities': jsonutils.dumps({
8672+
'vpd': {'card_serial_number': 'MT2113X00000'},
8673+
'sriov': {'pf_mac_address': '52:54:00:1e:59:c6'},
8674+
'network': ['gso', 'sg', 'tso', 'tx'],
8675+
}),
8676+
},
8677+
)
8678+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8679+
{'card_serial_number': 'MT2113X00000',
8680+
'pf_mac_address': '52:54:00:1e:59:c6',
8681+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8682+
8683+
def test__get_vf_pci_device_profile_with_dev_capabilities(self):
8684+
mydev = objects.PciDevice(
8685+
address='foo',
8686+
compute_node_id='123',
8687+
extra_info={
8688+
'capabilities': jsonutils.dumps({
8689+
'sriov': {},
8690+
'network': ['gso', 'sg', 'tso', 'tx'],
8691+
}),
8692+
},
8693+
)
8694+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8695+
{'capabilities': ['gso', 'sg', 'tso', 'tx']})
8696+
86308697

86318698
class TestAllocateForInstance(test.NoDBTestCase):
86328699
def setUp(self):

nova/tests/unit/virt/libvirt/cpu/test_api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,21 @@ def test_validate_all_dedicated_cpus_no_cpu(self):
244244
self.api.validate_all_dedicated_cpus()
245245
# no assert we want to make sure the validation won't raise if
246246
# no dedicated cpus are configured
247+
248+
@mock.patch.object(core, 'get_governor')
249+
@mock.patch.object(core, 'get_online')
250+
def test_validate_all_dedicated_cpus_for_cpu_state_with_off_cores(
251+
self, mock_get_online, mock_get_governor):
252+
self.flags(cpu_power_management=True, group='libvirt')
253+
self.flags(cpu_dedicated_set='1-3', group='compute')
254+
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
255+
# CPU1 and CPU3 are online while CPU2 is offline
256+
mock_get_online.side_effect = (True, False, True)
257+
mock_get_governor.return_value = 'performance'
258+
self.api.validate_all_dedicated_cpus()
259+
260+
mock_get_online.assert_has_calls([mock.call(1), mock.call(2),
261+
mock.call(3)])
262+
# we only have two calls as CPU2 was skipped
263+
mock_get_governor.assert_has_calls([mock.call(1),
264+
mock.call(3)])

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9385,7 +9385,7 @@ def test_set_quiesced_agent_connection_fails(self):
93859385

93869386
def test_create_snapshot_metadata(self):
93879387
base = objects.ImageMeta.from_dict(
9388-
{'disk_format': 'raw'})
9388+
{'disk_format': 'qcow2'})
93899389
instance_data = {'kernel_id': 'kernel',
93909390
'project_id': 'prj_id',
93919391
'ramdisk_id': 'ram_id',
@@ -9417,10 +9417,12 @@ def test_create_snapshot_metadata(self):
94179417
{'disk_format': 'ami',
94189418
'container_format': 'test_container'})
94199419
expected['properties']['os_type'] = instance['os_type']
9420-
expected['disk_format'] = base.disk_format
9420+
# The disk_format of the snapshot should be the *actual* format of the
9421+
# thing we upload, regardless of what type of image we booted from.
9422+
expected['disk_format'] = img_fmt
94219423
expected['container_format'] = base.container_format
94229424
ret = drvr._create_snapshot_metadata(base, instance, img_fmt, snp_name)
9423-
self.assertEqual(ret, expected)
9425+
self.assertEqual(expected, ret)
94249426

94259427
def test_get_volume_driver(self):
94269428
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
@@ -29000,7 +29002,8 @@ def test_ami(self):
2900029002
utils.get_system_metadata_from_image(
2900129003
{'disk_format': 'ami'})
2900229004

29003-
self._test_snapshot(disk_format='ami')
29005+
# If we're uploading a qcow2, we must set the disk_format as such
29006+
self._test_snapshot(disk_format='qcow2')
2900429007

2900529008
@mock.patch('nova.virt.libvirt.utils.get_disk_type_from_path',
2900629009
new=mock.Mock(return_value=None))

nova/tests/unit/virt/libvirt/volume/test_mount.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,32 @@ def test_umount_log_failure(self, mock_log):
580580

581581
mock_log.assert_called()
582582

583+
@mock.patch.object(mount.LOG, 'exception')
584+
def test_mount_failure(self, mock_log_exc):
585+
m = self._get_clean_hostmountstate()
586+
err = processutils.ProcessExecutionError
587+
self.mock_mount.side_effect = err
588+
589+
# Mount vol_a
590+
self.assertRaises(err, self._sentinel_mount, m, mock.sentinel.vol_a)
591+
592+
# Verify the mountpoint got removed after the failure
593+
self.assertEqual({}, m.mountpoints)
594+
595+
# Now try a scenario where the mount failed because the volume was
596+
# already mounted
597+
self.mock_ismount.side_effect = [False, True]
598+
599+
# Mount vol_a
600+
self._sentinel_mount(m, mock.sentinel.vol_a)
601+
602+
# Verify the mountpoint is present despite the error
603+
self.assertEqual(1, len(m.mountpoints))
604+
self.assertIn(mock.sentinel.mountpoint, m.mountpoints)
605+
606+
# Verify we logged an exception
607+
mock_log_exc.assert_called()
608+
583609

584610
class MountManagerTestCase(test.NoDBTestCase):
585611
class FakeHostMountState(object):

nova/tests/unit/virt/test_virt_drivers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ def setUp(self):
838838
# since we don't care about it.
839839
self.stub_out('os_vif.unplug', lambda a, kw: None)
840840
self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
841+
self.stub_out('nova.virt.libvirt.utils.get_disk_size',
842+
lambda *a, **k: 123456)
843+
self.stub_out('nova.virt.libvirt.utils.get_disk_backing_file',
844+
lambda *a, **k: None)
845+
self.stub_out('nova.privsep.path.chown', lambda *a, **k: None)
841846

842847
def test_init_host_image_type_rbd_force_raw_images_true(self):
843848
CONF.set_override('images_type', 'rbd', group='libvirt')

0 commit comments

Comments
 (0)