Exemple #1
0
    def driver_vendor_passthru(self, context, driver_name, driver_method,
                                  info):
        """RPC method which synchronously handles driver-level vendor passthru
        calls. These calls don't require a node UUID and are executed on a
        random conductor with the specified driver.

        :param context: an admin context.
        :param driver_name: name of the driver on which to call the method.
        :param driver_method: name of the vendor method, for use by the driver.
        :param info: user-supplied data to pass through to the driver.
        :raises: InvalidParameterValue if supplied info is not valid.
        :raises: UnsupportedDriverExtension if current driver does not have
                 vendor interface, if the vendor interface does not implement
                 driver-level vendor passthru or if the passthru method is
                 unsupported.
        :raises: DriverNotFound if the supplied driver is not loaded.

        """
        # Any locking in a top-level vendor action will need to be done by the
        # implementation, as there is little we could reasonably lock on here.
        LOG.debug("RPC driver_vendor_passthru for driver %s." % driver_name)
        try:
            driver = self.driver_factory[driver_name].obj
        except KeyError:
            raise exception.DriverNotFound(driver_name=driver_name)

        if not getattr(driver, 'vendor', None):
            raise exception.UnsupportedDriverExtension(
                driver=driver_name,
                extension='vendor interface')

        return driver.vendor.driver_vendor_passthru(context,
                                                    method=driver_method,
                                                    **info)
Exemple #2
0
 def test_start_fails_on_missing_driver(self, mock_df):
     mock_df.side_effect = exception.DriverNotFound('test')
     with mock.patch.object(self.dbapi, 'register_conductor',
                            autospec=True) as mock_reg:
         self.assertRaises(exception.DriverNotFound, self.service.init_host)
         self.assertTrue(mock_df.called)
         self.assertFalse(mock_reg.called)
Exemple #3
0
    def get_one(self, driver_name):
        """Retrieve a single driver."""
        # NOTE(russell_h): There is no way to make this more efficient than
        # retrieving a list of drivers using the current sqlalchemy schema, but
        # this path must be exposed for Pecan to route any paths we might
        # choose to expose below it.
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('baremetal:driver:get', cdict, cdict)

        def _find_driver(driver_dict, driver_type):
            for name, hosts in driver_dict.items():
                if name == driver_name:
                    return Driver.convert_with_links(name, list(hosts),
                                                     driver_type, detail=True)

        hw_type_dict = pecan.request.dbapi.get_active_hardware_type_dict()
        driver = _find_driver(hw_type_dict, 'dynamic')
        if driver:
            return driver
        driver_dict = pecan.request.dbapi.get_active_driver_dict()
        driver = _find_driver(driver_dict, 'classic')
        if driver:
            return driver

        raise exception.DriverNotFound(driver_name=driver_name)
Exemple #4
0
    def get_hash_ring(self, driver_name):
        self._ensure_rings_fresh()

        try:
            return self.hash_rings[driver_name]
        except KeyError:
            raise exception.DriverNotFound(_("The driver '%s' is unknown.") %
                                           driver_name)
Exemple #5
0
 def get_ring(self, driver_name, conductor_group):
     try:
         if self.use_groups:
             return self.ring['%s:%s' % (conductor_group, driver_name)]
         return self.ring[driver_name]
     except KeyError:
         raise exception.DriverNotFound(
             _("The driver '%s' is unknown.") % driver_name)
