Commit Graph

671 Commits

Author SHA1 Message Date
Dmitry Tantsur a9a4fff71c
Fix generating local paths when connecting virtual media
The generate path does not contain the node UUID, causing conflicts.

Also make sure to always clean up any existing files first.

Change-Id: I30f948d64e7b87f33841dc22828db60338a62dd8
2024-04-03 16:16:31 +02:00
Zuul df9e1ba80e Merge "[codespell] Fixing Spelling Mistakes" 2024-03-14 17:13:05 +00:00
Riccardo Pittau ed14b2e04f [trivial] add device_type param to attach_vmedia_device
We missed it.

Change-Id: I4bd8e07f301a298e495e88a2d80f6932290634ba
2024-03-11 15:11:06 +01:00
Zuul 30974ba0da Merge "Fix error handling in the virtual media attach API" 2024-03-08 10:57:19 +00:00
Dmitry Tantsur 79523c5911
Fix error handling in the virtual media attach API
Currently, if the image download fails, there are no traces of the
error. This change adds logging and populates last_error.

Change-Id: I73ea2f94fb910daf21a5d4f52d6839aac3bad579
2024-03-07 18:48:13 +01:00
Zuul bc73982a2a Merge "Split conductor-specific RPCService" 2024-03-06 20:53:55 +00:00
Zuul ae51a14bde Merge "Log upon completion of power sync" 2024-03-05 05:59:51 +00:00
Zuul a7ce0d7ae6 Merge "Add a reserved workers pool (5% by default)" 2024-02-29 07:22:42 +00:00
Dmitry Tantsur a9397f49d5
Split conductor-specific RPCService
The current implementation in common has a lot of assumptions that the
manager is a conductor manager. To be able to reuse the same base RPC
service for the PXE filter, split the conductor part away from the
common one.

Change-Id: I4d24cf82d62cb034840435ef15b5373748b65f09
2024-02-26 18:17:52 +01:00
Julia Kreger 82dbaa9668 Log upon completion of power sync
Previously, we updated node_periodic so we understood from the
logs when a periodic task was completed, so we could understand
where things were at in our hunt for database lock racess.

In any event, we now explicitly log in the _sync_power_state
method of the conductor, because it is not a node_periodic.

Change-Id: Iaec9926fe031e65de4732ff0bc7988c5604d4755
2024-02-13 15:28:42 -08:00
Sharpz7 949387bd80 [codespell] Fixing Spelling Mistakes
This is the first in a series of commits to add support for codespell. This is continuning the process completed in ironic-python-agent.

Future Commits will add a Tox Target, CI support and potentially a git-blame-ignore-revs file if their are lots of spelling mistakes that could clutter git blame.

Change-Id: Id328ff64c352e85b58181e9d9e35973a8706ab7a
2024-02-12 19:58:56 +00:00
Dmitry Tantsur 307c4572a6
Add node auto-discovery support for in-band inspection
This is a MVP of auto-discovery with no extra customization and no new
auto_discovered field from the spec.

Change-Id: I1528096aa08da6af4ac3c45b71d00e86947ed556
2024-02-02 09:24:52 +01:00
Jay Faulkner b0b7ee4254 Do not log lack of metrics support at WARNING lvl
We have some drivers, such as SNMP, which do not support metrics.
Environments with these nodes should not get "N" messages for "N" nodes
that can't generate sensor data.

Closes-bug: 2047709
Change-Id: Ibc1f3feb055521214512c8b350d67933491c2550
2023-12-29 10:59:42 -08:00
Dmitry Tantsur adec0f6f01
Add a reserved workers pool (5% by default)
I've seen a situation where heartbeats managed to completely saturate
the conductor workers, so that no API requests could come through that
required interaction with the conductor (i.e. everything other than
reads). Add periodic tasks for a large (thousands) number of nodes, and
you get a completely locked up Ironic.

This change reserves 5% (configurable) of the threads for API requests.
This is done by splitting one executor into two, of which the latter is
only used by normal _spawn_worker calls and only when the former is
exhausted. This allows an operator to apply a remediation, e.g. abort
some deployments or outright power off some nodes.

