Remove 'nova.virt.libvirt.compat'

This contained a single wrapper for 'domain.info()' that worked around a
race in libvirt 1.2.11. We haven't supported this version for quite some
time [1] so the module itself can go.

[1] http://git.openstack.org/cgit/openstack/nova/commit/?id=28d337b --
    Pick next minimum libvirt / QEMU versions for "Stein"

Change-Id: I690d64c01accb10afc2ff20844e2d51bfa68e635
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-07-04 10:17:10 +01:00
parent 1fdbe88ce7
commit 00740b063f
5 changed files with 6 additions and 114 deletions

View File

@ -1,66 +0,0 @@
# 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 mock
from nova.compute import power_state
from nova import test
from nova.tests.unit.virt.libvirt import fakelibvirt
from nova.virt.libvirt import compat
from nova.virt.libvirt import host
class CompatTestCase(test.NoDBTestCase):
def setUp(self):
super(CompatTestCase, self).setUp()
self.useFixture(fakelibvirt.FakeLibvirtFixture())
@mock.patch.object(host.Host, 'has_min_version')
def test_get_domain_info(self, mock_has_min_version):
test_host = host.Host("qemu:///system")
domain = mock.MagicMock()
expected = [power_state.RUNNING, 512, 512, None, None]
race = fakelibvirt.make_libvirtError(
fakelibvirt.libvirtError,
'ERR',
error_code=fakelibvirt.VIR_ERR_OPERATION_FAILED,
error_message='cannot read cputime for domain')
mock_has_min_version.return_value = True
domain.info.return_value = expected
actual = compat.get_domain_info(fakelibvirt, test_host, domain)
self.assertEqual(actual, expected)
self.assertEqual(domain.info.call_count, 1)
domain.info.reset_mock()
domain.info.side_effect = race
self.assertRaises(fakelibvirt.libvirtError,
compat.get_domain_info,
fakelibvirt, test_host, domain)
self.assertEqual(domain.info.call_count, 1)
domain.info.reset_mock()
mock_has_min_version.return_value = False
domain.info.side_effect = [race, expected]
actual = compat.get_domain_info(fakelibvirt, test_host, domain)
self.assertEqual(actual, expected)
self.assertEqual(domain.info.call_count, 2)
domain.info.reset_mock()
domain.info.side_effect = race
self.assertRaises(fakelibvirt.libvirtError,
compat.get_domain_info,
fakelibvirt, test_host, domain)
self.assertEqual(domain.info.call_count, 2)

View File

@ -1,36 +0,0 @@
# 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.
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
def get_domain_info(libvirt, host, virt_dom):
"""Method virDomain.info (libvirt version < 1.2.11) is
affected by a race condition. See bug #1372670 for more details.
This method detects it to perform a retry.
"""
def is_race(e):
code = e.get_error_code()
message = e.get_error_message()
return (code == libvirt.VIR_ERR_OPERATION_FAILED and
'cannot read cputime for domain' in message)
try:
return virt_dom.info()
except libvirt.libvirtError as e:
if not host.has_min_version((1, 2, 11)) and is_race(e):
LOG.warning('Race detected in libvirt.virDomain.info, '
'trying one more time')
return virt_dom.info()
raise

View File

@ -9273,8 +9273,7 @@ class LibvirtDriver(driver.ComputeDriver):
# TODO(sahid): Needs to use get_info but more changes have to
# be done since a mapping STATE_MAP LIBVIRT_POWER_STATE is
# needed.
(state, max_mem, mem, num_cpu, cpu_time) = \
guest._get_domain_info(self._host)
state, max_mem, mem, num_cpu, cpu_time = guest._get_domain_info()
config_drive = configdrive.required_by(instance)
launched_at = timeutils.normalize_time(instance.launched_at)
uptime = timeutils.delta_seconds(launched_at,

View File

@ -42,7 +42,6 @@ from nova import exception
from nova.i18n import _
import nova.privsep.libvirt
from nova.virt import hardware
from nova.virt.libvirt import compat
from nova.virt.libvirt import config as vconfig
libvirt = None
@ -513,16 +512,12 @@ class Guest(object):
"""Configures a new user password."""
self._domain.setUserPassword(user, new_pass, 0)
def _get_domain_info(self, host):
"""Returns information on Guest
:param host: a host.Host object with current
connection. Unfortunately we need to pass it
because of a workaround with < version 1.2..11
def _get_domain_info(self):
"""Returns information on Guest.
:returns list: [state, maxMem, memory, nrVirtCpu, cpuTime]
"""
return compat.get_domain_info(libvirt, host, self._domain)
return self._domain.info()
def get_info(self, host):
"""Retrieve information from libvirt for a specific instance name.
@ -534,7 +529,7 @@ class Guest(object):
:returns hardware.InstanceInfo:
"""
try:
dom_info = self._get_domain_info(host)
dom_info = self._get_domain_info()
except libvirt.libvirtError as ex:
error_code = ex.get_error_code()
if error_code == libvirt.VIR_ERR_NO_DOMAIN:

View File

@ -909,7 +909,7 @@ class Host(object):
for guest in self.list_guests(only_guests=False):
try:
# TODO(sahid): Use get_info...
dom_mem = int(guest._get_domain_info(self)[2])
dom_mem = int(guest._get_domain_info()[2])
except libvirt.libvirtError as e:
LOG.warning("couldn't obtain the memory from domain:"
" %(uuid)s, exception: %(ex)s",