nova/nova/tests/functional/libvirt/test_report_cpu_traits.py
Eric Fried 23fd6c2287 FakeLibvirtFixture: mock get_fs_info
A couple of recently-written [1][2] functional tests were mocking pieces
of the libvirt driver in ways that the existing FakeLibvirtFixture was
already doing [3].  This patch commonizes those tests to use the
fixture.

In addition, while those tests were being authored, they failed
intermittently with this symptom:

...
  File "nova/virt/libvirt/driver.py", line 6405, in get_available_resource
    disk_info_dict = self._get_local_gb_info()
  File "nova/virt/libvirt/driver.py", line 5663, in _get_local_gb_info
    info = libvirt_utils.get_fs_info(CONF.instances_path)
  File "nova/virt/libvirt/utils.py", line 370, in get_fs_info
    hddinfo = os.statvfs(path)
OSError: [Errno 2] No such file or directory: '/home/zuul/src/git.openstack.org/openstack/nova/instances'
...
Traceback (most recent call last):
  File "nova/tests/functional/libvirt/test_shared_resource_provider.py", line 45, in setUp
    self.host_uuid = self._get_provider_uuid_by_host(nodename)
  File "nova/tests/functional/integrated_helpers.py", line 410, in _get_provider_uuid_by_host
    'os-hypervisors?hypervisor_hostname_pattern=%s' % host).body
  File "nova/tests/functional/api/client.py", line 224, in api_get
    return APIResponse(self.api_request(relative_uri, **kwargs))
  File "nova/tests/functional/api/client.py", line 206, in api_request
    raise OpenStackApiNotFoundException(response=response)
nova.tests.functional.api.client.OpenStackApiNotFoundException: Item not found

It was discovered that the fix was mocking get_fs_info; so this patch
also adds that mock to FakeLibvirtFixture to avoid the race in future
tests using the fixture.

[1] https://review.openstack.org/#/c/560459/17/nova/tests/functional/libvirt/test_shared_resource_provider.py
[2] https://review.openstack.org/#/c/560317/17/nova/tests/functional/libvirt/test_report_cpu_traits.py
[3] 162e55d07e/nova/tests/unit/virt/libvirt/fakelibvirt.py (L1533-L1537)

Change-Id: I4890406c92f538f7a5f270f70567f12e9531a2ad
2018-07-24 12:37:59 +00:00

55 lines
2.2 KiB
Python

# Copyright (c) 2018 Intel, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from nova import conf
from nova.tests.functional import integrated_helpers
from nova.tests.unit.virt.libvirt import fakelibvirt
CONF = conf.CONF
class LibvirtReportTraitsTests(integrated_helpers.ProviderUsageBaseTestCase):
compute_driver = 'libvirt.LibvirtDriver'
def setUp(self):
super(LibvirtReportTraitsTests, self).setUp()
self.useFixture(fakelibvirt.FakeLibvirtFixture(stub_os_vif=False))
self.useFixture(
fixtures.MockPatch(
'nova.virt.libvirt.driver.LibvirtDriver.init_host'))
self.assertEqual([], self._get_all_providers())
self.compute = self._start_compute(CONF.host)
nodename = self.compute.manager._get_nodename(None)
self.host_uuid = self._get_provider_uuid_by_host(nodename)
def test_report_cpu_traits(self):
# Test CPU traits reported on initial node startup, these specific
# trait values are coming from fakelibvirt's baselineCPU result.
self.assertItemsEqual(['HW_CPU_X86_VMX', 'HW_CPU_X86_AESNI'],
self._get_provider_traits(self.host_uuid))
self._create_trait('CUSTOM_TRAITS')
new_traits = ['CUSTOM_TRAITS', 'HW_CPU_X86_AVX']
self._set_provider_traits(self.host_uuid, new_traits)
self._run_periodics()
# HW_CPU_X86_AVX is filtered out because nova-compute owns CPU traits
# and it's not in the baseline for the host.
self.assertItemsEqual(
['HW_CPU_X86_VMX', 'HW_CPU_X86_AESNI', 'CUSTOM_TRAITS'],
self._get_provider_traits(self.host_uuid)
)