Partial-Bug: #2038438
Change-Id: Iacc62d33ffccfc11694167ee2a7bc6aad82c1f2f
2023-12-07 13:47:39 +01:00
Dmitry Tantsur 0902912217 Generic API for attaching/detaching virtual media
This patch allows to attach or detach a generic image as
virtual media device after a node has been provisioned.

Closes-Bug: #2033288
Change-Id: I97b68047d769f6fb686c53e89084b5874e02b8c7
2023-11-23 09:55:09 +01:00
Julia Kreger c84fe147a3 Utilize the JSON-RPC port
Adds storage of the json-rpc port number to the conductor hostname
to enable rpc clients to understand which rpc servies they need to
connect to.

Depends-On: https://review.opendev.org/c/openstack/ironic-lib/+/879211
Change-Id: I6021152c83ab5025a9a9e6d8d24c64278c4c1053
2023-08-30 08:56:17 -07:00
Zuul f7dfc13c94 Merge "Adds service steps" 2023-08-29 02:56:22 +00:00
Julia Kreger 2fd3d8f01e Fail on node lookup if it is locked
In the agent token mechanism, restrictions exist when a an agent
token can be generated, and unfortunately this has to be done on
the conductor side involving a lock and a task because we need to
save the state of the node.

As such, we were in a situation where we were waiting on DB node
locking, which would prevent the agent from getting a node, and
potentially causing the lookup operation to fail, eventually.

We now quickly return NodeLocked which shouldn't cause the agent
any issues, although we need to improve error handling there as
well.

Change-Id: Ice335eed82b936753be99eedb16ceccf8a9a86a8
2023-08-23 13:18:43 -07:00
Julia Kreger 2366a4b86e Adds service steps
A huge list of initial work for service steps

* Adds service_step verb
* Adds service_step db/object/API field on the node object for the
  status.
* Increments the API version to 1.87 for both changes.
* Increments the RPC API version to 1.57.
* Adds initial testing to facilitate ensurance that supplied steps
  are passed through and executed upon.

Does not:

* Have tests for starting the agent ramdisk, although this is
  relatively boiler plate.
* Have a collection of pre-decorated steps available for immediate
  consumption.

Change-Id: I5b9dd928f24dff7877a4ab8dc7b743058cace994
2023-08-16 06:34:08 -07:00
Julia Kreger c4e3100d5c Add hold steps
* Updates API version to 1.85 to permit an ``unhold`` verb
* Adds the ``deploy hold`` and ``clean hold`` provision states
  to the internal state machine.
* Adds on documentation on steps to help provide greater clarity
  to Ironic's users on how to utilize steps. It should be noted
  this documentation also includes the power state reserved step
  names from the DPU functionality patch.
* Fixes the state machine diagram. Changes type to PNG as SVG
  rendering is broken due to python libraries utilized for SVG
  generation which do not work on more recent Python versions.

Change-Id: I34f58f4e77e7757b89247fd64f5fcde26f679453
2023-06-30 14:34:26 -07:00
Dmitry Tantsur 0370f5ac97 Migrate the inspector's /continue API
This change creates all necessary parts to processing inspection data:

* New API /v1/continue_inspection

Depending on the API version, either behaves like the inspector's API
or (new version) adds the lookup functionality on top.

The lookup process is migrated from ironic-inspector with minor changes.
It takes MAC addresses, BMC addresses and (optionally) a node UUID and
tries to find a single node in INSPECTWAIT state that satisfies all
of these. Any failure results in HTTP 404.

To make lookup faster, the resolved BMC addresses are cached in advance.

* New RPC continue_inspection

Essentially, checks the provision state again and delegates to the
inspect interface.

* New inspect interface call continue_inspection

The base version does nothing. Since we don't yet have in-band
inspection in Ironic proper, the only actual implementation is added
to the existing "inspector" interface that works by doing a call
to ironic-inspector.

