def test_cpu_dedicated_set(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('cpu-shared-set', '4-15') self.test_config.set('cpu-dedicated-set', '16-31') libvirt = context.NovaComputeLibvirtContext() expected = {'libvirtd_opts': '-d', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512, 'cpu_shared_set': '4-15', 'cpu_dedicated_set': '16-31', 'force_raw_images': True, 'inject_password': False, 'inject_partition': -2, 'default_ephemeral_format': 'ext4'} self.assertEqual(expected, libvirt()) # should be ignored self.test_config.set('vcpu-pin-set', '16-31') libvirt = context.NovaComputeLibvirtContext() self.assertEqual(expected, libvirt())
def test_libvirt_cpu_mode_aarch64(self, mock_uuid, mock_platform): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} mock_uuid.return_value = 'e46e530d-18ae-4a67-9ff0-e6e2ba7c60a7' mock_platform.machine.return_value = 'aarch64' libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['cpu_mode'], 'host-passthrough')
def test_libvirt_context_libvirtd_reserved_huge_pages_2(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'yakkety'} self.os_release.return_value = 'ocata' self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set( 'reserved-huge-pages', 'node:0,size:2048,count:6;node:1,size:1G,count:32') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'force_raw_images': True, 'default_ephemeral_format': 'ext4', 'reserved_host_memory': 512, 'reserved_huge_pages': ['node:0,size:2048,count:6', 'node:1,size:1G,count:32'] }, libvirt())
def test_libvirt_bin_context_migration_tcp_listen_with_post_copy(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('enable-live-migration', True) self.test_config.set('live-migration-permit-post-copy', True) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '-d -l', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'live_migration_uri': 'qemu+ssh://%s/system', 'live_migration_completion_timeout': 800, 'live_migration_downtime': 500, 'live_migration_downtime_delay': 75, 'live_migration_downtime_steps': 10, 'live_migration_permit_auto_converge': False, 'live_migration_permit_post_copy': True, 'default_ephemeral_format': 'ext4', 'force_raw_images': True, 'reserved_host_memory': 512}, libvirt())
def test_libvirt_new_uuid(self, mock_uuid): self.kv.return_value = FakeUnitdata() self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} mock_uuid.return_value = '73874c1c-ba48-406d-8d99-ac185d83b9bc' libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['host_uuid'], '73874c1c-ba48-406d-8d99-ac185d83b9bc')
def test_libvirt_vnf_configs(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('hugepages', '22') self.test_config.set('reserved-host-memory', 1024) self.test_config.set('vcpu-pin-set', '^0^2') self.test_config.set('pci-passthrough-whitelist', 'mypcidevices') self.test_config.set('virtio-net-tx-queue-size', 512) self.test_config.set('virtio-net-rx-queue-size', 1024) self.test_config.set('cpu-shared-set', "4-12,^8,15") self.test_config.set('cpu-dedicated-set', "0-3,^10,33") libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '-d', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'hugepages': True, 'kvm_hugepages': 1, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 1024, 'vcpu_pin_set': None, 'force_raw_images': True, 'pci_passthrough_whitelist': 'mypcidevices', 'virtio_net_tx_queue_size': 512, 'virtio_net_rx_queue_size': 1024, 'default_ephemeral_format': 'ext4', 'cpu_shared_set': "4-12,^8,15", 'cpu_dedicated_set': "0-3,^10,33"}, libvirt())
def test_nova_compute_extra_flags(self): self.test_config.set('cpu-model-extra-flags', 'pcid vmx pdpe1gb') self.lsb_release.return_value = {'DISTRIB_CODENAME': 'bionic'} libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['cpu_model_extra_flags'], 'pcid, vmx, pdpe1gb')
def test_libvirt_cpu_mode_none(self, mock_uuid): self.test_config.set('cpu-mode', 'none') self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} mock_uuid.return_value = 'e46e530d-18ae-4a67-9ff0-e6e2ba7c60a7' libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['cpu_mode'], 'none')
def test_libvirt_context_without_migration_network(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} self.test_config.set('enable-live-migration', True) self.test_config.set('migration-auth-type', 'ssh') self.os_release.return_value = 'kilo' self.assertEquals(context.NovaComputeLibvirtContext()()[ 'live_migration_uri'], 'qemu+ssh://%s/system')
def test_ksm_configs(self): self.test_config.set('ksm', '1') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '1') self.test_config.set('ksm', '0') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '0') self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.test_config.set('ksm', '') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'ocata' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'kilo' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'cactus' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '1')
def test_ksm_configs(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('ksm', '1') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '1') self.test_config.set('ksm', '0') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '0') self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.test_config.set('ksm', '') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'ocata' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'kilo' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == 'AUTO') self.os_release.return_value = 'diablo' self.test_config.set('ksm', 'AUTO') libvirt = context.NovaComputeLibvirtContext() self.assertTrue(libvirt()['ksm'] == '1')
def test_libvirt_context_with_migration_network(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} self.test_config.set('enable-live-migration', True) self.test_config.set('migration-auth-type', 'ssh') self.test_config.set('libvirt-migration-network', '10.5.0.0/16') self.os_release.return_value = 'rocky' context.NovaComputeLibvirtContext()() self.get_relation_ip.assert_called_with('migration', cidr_network="10.5.0.0/16")
def test_libvirt_context_with_migration_space(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} self.test_config.set('enable-live-migration', True) self.os_release.return_value = 'ocata' self.get_relation_ip.return_value = "10.5.0.5" libvirt_context = context.NovaComputeLibvirtContext()() self.get_relation_ip.assert_called_with('migration', cidr_network=None) self.assertTrue('live_migration_uri' not in libvirt_context.keys()) self.assertEquals(libvirt_context['live_migration_scheme'], 'ssh') self.assertEquals(libvirt_context['live_migration_inbound_addr'], '10.5.0.5')
def test_libvirt_bin_context_migration_tcp_listen(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('enable-live-migration', True) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d -l', 'arch': platform.machine(), 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512 }, libvirt())
def test_libvirt_disk_cachemodes(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('disk-cachemodes', 'file=unsafe,block=none') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d', 'disk_cachemodes': 'file=unsafe,block=none', 'arch': platform.machine(), 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512 }, libvirt())
def test_libvirt_hugepages(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('hugepages', '22') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d', 'arch': platform.machine(), 'hugepages': True, 'kvm_hugepages': 1, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512 }, libvirt())
def test_libvirt_context_libvirtd(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'yakkety'} self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('enable-live-migration', False) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '', 'libvirt_user': '******', 'arch': platform.machine(), 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512 }, libvirt())
def test_nova_config_context_multi_pci_alias(self, mock_config, local_unit, mock_relation_ids, mock_unit_get): local_unit.return_value = 'nova-compute/0' self.os_release.return_value = 'queens' self.lsb_release.return_value = {'DISTRIB_CODENAME': 'bionic'} mock_config.side_effect = self.test_config.get mock_unit_get.return_value = '127.0.0.1' self.test_config.set('pci-alias', self._pci_alias1) ctxt = context.NovaComputeLibvirtContext()() self.assertEqual( ctxt['pci_alias'], ('{"capability_type": "pci", "device_type": "type-PF", ' '"name": "IntelNIC", "product_id": "1111", ' '"vendor_id": "8086"}'))
def test_libvirt_bin_context_no_migration(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('enable-live-migration', False) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '-d', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'force_raw_images': True, 'default_ephemeral_format': 'ext4', 'reserved_host_memory': 512}, libvirt())
def test_vcpu_pin_set(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('vcpu-pin-set', '^0^2') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '-d', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512, 'vcpu_pin_set': '^0^2', 'force_raw_images': True, 'default_ephemeral_format': 'ext4'}, libvirt())
def test_libvirt_context_libvirtd_force_raw_images(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'zesty'} self.os_release.return_value = 'ocata' self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('force-raw-images', False) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'force_raw_images': False, 'default_ephemeral_format': 'ext4', 'reserved_host_memory': 512}, libvirt())
def test_libvirt_disk_cachemodes(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('disk-cachemodes', 'file=unsafe,block=none') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( {'libvirtd_opts': '-d', 'libvirt_user': '******', 'disk_cachemodes': 'file=unsafe,block=none', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'force_raw_images': True, 'default_ephemeral_format': 'ext4', 'reserved_host_memory': 512}, libvirt())
def test_libvirt_bin_context_migration_tcp_listen(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('enable-live-migration', True) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d -l', 'libvirt_user': '******', 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'live_migration_uri': 'qemu+ssh://%s/system', 'reserved_host_memory': 512 }, libvirt())
def test_nova_config_context_multi_pci_alias_pike(self, mock_config, local_unit, mock_relation_ids, mock_unit_get): self.os_release.return_value = 'pike' local_unit.return_value = 'nova-compute/0' self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} mock_config.side_effect = self.test_config.get mock_unit_get.return_value = '127.0.0.1' self.test_config.set('pci-alias', self._pci_alias_list) ctxt = context.NovaComputeLibvirtContext()() self.assertEqual( ctxt['pci_alias'], ('[{"capability_type": "pci", "device_type": "type-PF", ' '"name": "IntelNIC", "product_id": "1111", ' '"vendor_id": "8086"}, ' '{"capability_type": "pci", "device_type": "type-PCI", ' '"name": " Cirrus Logic ", "product_id": "0ff2", ' '"vendor_id": "10de"}]'))
def test_libvirt_hugepages(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.os_release.return_value = 'kilo' self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('hugepages', '22') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d', 'libvirt_user': '******', 'arch': platform.machine(), 'hugepages': True, 'ksm': 'AUTO', 'kvm_hugepages': 1, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 512 }, libvirt())
def test_libvirt_vnf_configs(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.test_config.set('hugepages', '22') self.test_config.set('reserved-host-memory', 1024) self.test_config.set('vcpu-pin-set', '^0^2') self.test_config.set('pci-passthrough-whitelist', 'mypcidevices') libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '-d', 'arch': platform.machine(), 'hugepages': True, 'kvm_hugepages': 1, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 1024, 'vcpu_pin_set': '^0^2', 'pci_passthrough_whitelist': 'mypcidevices' }, libvirt())
def test_libvirt_use_multipath(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'yakkety'} self.os_release.return_value = 'ocata' self.test_config.set('use-multipath', True) libvirt = context.NovaComputeLibvirtContext() self.assertEqual( { 'libvirtd_opts': '', 'libvirt_user': '******', 'use_multipath': True, 'arch': platform.machine(), 'ksm': 'AUTO', 'kvm_hugepages': 0, 'listen_tls': 0, 'host_uuid': self.host_uuid, 'force_raw_images': True, 'reserved_host_memory': 512 }, libvirt())
def test_libvirt_cpu_mode_none(self, mock_uuid): self.test_config.set('cpu-mode', 'none') mock_uuid.return_value = 'e46e530d-18ae-4a67-9ff0-e6e2ba7c60a7' libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['cpu_mode'], 'none')
def test_libvirt_cpu_mode_default(self, mock_uuid): libvirt = context.NovaComputeLibvirtContext() self.assertFalse('cpu-mode' in libvirt())
def test_libvirt_opts_xenial(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) self.lsb_release.return_value = {'DISTRIB_CODENAME': 'xenial'} libvirt = context.NovaComputeLibvirtContext() self.assertEqual(libvirt()['libvirtd_opts'], '')