def test_same_bmc_different_macs(self):
     uuid2 = uuidutils.generate_uuid()
     node_cache.add_node(uuid2,
                         istate.States.starting,
                         bmc_address='1.2.3.4',
                         mac=self.macs2)
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
     self.assertEqual(self.uuid, res.uuid)
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs2)
     self.assertEqual(uuid2, res.uuid)
Example #2
0
def _find_node_info(introspection_data, failures):
    try:
        return node_cache.find_node(
            bmc_address=introspection_data.get('ipmi_address'),
            mac=utils.get_valid_macs(introspection_data))
    except utils.NotFoundInCacheError as exc:
        not_found_hook = plugins_base.node_not_found_hook_manager()
        if not_found_hook is None:
            failures.append(_('Look up error: %s') % exc)
            return

        LOG.debug('Running node_not_found_hook %s',
                  CONF.processing.node_not_found_hook,
                  data=introspection_data)

        # NOTE(sambetts): If not_found_hook is not none it means that we were
        # unable to find the node in the node cache and there is a node not
        # found hook defined so we should try to send the introspection data
        # to that hook to generate the node info before bubbling up the error.
        try:
            node_info = not_found_hook.driver(introspection_data)
            if node_info:
                return node_info
            failures.append(_("Node not found hook returned nothing"))
        except Exception as exc:
            failures.append(_("Node not found hook failed: %s") % exc)
    except utils.Error as exc:
        failures.append(_('Look up error: %s') % exc)
 def test_both(self):
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(datetime.datetime.utcnow() - datetime.timedelta(
         seconds=60) < res.started_at < datetime.datetime.utcnow() +
                     datetime.timedelta(seconds=1))
     self.assertTrue(res._locked)
 def test_macs(self):
     res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(datetime.datetime.utcnow() - datetime.timedelta(
         seconds=60) < res.started_at < datetime.datetime.utcnow() +
                     datetime.timedelta(seconds=1))
     self.assertTrue(res._locked)
 def test_macs(self):
     res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(
         datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
         < res.started_at <
         datetime.datetime.utcnow() + datetime.timedelta(seconds=1))
     self.assertTrue(res._locked)
 def test_bmc(self):
     res = node_cache.find_node(bmc_address='1.2.3.4')
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(
         datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
         < res.started_at <
         datetime.datetime.utcnow() + datetime.timedelta(seconds=1))
     self.assertTrue(res._locked)
Example #7
0
def _find_node_info(introspection_data, failures):
    try:
        address = utils.get_ipmi_address_from_data(introspection_data)
        v6address = utils.get_ipmi_v6address_from_data(introspection_data)
        bmc_addresses = list(filter(None, [address, v6address]))
        macs = utils.get_valid_macs(introspection_data)
        return node_cache.find_node(bmc_address=bmc_addresses, mac=macs)
    except utils.NotFoundInCacheError as exc:
        if CONF.processing.permit_active_introspection:
            try:
                return node_cache.record_node(bmc_addresses=bmc_addresses,
                                              macs=macs)
            except utils.NotFoundInCacheError:
                LOG.debug(
                    'Active nodes introspection is enabled, but no node '
                    'was found for MAC(s) %(mac)s and BMC address(es) '
                    '%(addr)s; proceeding with discovery', {
                        'mac': ', '.join(macs) if macs else None,
                        'addr': ', '.join(filter(None, bmc_addresses)) or None
                    })

        not_found_hook = plugins_base.node_not_found_hook_manager()
        if not_found_hook is None:
            failures.append(_('Look up error: %s') % exc)
            return

        LOG.debug('Running node_not_found_hook %s',
                  CONF.processing.node_not_found_hook,
                  data=introspection_data)

        # NOTE(sambetts): If not_found_hook is not none it means that we were
        # unable to find the node in the node cache and there is a node not
        # found hook defined so we should try to send the introspection data
        # to that hook to generate the node info before bubbling up the error.
        try:
            node_info = not_found_hook.driver(introspection_data)
            if node_info:
                return node_info
            failures.append(_("Node not found hook returned nothing"))
        except Exception as exc:
            failures.append(_("Node not found hook failed: %s") % exc)
    except utils.Error as exc:
        failures.append(_('Look up error: %s') % exc)
Example #8
0
def _find_node_info(introspection_data, failures):
    try:
        return node_cache.find_node(
            bmc_address=introspection_data.get('ipmi_address'),
            mac=utils.get_valid_macs(introspection_data))
    except utils.NotFoundInCacheError as exc:
        not_found_hook = plugins_base.node_not_found_hook_manager()
        if not_found_hook is None:
            failures.append(_('Look up error: %s') % exc)
            return
        # NOTE(sambetts): If not_found_hook is not none it means that we were
        # unable to find the node in the node cache and there is a node not
        # found hook defined so we should try to send the introspection data
        # to that hook to generate the node info before bubbling up the error.
        try:
            node_info = not_found_hook.driver(introspection_data)
            if node_info:
                return node_info
            failures.append(_("Node not found hook returned nothing"))
        except Exception as exc:
            failures.append(_("Node not found hook failed: %s") % exc)
    except utils.Error as exc:
        failures.append(_('Look up error: %s') % exc)
 def test_both(self):
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(time.time() - 60 < res.started_at < time.time() + 1)
     self.assertTrue(res._locked)
 def test_macs(self):
     res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(time.time() - 60 < res.started_at < time.time() + 1)
     self.assertTrue(res._locked)
 def test_both(self):
     res = node_cache.find_node(bmc_address='1.2.3.4',
                                mac=self.macs)
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(time.time() - 60 < res.started_at < time.time() + 1)
     self.assertTrue(res._locked)
 def test_macs(self):
     res = node_cache.find_node(mac=['11:22:33:33:33:33', self.macs[1]])
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(time.time() - 60 < res.started_at < time.time() + 1)
     self.assertTrue(res._locked)
 def test_bmc(self):
     res = node_cache.find_node(bmc_address='1.2.3.4')
     self.assertEqual(self.uuid, res.uuid)
     self.assertTrue(time.time() - 60 < res.started_at < time.time() + 1)