Story: #2010275
Task: #46208
Change-Id: Ia3f5bb9d1845d6b8fab30232a72b5a360a5a56d2
2023-06-07 10:57:08 +02:00
Julia Kreger 75b881bd31 Fix DB/Lock session handling issues
Prior to this fix, we have been unable to run the Metal3 CI job
with SQLAlchemy's internal autocommit setting enabled. However
that setting is deprecated and needs to be removed.

Investigating our DB queries and request patterns, we were able
to identify some queries which generally resulted in the
underlying task and lock being held longer because the output
was not actually returned, which is something we've generally
had to fix in some places previously. Doing some of these
changes did drastically reduce the number of errors encountered
with the Metal3 CI job, however it did not eliminate them
entirely.

Further investigation, we were able to determine that the underlying
issue we were encountering was when we had an external semi-random
reader, such as Metal3 polling endpoints, we could reach a situation
where we would be blocked from updating the database as to open a
write lock, we need the active readers not to be interacting with
the database, and with a random reader of sorts, the only realistic
option we have is to enable the Write Ahead Log[0]. We didn't have
to do this with SQLAlchemy previously because autocommit behavior
hid the complexities from us, but in order to move to SQLAlchemy
2.0, we do need to remove autocommit.

Additionally, adds two unit tests for get_node_with_token rpc
method, which apparently we missed or lost somewhere along the
way. Also, adds notes to two Database interactions to suggest
we look at them in the future as they may not be the most
efficient path forward.

[0]: https://www.sqlite.org/wal.html

Change-Id: Iebcc15fe202910b942b58fc004d077740ec61912
2023-05-01 15:35:33 -07:00
Dmitry Tantsur 0e7c6f9788 Refactoring: create ironic.conductor.inspection
... to reduce the already frightening size of ironic.conductor.manager
and make space for more inspection additions.

While here, fix up log messages for clarity and brevity.

Change-Id: I5196d58016ae094f17e0aad187a11d9cceaab04b
2023-03-14 15:40:30 +01:00
Zuul a3f854392a Merge "Do not move nodes to CLEAN FAILED with empty last_error" 2023-03-02 14:23:40 +00:00
Dmitry Tantsur 9a0fa631ca Do not move nodes to CLEAN FAILED with empty last_error
When cleaning fails, we power off the node, unless it has been running
a clean step already. This happens when aborting cleaning or on a boot
failure. This change makes sure that the power action does not wipe
the last_error field, resulting in a node with provision_state=CLEANFAIL
and last_error=None for several seconds. I've hit this in Metal3.

Also when aborting cleaning, make sure last_error is set during
the transition to CLEANFAIL, not when the clean up thread starts
running.

While here, make sure to log the current step in all cases, not only
when aborting a non-abortable step.

Change-Id: Id21dd7eb44dad149661ebe2d75a9b030aa70526f
Story: #2010603
Task: #47476
2023-03-01 11:16:46 +01:00
Zuul cf43fa4e3c Merge "Get conductor metric data" 2023-02-27 17:24:15 +00:00
Julia Kreger 82b8ec7a39 Get conductor metric data
This change adds the capability for the ironic-conductor
and standalone service process to transmit timer and counter
metrics to the message bus notifier which may be consumed by
a ceilometer, ironic-prometheus-exporter, or other consumer of
metrics event data on to the message bus.

This functionality is not presently supported on dedicated API
services such as those running as an ``ironic-api`` application
process, or Ironic WSGI application. This is due to the lack of
an internal trigger mechanism to transmit the data in a metrics
update to the message bus and/or notifier plugin.

This change requires ironic-lib 5.4.0 to collect and ship metrics via
the message bus.

Depends-On: https://review.opendev.org/c/openstack/ironic-lib/+/865311
Change-Id: If6941f970241a22d96e06d88365f76edc4683364
2023-02-23 11:39:07 -08:00
Zuul 3707422bf7 Merge "Fixes console port conflict occurs in certain path" 2023-02-20 15:27:21 +00:00
Jakub Jelinek 25718f5fcf Indicate maintenance mode
Follow-up to I74b19f7a42c1326d7ec04e6320176e81639ebfb4
Mention need of the maintenance mode to orphan swift
objects during node clean up

