def test_check_exception_IncompatibleInterface(self, mock_get_interface): self.config(enabled_management_interfaces=['redfish']) self.config(default_management_interface=['redfish']) mock_get_interface.side_effect = exception.IncompatibleInterface( interface_type='management', hardware_type=self.driver) self.assertRaises(exception.NoValidDefaultForInterface, driver_factory.default_interface, self.driver, 'management')
def get_interface(driver_or_hw_type, interface_type, interface_name): """Get interface implementation instance. For hardware types also validates compatibility. :param driver_or_hw_type: a hardware type or classic driver instance. :param interface_type: name of the interface type (e.g. 'boot'). :param interface_name: name of the interface implementation from an appropriate entry point (ironic.hardware.interfaces.<interface type>). :returns: instance of the requested interface implementation. :raises: InterfaceNotFoundInEntrypoint if the entry point was not found. :raises: IncompatibleInterface if driver_or_hw_type is a hardware type and the requested implementation is not compatible with it. """ factory = _INTERFACE_LOADERS[interface_type]() try: impl_instance = factory.get_driver(interface_name) except KeyError: raise exception.InterfaceNotFoundInEntrypoint( iface=interface_name, entrypoint=factory._entrypoint_name, valid=factory.names) if not isinstance(driver_or_hw_type, hardware_type.AbstractHardwareType): # NOTE(dtantsur): classic drivers do not have notion of compatibility return impl_instance if isinstance(driver_or_hw_type, fake_hardware.FakeHardware): # NOTE(dtantsur): special-case fake hardware type to allow testing with # any combinations of interface implementations. return impl_instance supported_impls = getattr(driver_or_hw_type, 'supported_%s_interfaces' % interface_type) if type(impl_instance) not in supported_impls: raise exception.IncompatibleInterface( interface_type=interface_type, interface_impl=impl_instance, hardware_type=driver_or_hw_type.__class__.__name__) return impl_instance