Exemple #6
0
    def _init_extension_manager(cls):
        # NOTE(deva): In case multiple greenthreads queue up on this lock
        #             before _extension_manager is initialized, prevent
        #             creation of multiple NameDispatchExtensionManagers.
        if cls._extension_manager:
            return

        # Check for duplicated driver entries and warn the operator
        # about them
        counter = collections.Counter(CONF.enabled_drivers).items()
        duplicated_drivers = list(dup for (dup, i) in counter if i > 1)
        if duplicated_drivers:
            LOG.warning(
                _LW('The driver(s) "%s" is/are duplicated in the '
                    'list of enabled_drivers. Please check your '
                    'configuration file.'), ', '.join(duplicated_drivers))

        enabled_drivers = set(CONF.enabled_drivers)

        # NOTE(deva): Drivers raise "DriverLoadError" if they are unable to be
        #             loaded, eg. due to missing external dependencies.
        #             We capture that exception, and, only if it is for an
        #             enabled driver, raise it from here. If enabled driver
        #             raises other exception type, it is wrapped in
        #             "DriverLoadError", providing the name of the driver that
        #             caused it, and raised. If the exception is for a
        #             non-enabled driver, we suppress it.
        def _catch_driver_not_found(mgr, ep, exc):
            # NOTE(deva): stevedore loads plugins *before* evaluating
            #             _check_func, so we need to check here, too.
            if ep.name in enabled_drivers:
                if not isinstance(exc, exception.DriverLoadError):
                    raise exception.DriverLoadError(driver=ep.name, reason=exc)
                raise exc

        def _check_func(ext):
            return ext.name in enabled_drivers

        cls._extension_manager = (dispatch.NameDispatchExtensionManager(
            'ironic.drivers',
            _check_func,
            invoke_on_load=True,
            on_load_failure_callback=_catch_driver_not_found))

        # NOTE(deva): if we were unable to load any configured driver, perhaps
        #             because it is not present on the system, raise an error.
        if (sorted(enabled_drivers) != sorted(cls._extension_manager.names())):
            found = cls._extension_manager.names()
            names = [n for n in enabled_drivers if n not in found]
            # just in case more than one could not be found ...
            names = ', '.join(names)
            raise exception.DriverNotFound(driver_name=names)

        LOG.info(_LI("Loaded the following drivers: %s"),
                 cls._extension_manager.names())
Exemple #7
0
def get_hardware_type(hardware_type):
    """Get a hardware type instance by name.

    :param hardware_type: the name of the hardware type to find
    :returns: An instance of ironic.drivers.hardware_type.AbstractHardwareType
    :raises: DriverNotFound if requested hardware type cannot be found
    """
    try:
        return HardwareTypesFactory().get_driver(hardware_type)
    except KeyError:
        raise exception.DriverNotFound(driver_name=hardware_type)
Exemple #8
0
    def _get_ring(self, driver_name, conductor_group):
        # There are no conductors, temporary failure - 503 Service Unavailable
        if not self.ring:
            raise exception.TemporaryFailure()

        try:
            if self.use_groups:
                return self.ring['%s:%s' % (conductor_group, driver_name)]
            return self.ring[driver_name]
        except KeyError:
            raise exception.DriverNotFound(
                _("The driver '%s' is unknown.") % driver_name)
Exemple #9
0
    def get_one(self, driver_name):
        """Retrieve a single driver."""
        # NOTE(russell_h): There is no way to make this more efficient than
        # retrieving a list of drivers using the current sqlalchemy schema, but
        # this path must be exposed for Pecan to route any paths we might
        # choose to expose below it.

        driver_dict = pecan.request.dbapi.get_active_driver_dict()
        for name, hosts in driver_dict.items():
            if name == driver_name:
                return Driver.convert_with_links(name, list(hosts))

        raise exception.DriverNotFound(driver_name=driver_name)
Exemple #10
0
    def _get_driver(self, driver_name):
        """Get the driver.

        :param driver_name: name of the driver.
        :returns: the driver; an instance of a class which implements
                  :class:`ironic.drivers.base.BaseDriver`.
        :raises: DriverNotFound if the driver is not loaded.

        """
        try:
            return self._driver_factory[driver_name].obj
        except KeyError:
            raise exception.DriverNotFound(driver_name=driver_name)
Exemple #11
0
 def __init__(self):
     if not importutils.try_import('seamicroclient'):
         raise exception.DriverNotFound('PXEAndSeaMicroDriver')
     self.power = seamicro.Power()
     self.deploy = pxe.PXEDeploy()
     self.seamicro_vendor = seamicro.VendorPassthru()
     self.pxe_vendor = pxe.VendorPassthru()
     self.mapping = {
         'pass_deploy_info': self.pxe_vendor,
         'attach_volume': self.seamicro_vendor,
         'set_boot_device': self.seamicro_vendor,
         'set_node_vlan_id': self.seamicro_vendor
     }
     self.vendor = utils.MixinVendorInterface(self.mapping)