Story: 2010275
Task: 46204
Change-Id: Ie95a5bd333b0dab3e97254dfb4eb532bdbfd2650
2023-02-16 11:15:35 +00:00
Kaifeng Wang c9c9b3100d Fixes console port conflict occurs in certain path
The dynamically allocated console port for a node is saved
into database and reused on subsequent console operations.
In certain code path the port record cann't be trusted and
we should do a re-allocation.

This patch fixes the issue by ignores previous allocation
record. The extra cleanup in the takeover is not required
anymore and removed as well.

Change-Id: I1a07ea9b30a2c760af7a6a4e39f3ff227df28fff
Story: 2010489
Task: 47061
2023-02-15 17:42:37 +00:00
Jakub Jelinek bc921118b1 Erase swift inventory entry on node deletion
Follow-up to Ie174904420691be64ce6ca10bca3231f45a5bc58
which enables storage of inventory in Swift, but does not delete
the Swift entry when the node whose inventory is stored is deleted

Story: 2010275
Task: 46204
Change-Id: I74b19f7a42c1326d7ec04e6320176e81639ebfb4
2023-02-14 10:58:05 +00:00
Julia Kreger 49e085583d Phase 1 - SQLAlchemy 2.0 Compatability
One of the major changes in SQLAlchemy 2.0 is the removal
of autocommit support. It turns out Ironic was using this quite
aggressively without even really being aware of it.

* Moved the declaritive_base to ORM, as noted in the SQLAlchemy 2.0
  changes[0].

* Console testing caused us to become aware of issues around locking
  where session synchronization, when autocommit was enabled, was
  defaulted to False. The result of this is that you could have two
  sessions have different results, which could results on different
  threads, and where one could still attempt to lock based upon prior
  information. Inherently, while this basically worked, it was
  also sort of broken behavior. This resulted in locking being
  rewritten to use the style mandated in SQLAlchemy 2.0 migration
  documentation. This ultimately is due to locking, which is *heavily*
  relied upon in Ironic, and in unit testing with sqlite, there are
  no transactions, which means we can get some data inconsistency
  in unit testing as well if we're reliant upon the database to
  precisely and exactly return what we committed.[1]

* Begins changing the query.one()/query.all() style to use explicit
  select statements as part of the new style mandated for migration
  to SQLAlchemy 2.0.

* Instead of using field label strings for joined queries, use the
  object format, which makes much more sense now, and is part of
  the items required for eventual migration to 2.0.

* DB queries involving Traits are now loaded using SelectInLoad
  as opposed to Joins. The now deprecated ORM queries were quietly
  and silently de-duplicating rows and providing consistent sets
  from the resulting joined table responses, however putting much
  higher CPU load on the processing of results on the client.
  Prior performance testing has informed us this should be a minimal
  overhead impact, however these queries should no longer be in
  transactions with the Database Servers which should offset the
  shift in load pattern. The reason we cannot continue to deduplicate
  locally in our code is because we carry Dict data sets which cannot
  be hashed for deduplication. Most projects have handled this by
  treating them as Text and then converting, but without a massive
  rewrite, this seems to be the viable middle ground.

* Adds an explict mapping for traits and tags on the Node object
  to point directly to the NodeTrait and NodeTag classes. This
  superceeds the prior usage of a backref to make the association.

* Splits SQLAlchemy class model Node into Node and NodeBase, which
  allows for high performance queries to skip querying for ``tags``
  and ``traits``. Otherwise with the afrormentioned lookups would
  always execute as they are now properties as well on the Node
  class. This more common of a SQLAlchemy model, but Ironic's model
  has been a bit more rigid to date.

* Adds a ``start_consoles`` and ``start_allocations`` option to the
  conductor ``init_host`` method. This allows unit tests to be
  executed and launched with the service context, while *not* also
  creating race conditions which resulted in failed tests.

* The db API ``_paginate_query`` wrapper now contains additional
  logic to handle traditional ORM query responses and the newer style
  of unified query responses. Due to differences in queries and handling,
  which also was part of the driver for the creation of ``NodeBase``,
  as SQLAlchemy will only create an object if a base object is referenced.
  Also, by default, everything returned is a tuple in 1.4 with the
  unified interface.

