diff --git a/nova/tests/functional/libvirt/base.py b/nova/tests/functional/libvirt/base.py index 554800b13b97..21a8412a2cfd 100644 --- a/nova/tests/functional/libvirt/base.py +++ b/nova/tests/functional/libvirt/base.py @@ -15,6 +15,7 @@ import copy import fixtures +import io import mock from nova.objects import fields as obj_fields @@ -45,7 +46,20 @@ class ServersTestBase(base.ServersTestBase): self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.useFixture(func_fixtures.PlacementFixture()) - self.stub_out('nova.privsep.utils.supports_direct_io', lambda _: True) + self.useFixture(fixtures.MockPatch( + 'nova.virt.libvirt.LibvirtDriver._create_image')) + self.useFixture(fixtures.MockPatch( + 'nova.virt.libvirt.LibvirtDriver._get_local_gb_info', + return_value={'total': 128, 'used': 44, 'free': 84})) + self.useFixture(fixtures.MockPatch( + 'nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', + return_value=True)) + self.useFixture(fixtures.MockPatch( + 'nova.virt.libvirt.driver.libvirt_utils.file_open', + side_effect=[io.BytesIO(b''), io.BytesIO(b'')])) + self.useFixture(fixtures.MockPatch( + 'nova.privsep.utils.supports_direct_io', + return_value=True)) # Mock the 'get_connection' function, as we're going to need to provide # custom capabilities for each test diff --git a/nova/tests/functional/libvirt/test_numa_servers.py b/nova/tests/functional/libvirt/test_numa_servers.py index 351caa9ebf0e..09d936221d4d 100644 --- a/nova/tests/functional/libvirt/test_numa_servers.py +++ b/nova/tests/functional/libvirt/test_numa_servers.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import io import six import mock @@ -57,14 +56,6 @@ class NUMAServersTestBase(base.ServersTestBase): return self.start_service('scheduler') -@mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - new=mock.Mock(return_value={'total': 128, - 'used': 44, - 'free': 84})) -@mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - new=mock.Mock(return_value=True)) -@mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - new=mock.Mock(side_effect=[io.BytesIO(b''), io.BytesIO(b'')])) class NUMAServersTest(NUMAServersTestBase): def _run_build_test(self, flavor_id, end_status='ACTIVE'): @@ -188,16 +179,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): return self._wait_for_state_change(found_server, 'BUILD') - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_create_server_with_single_physnet( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_create_server_with_single_physnet(self): extra_spec = {'hw:numa_nodes': '1'} flavor_id = self._create_flavor(extra_spec=extra_spec) networks = [ @@ -210,16 +192,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertTrue(self.mock_filter.called) self.assertEqual('ACTIVE', status) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_create_server_with_multiple_physnets( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_create_server_with_multiple_physnets(self): """Test multiple networks split across host NUMA nodes. This should pass because the networks requested are split across @@ -239,16 +212,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertTrue(self.mock_filter.called) self.assertEqual('ACTIVE', status) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_create_server_with_multiple_physnets_fail( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_create_server_with_multiple_physnets_fail(self): """Test multiple networks split across host NUMA nodes. This should fail because we've requested a single-node instance but the @@ -267,16 +231,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertTrue(self.mock_filter.called) self.assertEqual('ERROR', status) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_create_server_with_physnet_and_tunneled_net( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_create_server_with_physnet_and_tunneled_net(self): """Test combination of physnet and tunneled network. This should pass because we've requested a single-node instance and the @@ -295,16 +250,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertTrue(self.mock_filter.called) self.assertEqual('ACTIVE', status) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_rebuild_server_with_network_affinity( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_rebuild_server_with_network_affinity(self): extra_spec = {'hw:numa_nodes': '1'} flavor_id = self._create_flavor(extra_spec=extra_spec) networks = [ @@ -353,16 +299,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertEqual(500, ex.response.status_code) self.assertIn('NoValidHost', six.text_type(ex)) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_cold_migrate_with_physnet( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_cold_migrate_with_physnet(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, kB_mem=15740000) @@ -426,16 +363,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase): self.assertIsNotNone(network_metadata) self.assertEqual(set(['foo']), network_metadata.physnets) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_cold_migrate_with_physnet_fails( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_cold_migrate_with_physnet_fails(self): host_infos = [ # host 1 has room on both nodes fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, diff --git a/nova/tests/functional/libvirt/test_pci_sriov_servers.py b/nova/tests/functional/libvirt/test_pci_sriov_servers.py index 462b2b942a58..a52977b941c1 100644 --- a/nova/tests/functional/libvirt/test_pci_sriov_servers.py +++ b/nova/tests/functional/libvirt/test_pci_sriov_servers.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import io - import fixtures import mock from oslo_config import cfg @@ -50,17 +48,6 @@ class _PCIServersTestBase(base.ServersTestBase): 'nova.scheduler.filters.pci_passthrough_filter' '.PciPassthroughFilter.host_passes', side_effect=host_pass_mock)).mock - self.useFixture(fixtures.MockPatch( - 'nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84})) - self.useFixture(fixtures.MockPatch( - 'nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True)) - self.useFixture(fixtures.MockPatch( - 'nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')])) def _setup_scheduler_service(self): # Enable the 'NUMATopologyFilter', 'PciPassthroughFilter' @@ -139,8 +126,7 @@ class SRIOVServersTest(_PCIServersTestBase): }, )] - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_VF(self, img_mock): + def test_create_server_with_VF(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, @@ -155,8 +141,7 @@ class SRIOVServersTest(_PCIServersTestBase): self._run_build_test(flavor_id) - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_PF(self, img_mock): + def test_create_server_with_PF(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, @@ -171,8 +156,7 @@ class SRIOVServersTest(_PCIServersTestBase): self._run_build_test(flavor_id) - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_PF_no_VF(self, img_mock): + def test_create_server_with_PF_no_VF(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, @@ -192,8 +176,7 @@ class SRIOVServersTest(_PCIServersTestBase): self._run_build_test(flavor_id_pfs) self._run_build_test(flavor_id_vfs, end_status='ERROR') - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_VF_no_PF(self, img_mock): + def test_create_server_with_VF_no_PF(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, @@ -307,8 +290,7 @@ class PCIServersTest(_PCIServersTestBase): } )] - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_pci_dev_and_numa(self, img_mock): + def test_create_server_with_pci_dev_and_numa(self): """Verifies that an instance can be booted with cpu pinning and with an assigned pci device. """ @@ -329,8 +311,7 @@ class PCIServersTest(_PCIServersTestBase): self._run_build_test(flavor_id) - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_pci_dev_and_numa_fails(self, img_mock): + def test_create_server_with_pci_dev_and_numa_fails(self): """This test ensures that it is not possible to allocated CPU and memory resources from one NUMA node and a PCI device from another. """ @@ -376,8 +357,7 @@ class PCIServersWithNUMAPoliciesTest(_PCIServersTestBase): } )] - @mock.patch('nova.virt.libvirt.LibvirtDriver._create_image') - def test_create_server_with_pci_dev_and_numa(self, img_mock): + def test_create_server_with_pci_dev_and_numa(self): """Validate behavior of 'preferred' PCI NUMA policy. This test ensures that it *is* possible to allocate CPU and memory diff --git a/nova/tests/functional/libvirt/test_rt_servers.py b/nova/tests/functional/libvirt/test_rt_servers.py index b9643f0c1c94..7b1735eee901 100644 --- a/nova/tests/functional/libvirt/test_rt_servers.py +++ b/nova/tests/functional/libvirt/test_rt_servers.py @@ -13,9 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import io -import mock - from nova.tests.functional.api import client from nova.tests.functional.libvirt import base from nova.tests.unit.virt.libvirt import fakelibvirt @@ -46,16 +43,7 @@ class RealTimeServersTest(base.ServersTestBase): client.OpenStackApiException, self.api.post_server, {'server': server}) - @mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info', - return_value={'total': 128, - 'used': 44, - 'free': 84}) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname', - return_value=True) - @mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open', - side_effect=[io.BytesIO(b''), io.BytesIO(b'')]) - def test_success( - self, mock_file_open, mock_valid_hostname, mock_get_fs_info): + def test_success(self): host_info = fakelibvirt.NUMAHostInfo(cpu_nodes=2, cpu_sockets=1, cpu_cores=2, cpu_threads=2, kB_mem=15740000)