libvirt: Remove 'enable_hairpin'
This was only used with nova-network. Change-Id: Ia9dea804717d7afa9cf83f9689a018888987955d Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
9142a97f24
commit
783d4cb246
@ -113,13 +113,6 @@ def ploop_restore_descriptor(image_dir, base_delta, fmt):
|
|||||||
check_exit_code=True)
|
check_exit_code=True)
|
||||||
|
|
||||||
|
|
||||||
@nova.privsep.sys_admin_pctxt.entrypoint
|
|
||||||
def enable_hairpin(interface):
|
|
||||||
"""Enable hairpin mode for a libvirt guest."""
|
|
||||||
with open('/sys/class/net/%s/brport/hairpin_mode' % interface, 'w') as f:
|
|
||||||
f.write('1')
|
|
||||||
|
|
||||||
|
|
||||||
@nova.privsep.sys_admin_pctxt.entrypoint
|
@nova.privsep.sys_admin_pctxt.entrypoint
|
||||||
def plug_infiniband_vif(vnic_mac, device_id, fabric, net_model, pci_slot):
|
def plug_infiniband_vif(vnic_mac, device_id, fabric, net_model, pci_slot):
|
||||||
processutils.execute('ebrctl', 'add-port', vnic_mac, device_id,
|
processutils.execute('ebrctl', 'add-port', vnic_mac, device_id,
|
||||||
|
@ -76,18 +76,6 @@ class LibvirtTestCase(test.NoDBTestCase):
|
|||||||
'ploop', 'restore-descriptor', '-f', 'raw',
|
'ploop', 'restore-descriptor', '-f', 'raw',
|
||||||
'/img/dir', 'imagefile', check_exit_code=True)
|
'/img/dir', 'imagefile', check_exit_code=True)
|
||||||
|
|
||||||
def test_enable_hairping(self):
|
|
||||||
mock_open = mock.mock_open()
|
|
||||||
with mock.patch.object(six.moves.builtins, 'open',
|
|
||||||
new=mock_open) as mock_open:
|
|
||||||
nova.privsep.libvirt.enable_hairpin('eth0')
|
|
||||||
|
|
||||||
handle = mock_open()
|
|
||||||
self.assertTrue(mock.call('/sys/class/net/eth0/brport/'
|
|
||||||
'hairpin_mode', 'w') in
|
|
||||||
mock_open.mock_calls)
|
|
||||||
handle.write.assert_called_with('1')
|
|
||||||
|
|
||||||
@mock.patch('oslo_concurrency.processutils.execute')
|
@mock.patch('oslo_concurrency.processutils.execute')
|
||||||
def test_plug_infiniband_vif(self, mock_execute):
|
def test_plug_infiniband_vif(self, mock_execute):
|
||||||
nova.privsep.libvirt.plug_infiniband_vif('fakemac', 'devid', 'fabric',
|
nova.privsep.libvirt.plug_infiniband_vif('fakemac', 'devid', 'fabric',
|
||||||
|
@ -10561,7 +10561,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||||||
"<devices>{}</devices></domain>")
|
"<devices>{}</devices></domain>")
|
||||||
disks_xml = ''
|
disks_xml = ''
|
||||||
for dsk in disks:
|
for dsk in disks:
|
||||||
if dsk['type'] is not 'network':
|
if dsk['type'] != 'network':
|
||||||
disks_xml = ''.join([disks_xml,
|
disks_xml = ''.join([disks_xml,
|
||||||
"<disk type='{type}'>"
|
"<disk type='{type}'>"
|
||||||
"<driver name='qemu' type='{driver}'/>"
|
"<driver name='qemu' type='{driver}'/>"
|
||||||
@ -17870,40 +17870,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||||||
domain=fake_domain)
|
domain=fake_domain)
|
||||||
self.assertTrue(self.log_error_called)
|
self.assertTrue(self.log_error_called)
|
||||||
|
|
||||||
@mock.patch('nova.privsep.libvirt.enable_hairpin')
|
|
||||||
def test_create_domain_enable_hairpin_fails(self, mock_writefile):
|
|
||||||
"""Tests that the xml is logged when enabling hairpin mode for the
|
|
||||||
domain fails.
|
|
||||||
"""
|
|
||||||
# Guest.enable_hairpin is only called for nova-network.
|
|
||||||
# TODO(mikal): remove this test when nova-net goes away
|
|
||||||
self.flags(use_neutron=False)
|
|
||||||
fake_xml = "<test>this is a test</test>"
|
|
||||||
fake_domain = FakeVirtDomain(fake_xml)
|
|
||||||
|
|
||||||
mock_writefile.side_effect = IOError
|
|
||||||
|
|
||||||
def fake_get_interfaces(*args):
|
|
||||||
return ["dev"]
|
|
||||||
|
|
||||||
self.log_error_called = False
|
|
||||||
|
|
||||||
def fake_error(msg, *args, **kwargs):
|
|
||||||
self.log_error_called = True
|
|
||||||
self.assertIn(fake_xml, msg % args)
|
|
||||||
|
|
||||||
self.stub_out('nova.virt.libvirt.guest.LOG.error', fake_error)
|
|
||||||
|
|
||||||
self.create_fake_libvirt_mock()
|
|
||||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
|
||||||
self.stub_out(
|
|
||||||
'nova.virt.libvirt.guest.Guest.get_interfaces',
|
|
||||||
fake_get_interfaces)
|
|
||||||
|
|
||||||
self.assertRaises(IOError, drvr._create_domain, domain=fake_domain,
|
|
||||||
power_on=False)
|
|
||||||
self.assertTrue(self.log_error_called)
|
|
||||||
|
|
||||||
def test_get_vnc_console(self):
|
def test_get_vnc_console(self):
|
||||||
instance = objects.Instance(**self.test_instance)
|
instance = objects.Instance(**self.test_instance)
|
||||||
dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
|
dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
|
||||||
@ -21005,9 +20971,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
|
|||||||
external_events)
|
external_events)
|
||||||
return mock.MagicMock()
|
return mock.MagicMock()
|
||||||
|
|
||||||
def fake_enable_hairpin(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def fake_get_info(self, instance):
|
def fake_get_info(self, instance):
|
||||||
if powered_on:
|
if powered_on:
|
||||||
return hardware.InstanceInfo(state=power_state.RUNNING)
|
return hardware.InstanceInfo(state=power_state.RUNNING)
|
||||||
@ -21029,8 +20992,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
|
|||||||
fw)
|
fw)
|
||||||
self.stub_out('nova.virt.libvirt.driver.LibvirtDriver.'
|
self.stub_out('nova.virt.libvirt.driver.LibvirtDriver.'
|
||||||
'_create_domain_and_network', fake_create_domain)
|
'_create_domain_and_network', fake_create_domain)
|
||||||
self.stub_out('nova.virt.libvirt.guest.Guest.enable_hairpin',
|
|
||||||
fake_enable_hairpin)
|
|
||||||
self.stub_out('nova.virt.libvirt.driver.LibvirtDriver.get_info',
|
self.stub_out('nova.virt.libvirt.driver.LibvirtDriver.get_info',
|
||||||
fake_get_info)
|
fake_get_info)
|
||||||
self.stub_out('nova.utils.get_image_from_system_metadata',
|
self.stub_out('nova.utils.get_image_from_system_metadata',
|
||||||
|
@ -89,27 +89,6 @@ class GuestTestCase(test.NoDBTestCase):
|
|||||||
self.assertRaises(test.TestingException, self.guest.launch)
|
self.assertRaises(test.TestingException, self.guest.launch)
|
||||||
self.assertEqual(1, mock_safe_decode.called)
|
self.assertEqual(1, mock_safe_decode.called)
|
||||||
|
|
||||||
@mock.patch('nova.privsep.libvirt.enable_hairpin')
|
|
||||||
@mock.patch.object(libvirt_guest.Guest, 'get_interfaces')
|
|
||||||
def test_enable_hairpin(self, mock_get_interfaces, mock_writefile):
|
|
||||||
mock_get_interfaces.return_value = ["vnet0", "vnet1"]
|
|
||||||
self.guest.enable_hairpin()
|
|
||||||
mock_writefile.assert_has_calls([
|
|
||||||
mock.call('vnet0'),
|
|
||||||
mock.call('vnet1')]
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch.object(encodeutils, 'safe_decode')
|
|
||||||
@mock.patch('nova.privsep.libvirt.enable_hairpin')
|
|
||||||
@mock.patch.object(libvirt_guest.Guest, 'get_interfaces')
|
|
||||||
def test_enable_hairpin_exception(self, mock_get_interfaces,
|
|
||||||
mock_writefile, mock_safe_decode):
|
|
||||||
mock_get_interfaces.return_value = ["foo"]
|
|
||||||
mock_writefile.side_effect = test.TestingException
|
|
||||||
|
|
||||||
self.assertRaises(test.TestingException, self.guest.enable_hairpin)
|
|
||||||
self.assertEqual(1, mock_safe_decode.called)
|
|
||||||
|
|
||||||
def test_get_interfaces(self):
|
def test_get_interfaces(self):
|
||||||
self.domain.XMLDesc.return_value = """<domain>
|
self.domain.XMLDesc.return_value = """<domain>
|
||||||
<devices>
|
<devices>
|
||||||
|
@ -6146,9 +6146,6 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
if power_on or pause:
|
if power_on or pause:
|
||||||
guest.launch(pause=pause)
|
guest.launch(pause=pause)
|
||||||
|
|
||||||
if not utils.is_neutron():
|
|
||||||
guest.enable_hairpin()
|
|
||||||
|
|
||||||
return guest
|
return guest
|
||||||
|
|
||||||
def _neutron_failed_callback(self, event_name, instance):
|
def _neutron_failed_callback(self, event_name, instance):
|
||||||
@ -9337,7 +9334,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
# being left in an ERROR state and still marked on the source.
|
# being left in an ERROR state and still marked on the source.
|
||||||
try:
|
try:
|
||||||
self._disconnect_volume(context, connection_info, instance)
|
self._disconnect_volume(context, connection_info, instance)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
volume_id = driver_block_device.get_volume_id(connection_info)
|
volume_id = driver_block_device.get_volume_id(connection_info)
|
||||||
LOG.exception("Ignoring exception while attempting to "
|
LOG.exception("Ignoring exception while attempting to "
|
||||||
"disconnect volume %s from the source host "
|
"disconnect volume %s from the source host "
|
||||||
|
@ -40,7 +40,6 @@ import six
|
|||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
import nova.privsep.libvirt
|
|
||||||
from nova.virt import hardware
|
from nova.virt import hardware
|
||||||
from nova.virt.libvirt import config as vconfig
|
from nova.virt.libvirt import config as vconfig
|
||||||
|
|
||||||
@ -194,17 +193,6 @@ class Guest(object):
|
|||||||
"""Resumes a paused guest."""
|
"""Resumes a paused guest."""
|
||||||
self._domain.resume()
|
self._domain.resume()
|
||||||
|
|
||||||
def enable_hairpin(self):
|
|
||||||
"""Enables hairpin mode for this guest."""
|
|
||||||
interfaces = self.get_interfaces()
|
|
||||||
try:
|
|
||||||
for interface in interfaces:
|
|
||||||
nova.privsep.libvirt.enable_hairpin(interface)
|
|
||||||
except Exception:
|
|
||||||
with excutils.save_and_reraise_exception():
|
|
||||||
LOG.error('Error enabling hairpin mode with XML: %s',
|
|
||||||
self._encoded_xml, errors='ignore')
|
|
||||||
|
|
||||||
def get_interfaces(self):
|
def get_interfaces(self):
|
||||||
"""Returns a list of all network interfaces for this domain."""
|
"""Returns a list of all network interfaces for this domain."""
|
||||||
doc = None
|
doc = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user