* Also modified one unit test which counted time.sleep calls, which is
  a known pattern which can create failures which are ultimately noise.

Ultimately, I have labelled the remaining places which SQLAlchemy
warnings are raised at for deprecation/removal of functionality,
which needs to be addressed.

[0] https://docs.sqlalchemy.org/en/14/changelog/migration_20.html
[1] https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#transaction-isolation-level-autocommit

Change-Id: Ie0f4b8a814eaef1e852088d12d33ce1eab408e23
2022-10-13 21:21:40 +00:00
Julia Kreger 9a8b1d149c Concurrent Distructive/Intensive ops limits
Provide the ability to limit resource intensive or potentially
wide scale operations which could be a symptom of a highly
distructive and unplanned operation in progress.

The idea behind this change is to help guard the overall deployment
to prevent an overall resource exhaustion situation, or prevent an
attacker with valid credentials from putting an entire deployment
into a potentially disasterous cleaning situation since ironic only
other wise limits concurrency based upon running tasks by conductor.

Story: 2010007
Task: 45140

Change-Id: I642452cd480e7674ff720b65ca32bce59a4a834a
2022-09-20 06:47:38 -07:00
Zuul 0c4401cfbb Merge "Trivial: log which state the node is in" 2022-07-14 01:37:11 +00:00
Julia Kreger e78f123ff8 Make anaconda non-image deploys sane
Ironic has a lot of logic built up around use of images for filesystems,
however several recent additions, such as the ``ramdisk`` and ``anaconda``
deployment interfaces have started to break this mold.

In working with some operators attempting to utilzie the anaconda
deployment interface outside the context of full OpenStack, we discovered
some issues which needed to be make simpler to help remove the need to
route around data validation checks for things that are not required.

Standalong users also have the ability to point to a URL with anaconda,
where as Operators using OpenStack can only do so with customized kickstart
files. While this is okay, the disparity in configuraiton checking
was also creating additional issues.

In this, we discovered we were not really graceful with redirects,
so we're now a little more graceful with them.

Story: 2009939
Story: 2009940
Task: 44834
Task: 44833
Change-Id: I8b0a50751014c6093faa26094d9f99e173dcdd38
2022-07-11 07:41:06 -07:00
Dmitry Tantsur 0f16273886 Trivial: log which state the node is in
Change-Id: I87326585896cae9df717e9d19b2ea441d92d3b1a
2022-07-06 16:51:43 +02:00
Julia Kreger c3f397149a Auto-populate lessee for deployments
Adds a configuration option and capability to automatically
record the lessee for a deployment based upon the original
auth_token information provided in the request context.

Additional token information is now shared through the context
which is extended in the same fashion as most other projects
saving request token information to their RequestContext,
instead of triggering excess API calls in the background to
Keystone to try and figure out requestor's information.

Change-Id: I42a2ceb9d2e7dfdc575eb37ed773a1bc682cec23
2022-05-23 16:21:19 -07:00
Harald Jensås 4cf0147e86 Exclude current conductor from offline_conductors
In some cases the current conductor may have failed to updated
the heartbeat timestamp due to failure of resource starvation.
When this occurs the dbapi get_offline_conductors method will
include the current conductor in its return value.

In this scenario the conductor may end up forcefully remove
node reservations or allocations from itself, triggering takeover
which fail on-going operations.

This change adds a wrapper to exclude the current conductor.
The wrapper will log a warning to raise the issue.

Related-Bug: #1970484
Stroy: 2010016
Task: 45204
Change-Id: I6a8f38934b475f792433be6f0882540b82ca26c1
2022-04-28 10:28:26 +02:00
Zuul 81f17f8a35 Merge "Shorten error messages in commonly used modules" 2022-03-11 07:41:34 +00:00
Zuul e3221673ee Merge "Ignore fake nodes in the power sync loop" 2022-03-09 15:50:41 +00:00
Dmitry Tantsur daa7dba331 Shorten error messages in commonly used modules
* Do not mention "deploy driver", it's not a thing.
* Be careful with the pattern "Error: %s" or "Reason: %s". It is good
  for long introductory sentences, but looks poor for shorter ones and
  becomes really problematic when several instances are concatenated.