Exemple #12
0
 def test_driver_properties_invalid_driver_name(self, mock_topic,
                                                mock_properties):
     # Cannot get driver properties for an invalid driver; no RPC topic
     # exists for it.
     driver._DRIVER_PROPERTIES = {}
     driver_name = 'bad_driver'
     mock_topic.side_effect = exception.DriverNotFound(
         driver_name=driver_name)
     mock_properties.return_value = {'prop1': 'Property 1. Required.'}
     ret = self.get_json('/drivers/%s/properties' % driver_name,
                         expect_errors=True)
     self.assertEqual(http_client.NOT_FOUND, ret.status_int)
     mock_topic.assert_called_once_with(driver_name)
     self.assertFalse(mock_properties.called)
Exemple #13
0
 def test_driver_properties_cannot_load(self, mock_topic, mock_properties):
     # Cannot get driver properties for the driver. Although an RPC topic
     # exists for it, the conductor wasn't able to load it.
     driver._DRIVER_PROPERTIES = {}
     driver_name = 'driver'
     mock_topic.return_value = 'driver_topic'
     mock_properties.side_effect = exception.DriverNotFound(
         driver_name=driver_name)
     ret = self.get_json('/drivers/%s/properties' % driver_name,
                         expect_errors=True)
     self.assertEqual(http_client.NOT_FOUND, ret.status_int)
     mock_topic.assert_called_once_with(driver_name)
     mock_properties.assert_called_once_with(mock.ANY, driver_name,
                                             topic=mock_topic.return_value)
Exemple #14
0
    def get_one(self, driver_name):
        """Retrieve a single driver."""
        # NOTE(russell_h): There is no way to make this more efficient than
        # retrieving a list of drivers using the current sqlalchemy schema, but
        # this path must be exposed for Pecan to route any paths we might
        # choose to expose below it.
        api_utils.check_policy('baremetal:driver:get')

        hw_type_dict = api.request.dbapi.get_active_hardware_type_dict()
        for name, hosts in hw_type_dict.items():
            if name == driver_name:
                return convert_with_links(name, list(hosts),
                                          detail=True)

        raise exception.DriverNotFound(driver_name=driver_name)
Exemple #15
0
    def test_excl_lock_get_driver_exception(self, get_ports_mock,
                                            get_driver_mock, reserve_mock,
                                            release_mock, node_get_mock):
        reserve_mock.return_value = self.node
        get_driver_mock.side_effect = exception.DriverNotFound(
            driver_name='foo')

        self.assertRaises(exception.DriverNotFound, task_manager.TaskManager,
                          self.context, 'fake-node-id')

        reserve_mock.assert_called_once_with(self.host, 'fake-node-id')
        get_ports_mock.assert_called_once_with(self.node.id)
        get_driver_mock.assert_called_once_with(self.node.driver)
        release_mock.assert_called_once_with(self.host, self.node.id)
        self.assertFalse(node_get_mock.called)
Exemple #16
0
    def test_excl_lock_build_driver_exception(self, get_portgroups_mock,
                                              get_ports_mock,
                                              build_driver_mock, reserve_mock,
                                              release_mock, node_get_mock):
        reserve_mock.return_value = self.node
        build_driver_mock.side_effect = (exception.DriverNotFound(
            driver_name='foo'))

        self.assertRaises(exception.DriverNotFound, task_manager.TaskManager,
                          self.context, 'fake-node-id')

        node_get_mock.assert_called_once_with(self.context, 'fake-node-id')
        reserve_mock.assert_called_once_with(self.context, self.host,
                                             'fake-node-id')
        get_ports_mock.assert_called_once_with(self.context, self.node.id)
        get_portgroups_mock.assert_called_once_with(self.context, self.node.id)
        build_driver_mock.assert_called_once_with(mock.ANY, driver_name=None)
        release_mock.assert_called_once_with(self.context, self.host,
                                             self.node.id)
Exemple #17
0
def get_driver(driver_name):
    """Simple method to get a ref to an instance of a driver.

    Driver loading is handled by the DriverFactory class. This method
    conveniently wraps that class and returns the actual driver object.

    :param driver_name: the name of the driver class to load
    :returns: An instance of a class which implements
              ironic.drivers.base.BaseDriver
    :raises: DriverNotFound if the requested driver_name could not be
             found in the "ironic.drivers" namespace.

    """

    try:
        factory = DriverFactory()
        return factory[driver_name].obj
    except KeyError:
        raise exception.DriverNotFound(driver_name=driver_name)
