Merge "Add checks for driver attach_interfaces capability"
This commit is contained in:
commit
655922ca66
@ -119,7 +119,8 @@ class InterfaceAttachmentController(wsgi.Controller):
|
||||
exception.NetworkDuplicated,
|
||||
exception.NetworkAmbiguous,
|
||||
exception.NoMoreFixedIps,
|
||||
exception.PortNotUsable) as e:
|
||||
exception.PortNotUsable,
|
||||
exception.AttachInterfaceNotSupported) as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
except (exception.InstanceIsLocked,
|
||||
exception.FixedIpAlreadyInUse,
|
||||
@ -128,8 +129,6 @@ class InterfaceAttachmentController(wsgi.Controller):
|
||||
except (exception.PortNotFound,
|
||||
exception.NetworkNotFound) as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
common.raise_feature_not_supported()
|
||||
except exception.InterfaceAttachFailed as e:
|
||||
raise webob.exc.HTTPInternalServerError(
|
||||
explanation=e.format_message())
|
||||
|
@ -5023,6 +5023,9 @@ class ComputeManager(manager.Manager):
|
||||
def attach_interface(self, context, instance, network_id, port_id,
|
||||
requested_ip):
|
||||
"""Use hotplug to add an network adapter to an instance."""
|
||||
if not self.driver.capabilities['supports_attach_interface']:
|
||||
raise exception.AttachInterfaceNotSupported(
|
||||
instance_id=instance.uuid)
|
||||
bind_host_id = self.driver.network_binding_host_id(context, instance)
|
||||
network_info = self.network_api.allocate_port_for_instance(
|
||||
context, instance, port_id, network_id, requested_ip,
|
||||
|
@ -2119,3 +2119,8 @@ class OsInfoNotFound(NotFound):
|
||||
|
||||
class BuildRequestNotFound(NotFound):
|
||||
msg_fmt = _("BuildRequest not found for instance %(uuid)s")
|
||||
|
||||
|
||||
class AttachInterfaceNotSupported(Invalid):
|
||||
msg_fmt = _("Attaching interfaces is not supported for "
|
||||
"instance %(instance)s.")
|
||||
|
@ -303,14 +303,6 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
|
||||
self.attachments.create, self.req, FAKE_UUID1,
|
||||
body=body)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'attach_interface',
|
||||
side_effect=NotImplementedError())
|
||||
def test_attach_interface_with_not_implemented(self, _mock):
|
||||
body = {'interfaceAttachment': {'net_id': FAKE_NET_ID1}}
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.attachments.create, self.req, FAKE_UUID1,
|
||||
body=body)
|
||||
|
||||
def test_detach_interface_with_invalid_state(self):
|
||||
def fake_detach_interface_invalid_state(*args, **kwargs):
|
||||
raise exception.InstanceInvalidState(
|
||||
|
@ -9528,6 +9528,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
bind_host_id='fake-host'
|
||||
).AndReturn(nwinfo)
|
||||
self.mox.ReplayAll()
|
||||
with mock.patch.dict(self.compute.driver.capabilities,
|
||||
supports_attach_interface=True):
|
||||
vif = self.compute.attach_interface(self.context,
|
||||
instance,
|
||||
network_id,
|
||||
@ -9555,8 +9557,10 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
mock.patch.object(self.compute.network_api,
|
||||
'allocate_port_for_instance'),
|
||||
mock.patch.object(self.compute.network_api,
|
||||
'deallocate_port_for_instance')) as (
|
||||
mock_attach, mock_allocate, mock_deallocate):
|
||||
'deallocate_port_for_instance'),
|
||||
mock.patch.dict(self.compute.driver.capabilities,
|
||||
supports_attach_interface=True)) as (
|
||||
mock_attach, mock_allocate, mock_deallocate, mock_dict):
|
||||
|
||||
mock_allocate.return_value = nwinfo
|
||||
mock_attach.side_effect = exception.NovaException("attach_failed")
|
||||
|
@ -1663,6 +1663,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
mock.call(self.context, f_instance, e,
|
||||
mock.ANY)])
|
||||
|
||||
with mock.patch.dict(self.compute.driver.capabilities,
|
||||
supports_attach_interface=True):
|
||||
do_test()
|
||||
|
||||
def test_detach_interface_failure(self):
|
||||
|
@ -121,6 +121,15 @@ class IronicDriverTestCase(test.NoDBTestCase):
|
||||
self.assertFalse(self.driver.capabilities['supports_recreate'],
|
||||
'Driver capabilities for \'supports_recreate\''
|
||||
'is invalid')
|
||||
self.assertFalse(self.driver.capabilities[
|
||||
'supports_migrate_to_same_host'],
|
||||
'Driver capabilities for '
|
||||
'\'supports_migrate_to_same_host\' is invalid')
|
||||
self.assertFalse(self.driver.capabilities[
|
||||
'supports_attach_interface'],
|
||||
'Driver capabilities for '
|
||||
'\'supports_attach_interface\' '
|
||||
'is invalid')
|
||||
|
||||
def test__get_hypervisor_type(self):
|
||||
self.assertEqual('ironic', self.driver._get_hypervisor_type())
|
||||
|
@ -663,6 +663,10 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
self.assertFalse(drvr.capabilities['supports_migrate_to_same_host'],
|
||||
'Driver capabilities for '
|
||||
'\'supports_migrate_to_same_host\' is invalid')
|
||||
self.assertTrue(drvr.capabilities['supports_attach_interface'],
|
||||
'Driver capabilities for '
|
||||
'\'supports_attach_interface\' '
|
||||
'is invalid')
|
||||
|
||||
def create_fake_libvirt_mock(self, **kwargs):
|
||||
"""Defining mocks for LibvirtDriver(libvirt is not used)."""
|
||||
|
@ -135,7 +135,8 @@ class ComputeDriver(object):
|
||||
capabilities = {
|
||||
"has_imagecache": False,
|
||||
"supports_recreate": False,
|
||||
"supports_migrate_to_same_host": False
|
||||
"supports_migrate_to_same_host": False,
|
||||
"supports_attach_interface": False
|
||||
}
|
||||
|
||||
def __init__(self, virtapi):
|
||||
|
@ -94,7 +94,8 @@ class HyperVDriver(driver.ComputeDriver):
|
||||
capabilities = {
|
||||
"has_imagecache": False,
|
||||
"supports_recreate": False,
|
||||
"supports_migrate_to_same_host": True
|
||||
"supports_migrate_to_same_host": True,
|
||||
"supports_attach_interface": True
|
||||
}
|
||||
|
||||
def __init__(self, virtapi):
|
||||
|
@ -124,7 +124,9 @@ class IronicDriver(virt_driver.ComputeDriver):
|
||||
|
||||
capabilities = {"has_imagecache": False,
|
||||
"supports_recreate": False,
|
||||
"supports_migrate_to_same_host": False}
|
||||
"supports_migrate_to_same_host": False,
|
||||
"supports_attach_interface": False
|
||||
}
|
||||
|
||||
def __init__(self, virtapi, read_only=False):
|
||||
super(IronicDriver, self).__init__(virtapi)
|
||||
|
@ -504,7 +504,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
capabilities = {
|
||||
"has_imagecache": True,
|
||||
"supports_recreate": True,
|
||||
"supports_migrate_to_same_host": False
|
||||
"supports_migrate_to_same_host": False,
|
||||
"supports_attach_interface": True
|
||||
}
|
||||
|
||||
def __init__(self, virtapi, read_only=False):
|
||||
|
@ -56,7 +56,8 @@ class VMwareVCDriver(driver.ComputeDriver):
|
||||
capabilities = {
|
||||
"has_imagecache": True,
|
||||
"supports_recreate": False,
|
||||
"supports_migrate_to_same_host": True
|
||||
"supports_migrate_to_same_host": True,
|
||||
"supports_attach_interface": True
|
||||
}
|
||||
|
||||
# Legacy nodename is of the form: <mo id>(<cluster name>)
|
||||
|
Loading…
Reference in New Issue
Block a user