This change updates deploy_utils, agent code and conductor modules.

Change-Id: Ie1efea02b5f1a174e9ef8c5253ce9754a60b4c56
2022-02-17 19:16:52 +01:00
Dmitry Tantsur a813c769e8 Explicit parameter to distinguish partition/whole-disk images
Using kernel/ramdisk makes no sense with local boot, we need a better
way. We already have an internal image_type instance parameter, let's
make it public.

Glance support will be added in the next patch.

Change-Id: I4ce5f7a2317d952f976194d2022328f4afbb0258
2022-01-28 19:13:13 +01:00
Dmitry Tantsur d342b07dd6 Adoption: do not validate boot interface when local booting
We validate the boot interface during adoption because of:
a) potential rebuilding,
b) non-local boot.

Rebuild proved a rarely used feature, and local boot is the default
nowadays, so it makes less sense to unconditionally validate the boot
interface during adoption. We will run the validation anyway the next
time we need to do something with booting.

Similarly, do not record is_whole_disk_image None if it cannot be
reliably determined.

Change-Id: I95252aea808c48ea2d94569449c871f0d483caaa
2021-12-13 10:25:27 +01:00
Dmitry Tantsur d0f61e9493 Ignore fake nodes in the power sync loop
Fake nodes have power_state None and the power interface returns None as
well. Currently we make an update every loop, even though the values are
the same. This change fixes it.

Change-Id: I5227c058f3f6e1583b54a1cbc7edc6d42e20ae53
2021-12-09 14:57:51 +01:00
Zuul c4d2f4b8c6 Merge "All-in-one Ironic service with a local RPC bus" 2021-12-08 16:35:54 +00:00
Zuul c0fc88b728 Merge "Refactor driver_internal_info updates to methods" 2021-12-07 20:42:50 +00:00
Dmitry Tantsur 9a6f2d101b All-in-one Ironic service with a local RPC bus
This adds a new executable /usr/bin/ironic (cool that we no longer have
a CLI with this name) that starts API and conductor together in the same
process. When an RPC host name matches the current one, the call is not
routed through the remote RPC, a local function call is done instead.

Story: #2009676
Task: #43953
Change-Id: I51bf7226aea145dc7c8fd93d61caa233ca16c9c9
2021-12-07 09:31:12 +01:00
Dmitry Tantsur 18d016f796 Avoid RPC notify_conductor_resume_{deploy,clean} in agent_base
Currently we use an RPC call to the conductor itself to proceed to the
next clean or deploy step. This is unnecessary and requires temporary
lifting the lock, potentially causing race conditions.

This change makes the agent code use continue_node_{deploy,clean}
directly. The drivers still need updating, it will be done later.

Story: #2008167
Task: #40922
Change-Id: If4763d542029b9021432425532f24a0228f04c25
2021-12-06 12:38:04 +01:00
Steve Baker d5eb6ee567 Refactor driver_internal_info updates to methods
Making updates to driver_internal_info can result in hard to read code
due the requirement to assign the whole driver_internal_info back to
the node to trigger the expected update operation. This change
replaces driver_internal_info update operations with a new
methods:
- set_driver_internal_info
- del_driver_internal_info
- timestamp_driver_internal_info

This change defines the functions and moves core conductor logic to
use them. Subsequent changes in this series will move drivers to use
the new functions.

Change-Id: Ib8917c3c674e77cd3aba6a1e73c65162e3ee1141
2021-12-03 14:49:33 +13:00
Arne Wiebalck 323344e07c [Trivial] Clarify conditions under which power recovery is attempted
Be more precise when describing the conditions for automatic
recovery from power failures ('maintenance type' is a term
we use nowhere else).

Change-Id: Iaf14c0fc73f8c97b9d8669485011966a650c21a8
2021-11-04 17:57:59 +01:00