Exemple #18
0
 def __init__(self):
     if not importutils.try_import('UcsSdk'):
         raise exception.DriverNotFound('PXEAndCiscoUCSMDriver')
     self.power = cisco.Power()
     self.deploy = pxe.PXEDeploy()
     self.ucsm_vendor = cisco.VendorPassthru()
     self.pxe_vendor = pxe.VendorPassthru()
     self.mapping = {
         'pass_deploy_info': self.pxe_vendor,
         'launch_kvm': self.ucsm_vendor,
         'get_location': self.ucsm_vendor,
         'get_inventory': self.ucsm_vendor,
         'get_faults': self.ucsm_vendor,
         'get_temperature_stats': self.ucsm_vendor,
         'get_power_stats': self.ucsm_vendor,
         'get_firmware_version': self.ucsm_vendor
     }
     self.driver_vendor_mapping = {'enroll_nodes': self.ucsm_vendor}
     self.vendor = utils.MixinVendorInterface(self.mapping,
                                              self.driver_vendor_mapping)
Exemple #19
0
    def test_shared_lock_build_driver_exception(
            self, get_voltgt_mock, get_volconn_mock, get_portgroups_mock,
            get_ports_mock, build_driver_mock,
            reserve_mock, release_mock, node_get_mock):
        node_get_mock.return_value = self.node
        build_driver_mock.side_effect = (
            exception.DriverNotFound(driver_name='foo'))

        self.assertRaises(exception.DriverNotFound,
                          task_manager.TaskManager,
                          self.context,
                          'fake-node-id',
                          shared=True)

        self.assertFalse(reserve_mock.called)
        self.assertFalse(release_mock.called)
        node_get_mock.assert_called_once_with(self.context, 'fake-node-id')
        get_ports_mock.assert_called_once_with(self.context, self.node.id)
        get_portgroups_mock.assert_called_once_with(self.context, self.node.id)
        get_volconn_mock.assert_called_once_with(self.context, self.node.id)
        get_voltgt_mock.assert_called_once_with(self.context, self.node.id)
        build_driver_mock.assert_called_once_with(mock.ANY)
 def test_start_fails_hw_type_register(self, del_mock, reg_mock, log_mock):
     reg_mock.side_effect = exception.DriverNotFound('hw-type')
     self.assertRaises(exception.DriverNotFound, self.service.init_host)
     self.assertTrue(log_mock.error.called)
     del_mock.assert_called_once_with()
Exemple #21
0
 def __getitem__(self, driver_name):
     try:
         return self.ring[driver_name]
     except KeyError:
         raise exception.DriverNotFound(
             _("The driver '%s' is unknown.") % driver_name)
(options, args) = parser.parse_args()

# Load the Discovery Driver
try:
    if options.discovery_driver:
        discovery_driver = driver.DriverManager(
                                namespace='ironic.tools.discovery',
                                name=options.discovery_driver,
                                invoke_on_load=True,
                                invoke_args=(options.username,
                                             options.password,
                                             options.host),
                            )
except KeyError:
    raise exception.DriverNotFound(driver_name=options.discovery_driver)

if options.action == "create":
    chassis = ChassisEnclosure(options.host, options.username,
                               options.password, options.ironic_driver,
                               discovery_driver, None)
    chassis.create_chassis()
elif options.action == "update":
    chassis = ChassisEnclosure(options.host, options.username,
                               options.password, options.ironic_driver,
                               None, options.chassis_uuid)
    chassis.update_chassis()
elif options.action == "delete":
    chassis = ChassisEnclosure(None, None, None, None, None,
                               options.chassis_uuid)
    chassis.delete_chassis()
Exemple #23
0
 def __init__(self):
     if not importutils.try_import('seamicroclient'):
         raise exception.DriverNotFound('FakeSeaMicroDriver')
     self.power = seamicro.Power()
     self.deploy = fake.FakeDeploy()
     self.vendor = seamicro.VendorPassthru()