Exemplo n.º 1
0
 def test_lookup_by_mac_only(self):
     uuid = ir_utils.lookup_node(macs=self.macs, ironic=self.ironic)
     self.assertEqual(self.node.uuid, uuid)
     self.ironic.ports.assert_has_calls([
         mock.call(address=mac, fields=['uuid', 'node_uuid'])
         for mac in self.macs
     ])
Exemplo n.º 2
0
 def test_lookup_by_both(self):
     uuid = ir_utils.lookup_node(
         bmc_addresses=[self.bmc_address, self.bmc_v6address],
         macs=self.macs,
         ironic=self.ironic)
     self.assertEqual(self.node.uuid, uuid)
     self.ironic.port.list.assert_has_calls(
         [mock.call(address=mac) for mac in self.macs])
     self.assertEqual(1, self.ironic.node.list.call_count)
Exemplo n.º 3
0
def record_node(ironic=None, bmc_addresses=None, macs=None):
    """Create a cache record for a known active node.

    :param ironic: ironic client instance.
    :param bmc_addresses: list of BMC addresses.
    :param macs: list of MAC addresses.
    :return: NodeInfo
    """
    if not bmc_addresses and not macs:
        raise utils.NotFoundInCacheError(
            _("Existing node cannot be found since neither MAC addresses "
              "nor BMC addresses are present in the inventory"))

    if ironic is None:
        ironic = ir_utils.get_client()

    node = ir_utils.lookup_node(macs=macs,
                                bmc_addresses=bmc_addresses,
                                ironic=ironic)
    if not node:
        bmc_addresses = ', '.join(bmc_addresses) if bmc_addresses else None
        macs = ', '.join(macs) if macs else None
        raise utils.NotFoundInCacheError(
            _("Existing node was not found by MAC address(es) %(macs)s "
              "and BMC address(es) %(addr)s") % {
                  'macs': macs,
                  'addr': bmc_addresses
              })

    node = ironic.node.get(node, fields=['uuid', 'provision_state'])
    # TODO(dtantsur): do we want to allow updates in all states?
    if node.provision_state not in ir_utils.VALID_ACTIVE_STATES:
        raise utils.Error(
            _("Node %(node)s is not active, its provision "
              "state is %(state)s") % {
                  'node': node.uuid,
                  'state': node.provision_state
              })

    return add_node(node.uuid,
                    istate.States.waiting,
                    manage_boot=False,
                    mac=macs,
                    bmc_address=bmc_addresses)
Exemplo n.º 4
0
 def test_lookup_by_bmc_only(self):
     uuid = ir_utils.lookup_node(
         bmc_addresses=[self.bmc_address, '42.42.42.42'],
         ironic=self.ironic)
     self.assertEqual(self.node.uuid, uuid)
     self.assertEqual(1, self.ironic.nodes.call_count)
Exemplo n.º 5
0
 def test_no_input_no_result(self):
     self.assertIsNone(ir_utils.lookup_node())