Commit Graph

57 Commits

Author SHA1 Message Date
Takashi Kajinami ea9ad2891c Remove dependency on pytz
pytz will be removed from RHEL/CentOS 10 because of the built-in
zoneinfo[1].

Because the current usage of pytz can be very easily replaced, this
removes the dependency on pytz.

[1] https://issues.redhat.com/browse/RHEL-219

Change-Id: Iafcaf2f1095cd7c738dac391a9af10622806e932
2024-01-27 10:42:39 +00:00
Anton Arefiev 3fe42b53fd SQLAlchemy 2.0 Support
Primarily remove the workaround added in
Ia6d512ff2ae417bab938cb095fbb0884d195010a which added
continued use of autocommit, which is incompatible with
SQLAlchemy 2.0.

Also set the environment for unit tests to report compatability
warnings, although it appears none are being reported at this time.

Also cuts out the db upgrade cruft to only use the online database
migration code through oslo_db's enginefacade, which has the smarts
to handle online or offline migrations.

And then, retools unit/functional test data storage to utlize sqlite,
and in that re-tooled the queries to prevent locking conditions
which could exist with queries, and some additional refactoring/cleanup.

Also, don't mock and test time.sleep().

Additionally, it looks like we have discovered the root cause of the
memory/connection leakage issue which has been observed, due to the
way lists of nodes are processed/returned.

This change was based upon the work in
I506da42a9891a245831f325e34bec92e0a3f33f0 which is included in
this commit as the entire database structure and interaction
has been modified for ironic-inspector.

Co-Authored-By: aarefiev <aarefiev@mirantis.com>
Story: 2009727
Task: 44132
Change-Id: Ic88eb9dec5fddc924a72d9a23c17a304954ebf46
2022-12-15 09:28:55 -08:00
Takashi Kajinami d7400b5dc4 Add optional healthcheck middleware
This change allows uses to enable the healthcheck middleware from
oslo.middleware in API pipeline, by setting the [healthcheck]/enabled
option. This middleware provides an API endpoint at /healthcheck path
which allows load balancers or monitoring applications to determine
a service is up using HTTP requests.

This change basically follows the same change merged in ironic[1] repo.

[1] 6f439414bdcef9fc02f844f475ec798d48d42558

Change-Id: Ic2ee2bca74ea2a5a0723ef54b10c531f77ea7b8d
2021-09-12 22:51:38 +09:00
Pavlo Shchelokovskyy 5c79d7552a Fix node id vs uuid in processing_logger_prefix
this is a follow-up to Icd3de82877c6a53d32b4c9fd3e500d3cd9d7fb17

one more place was identified as trying to use uuid attr of a Node
object from openstacksdk instead of id attr.

In tests, use stricter mocking with spec_set (that actually fails to
access or set an atribute of a mock that is absent from the spec class
or instance) to guard against future possible changes.

Change-Id: I83c420d0e91e00f583a28833f4f710cf70b01fa8
Story: 2008379
Task: 41300
2021-02-17 18:40:58 +02:00
Steve Baker 92c64226f4 Add public api support to basic auth
This change implements an alternative middleware which supports the
same deferred auth mechanism as the keystone auth middleware.

When auth fails the header X-Identity-Status is set to Invalid, which
only becomes an Unauthorized response when the path is not public.

Without this change, the paths /, /v1 and /v1/continue
incorrectly require authentication when using basic auth.

Change-Id: I780151870f851ad5dcd45610aacedcca23607a71
Story: 2007656
Task: 39826
2020-07-23 10:53:11 +12:00
Steve Baker 196c019771 Enable Basic HTTP authentication middleware.
When the config option ``auth_strategy`` is set to ``http_basic`` then
non-public API calls require a valid HTTP Basic authentication header to be
set. The config option ``http_basic_auth_user_file`` defaults to
``/etc/ironic-inspector/htpasswd`` and points to a file which supports the
Apache htpasswd syntax[1]. This file is read for every request, so no
service restart is required when changes are made.

The only password digest supported is bcrypt, and the ``bcrypt``
python library is used for password checks since it supports ``$2y$``
prefixed bcrypt passwords as generated by the Apache htpasswd utility.

To try basic authentication, the following can be done:

* Set ``/etc/ironic-inspector/inspector.conf`` ``DEFAULT`` ``auth_strategy``
  to ``http_basic``
* Populate the htpasswd file with entries, for example:
  ``htpasswd -nbB myName myPassword >> /etc/ironic-inspector/htpasswd``
* Make basic authenticated HTTP requests, for example:
  ``curl --user myName:myPassword http://localhost:6385/v1/introspection``

[1] https://httpd.apache.org/docs/current/misc/password_encryptions.html

Change-Id: If50dfbfc18445ad9fe27e17cb0ee1b317ff25a0b
Depends-On: https://review.opendev.org/729070
Story: 2007656
Task: 39826
2020-06-05 01:28:40 +12:00
Riccardo Pittau 4eefb42550 Finalize ironicclient removal
Completely remove dependency from ironicclient in favor of
openstacksdk.

Change-Id: I9b98ddb05fe867a0d3884f736a2edd7b4d61b00c
2020-03-25 10:08:38 +01:00
Kaifeng Wang 293b0c7c15 Split API and conductor services
This patch splits API and conductor services for ironic-inspector.
Previous patch utilized lock from tooz coordinator, this patch adds
a coordinator wrapper for easier usage and further introduces group
interfaces.

Each conductor service will join a predefined group to mark it's
availability, on each request, API service will query members from
the group and randomly choose on of them, create desiginated topic
and deliver request to it.

The feature is tested with the memcached, file backend of tooz.
Other backends are not fully tested but may work as well, please
refer to tooz documentation for driver compatibilities[1].

[1] https://docs.openstack.org/tooz/latest/user/compatibility.html

Story: 2001842
Task: 30376

Change-Id: I419176cd6d44d74c066db275ef008fe8bb6ef37a
2019-08-12 15:29:55 +08:00
Kaifeng Wang 1bed475409 Adds tooz locking driver
Adds tooz requirements, configuration options and locking support.

Story: 2001842
Task: 30376

Change-Id: I78ffdeeb502cbed0550152b19efbb224f47c65af
2019-08-02 09:58:10 +08:00
Zuul 3e702f65db Merge "Use bmc ipv6 address while processing introspection data" 2019-07-03 20:01:29 +00:00
Nikolay Fedotov fcb0ca8a6e Use bmc ipv6 address while processing introspection data
Change-Id: Id6d56860a4e47f28c875ed6032e1f99a997aea9b
Story: #2005779
Task: #33503
2019-06-19 15:03:07 +03:00
Dmitry Tantsur 463d0a2f54 Stop failing on missing memory or CPU
They have been optional for scheduling since Pike and are not used
by Nova at all since Stein.

Change-Id: Idd4d727d3bbcbb8898a0d989d3c496070bc41d8a
2019-06-14 10:10:02 +02:00
space d278bb6f77 introspection data backend: plugin layer
Configurable introspection data storage backend [1] is proposed
to provide flexible extension of introspection data storage
instead of the single support of Swift storage backend.

This patch adds plugin mechanism for loading introspection
storage, creates database backend and moves Swift storage
into a plugin.

[1] http://specs.openstack.org/openstack/ironic-inspector-specs/specs/configurable-introspection-data-backends.html

Story: 1726713
Task: 11373

Co-Authored-By: Kaifeng Wang <kaifeng.w@gmail.com>
Change-Id: Ie4d09dc0afc441b20a1e5e3bd8e742b1df918954
2019-01-07 17:31:15 +08:00
Kaifeng Wang a8c1d06bd0 introspection data backend: implements db
Configurable introspection data storage backend [1] is
proposed to provide flexible extension of introspection
data storage instead of the single support of Swift storage
backend.

This patch adds database support for using ironic-inspector
database as the storage backend.

A table named ``introspection_data`` is created to serve as
the storage for introspected data.

[1] http://specs.openstack.org/openstack/ironic-inspector-specs/specs/configurable-introspection-data-backends.html

Change-Id: I8b29b7b86d90823d29b921ebf64acddbcd2d8d0d
Story: 1726713
Task: 11373
2018-12-04 10:54:32 +08:00
chenxiangui 2cfbde1fc5 Remove unused import
Remove unused import in utils.py

Change-Id: If8c8207c8687525ece1aff14a50057a40c49e5bb
2018-06-12 15:14:23 +08:00
Pavlo Shchelokovskyy 198ef70c2b Add request context and policy enforcement
this patch introduces an oslo.policy-based API access policy
enforcement engine to ironic-inspector.
As part of implementation, a proper oslo.context-based request
context is also generated and assigned to each request.

Short overview of changes:

- added custom RequestContext class

  - extends oslo.context to handle of "is_public_api" flag
    (False by default)

- added context to request in each API route

  - '/continue' api sets the "is_public_api" flag to True

- added documented definitions for API access policies and their
  defaults
- added enforcement of these policies on API requests
- added oslo.policy-specific entry points to setup.cfg
- added autogenerated policy sample file with defaults
- added documentation with autogenerated policies

Change-Id: Iff6f98fa9950d78608f0a7c325d132c11a1383b3
Closes-Bug: #1719812
2017-10-13 11:55:52 +00:00
Jenkins e4b14f1a76 Merge "Treat 0.0.0.0 and '' as missing BMC address" 2017-08-10 16:51:42 +00:00
Dmitry Tantsur 2a4c9d800f Treat 0.0.0.0 and '' as missing BMC address
It became apparent in https://review.openstack.org/#/c/480679/ that these are
correct values for ipmitool to return.

Change-Id: Ied18a81dc899d8fc5290a2756f412e5075e923c4
2017-08-10 10:33:58 +02:00
Anton Arefiev 8fd9f73a9c Clean up deprecated config options
Remove deprecated in ocata options: `introspection_delay_drivers`
and `log_bmc_address`.

Change-Id: I52a7c48609af558cd641d544910be8bce13968a5
2017-08-09 11:38:29 +03:00
Annie Lezil c06a9a7f24 Remove translation of log messages Part-1
The i18n team has decided not to translate the logs because it seems
like it not very useful.

This are the files as of now do not have merge conflicts.

Change-Id: I082f6302f120a8c0c81482b73be301e83fe3a3a8
Partial-Bug: #1674374
2017-03-24 21:45:04 +00:00
Jenkins 0b634ed5b3 Merge "Clean up deprecated configuration options" 2017-02-01 12:00:20 +00:00
Dmitry Tantsur 73584d27bb Clean up deprecated configuration options
Mostly removes old authentication options and support for [discoverd].

Also update example.conf to the latest version.

Change-Id: Ided8705c4345a1170c211d926d916cec2173ccb9
2017-01-27 10:22:55 +01:00
Dmitry Tantsur 6e2ea6242d Allow diskless nodes introspection
There is a demand to use introspection on diskless nodes to figure out
what is possible to figure out.

We might need more changes to properly support diskless nodes, this
change is just to allow people to play with it.

The property ``local_gb == 0`` for a diskless node.

Change-Id: I21b2f2c069fdbf767367ec3d1fbf77bab6292b25
Partial-Bug: #1554243
2017-01-26 17:08:56 +01:00
dparalen 3ddc0615e5 Introducing node introspection state management
Currently, state of a node introspection isn't kept in the database.
This change introduces:

* a new database column to keep the node introspection state
* an automaton to manage the node introspection state
* a decorator to declare a function performing an introspection state
  transition
* a version_id column is added, to enhance database consistency, that
  is consulted whenever node_info is committed

This change is part of the HA_Inspector effort[1]

[1] https://specs.openstack.org/openstack/ironic-inspector-specs/specs/HA_inspector.html

Closes-Bug: #1618835
Partial-Bug: #1525218
Change-Id: I18cb45f0d1194414715ccbe826d8a95610ec718d
2016-12-15 00:20:27 +01:00
Luong Anh Tuan 185effbb18 Use function is_valid_mac from oslo.utils
Oslo.utils 3.17 provides same function, just use it.

Change-Id: I16e3775a239b017c3431c425d86085380e28da4c
2016-11-22 12:59:53 +00:00
dparalen 3b15527580 UUID, started_at, finished_at in the status API
Enhance the introspection status with the fields:

* uuid
* started_at
* finished_at

Change-Id: I36caa7d954a9bfb029d3f849fdf5e73f06f3da74
Partial-Bug: #1525238
2016-10-21 00:25:38 +02:00
Dmitry Tantsur 0b58e31e3e Remove support for the old bash ramdisk
From now on only rely on the IPA inventory and 2 additional fields:
boot_interface and root_device.

Also updated unit tests to use one inventory example.
Also removed duplicating unit tests and checks in test_process.
Also removed devstack support for the old ramdisk.

Change-Id: Ib382328295fc2c1b9143171b1047304febadcaca
2016-06-06 13:36:05 +02:00
Dmitry Tantsur b638c70f82 Use all valid MAC's for lookup
Currently we are using only the resulting MAC(s) when doing a node lookup.
In many cases it is the MAC of the PXE-booting NIC. However, it's not necessary
the MAC that people used for enrolling the Ironic node, which will lead to
lookup failures on the virtual environment. This change makes the lookup
procedure use all of the valid MAC's.

Similarly, the enroll node_not_found_hook now checks all MAC's before creating
a node.

Code in the validate_interfaces hook was reordered to ensure we only keep
interfaces with valid MAC's even in the "all_interfaces" list.

Change-Id: Ie7df05d9a7855716fb835c90cfb0ac7fc4cd66df
2016-03-18 13:41:04 +01:00
Jiri Tomasek 19fe16fd42 Added CORS support to Ironic Inspector
This adds the CORS support middleware to Ironic Inspector, allowing a deployer
to optionally configure rules under which a javascript client may
break the single-origin policy and access the API directly.

OpenStack CrossProject Spec:
   http://specs.openstack.org/openstack/openstack-specs/specs/cors-support.html
Oslo_Middleware Docs:
   http://docs.openstack.org/developer/oslo.middleware/cors.html
OpenStack Cloud Admin Guide:
   http://docs.openstack.org/admin-guide-cloud/cross_project_cors.html
DocImpact: Add link to CORS configuration in admin cloud guide.

Change-Id: I467d4e14b27f1d4808786d431aff66808c707a99
2016-03-14 15:29:09 +01:00
Jenkins aea60cdc4a Merge "Allow specify log level for Error exception" 2016-03-10 12:05:37 +00:00
Anton Arefiev dab42173c0 Allow specify log level for Error exception
For now, all Error exceptions logged with error level, but some exceptions
may be expected as correct flow and they shouldn't be logged as errors.

NotFoundInCacheError, for example, is raised when there isn't info in cache
about introspected node, this case may be handled by not_found_hook, so
this wouldn't be error anymore.

Change-Id: Ie537ccaef0035b2ef839c34fad0a5e6c9ba8f064
2016-03-10 11:58:40 +02:00
Dmitry Tantsur 5b02024cca Use futurist library for asynchronous tasks
A green thread is now used instead of spawn_n for running asynchronous
operations during introspection, processing and aborting.
The existing periodic tasks are now run using Futurist PeriodicWorker.

Main shut down procedure was split into a separate function for convenience.
Also updated the example.conf to the latest versions (some pending updates from
3rdparty libraries included).

Change-Id: Id0efa31aee68a80ec55e4136c53189484b452559
2016-03-02 15:40:01 +01:00
Dmitry Tantsur 0f8b5de248 Split ironic-related functions from utils to separate common.ironic module
Change-Id: I56c1a5eececb555c14847aecfc153ed40e680863
2016-03-01 16:11:11 +01:00
Anton Arefiev 5086d93b41 Add enroll_node_not_found hook
Add new node_not_found_hook - enroll_node_not_found hook,
which allows to enroll unknown nodes to Ironic automatically.

Change-Id: If1528688504e4be4b2369b985bc576544d96868d
Related-Bug: #1524753
2016-03-01 14:00:31 +02:00
Jenkins ade97c9700 Merge "Enable Keystone v3 endpoints for Inspector" 2016-02-03 12:01:43 +00:00
Sam Betts 40c17e30fc Enable Keystone v3 endpoints for Inspector
Change-Id: Iaa6d1b9dcca401987ac5f8ccc37e337736905b92
Closes-Bug: #1531236
2016-02-02 16:11:27 +00:00
dparalen c365e5403c Stringify node_info.uuid as a precaution
Currently, utils:processing_logger_prefix() assumes node_info.uuid to be a
string.  However, a (broken) test case could encounter a TypeError logging:

   File "ironic_inspector/utils.py", line 103, in processing_logger_prefix
     return _('[node: %s]') % ' '.join(parts)
 TypeError: sequence item 0: expected string, MagicMock found

The patch purpose is to apply str(node_info.uuid) as a precaution.  This may
also help track where the real issue is with a broken test case.

Change-Id: I689f67c44a6304f7b296829fef3339872a4f6d36
2016-01-21 15:34:40 +01:00
Dmitry Tantsur 0423d93736 Track node identification during the whole processing
Currently our logging in processing is very inconsistent:
some log strings mention node UUID, some - node BMC IP, some nothing.
This change introduces a common prefix for all processing logs
based on as much information as possible.
Only code that actually have some context about the node (either
NodeInfo or introspection data) is updated.

Also logging BMC addresses can be disabled now.

Updates example.conf (a lot of updated comments from oslo).

Change-Id: Ib20f2acdc60bfaceed7a33467557b92857c32798
2016-01-13 12:23:15 +01:00
Dmitry Tantsur 966647548a Drop support for introspecting nodes in maintenance mode
Deprecated since liberty. We used to need it because ironic didn't have
'manageable' and 'enroll' states when ironic-inspector was started.

Change-Id: Ia38c40806836820219e86fe277ffd0b2fbd9ec58
Closes-Bug: #1506347
2015-12-15 14:25:27 +01:00
Zhenguo Niu bcd8d5dfa0 Replace deprecated LOG.warn with LOG.warning
Closes-Bug: #1508442
Change-Id: Ifcc2004f3274808d868c9947ed2b0b484f815daa
2015-10-22 06:18:47 +00:00
Jenkins 178326c62d Merge "Add missing plugins for introspection rules" 2015-09-23 10:51:36 +00:00
Dmitry Tantsur 6c686e81ce Add missing plugins for introspection rules
Conditions:
* in-net: checks if address is in a network

Actions:
* set-capability: sets a capability
* extend-attribute: append value to a list attibute

Helper method NodeInfo.replace_field is added to simplify writing
similar action plugins.

Implements: blueprint rules
Change-Id: I7e47b3500624df1f2cb15445d05e1c9bca6dc9ae
2015-09-18 17:42:42 +02:00
Sam Betts 6d06f09e89 Ignore IPMI Address for IPMI Bridged nodes
When a node is behind an IPMI bridge the IPMI address stored in ironic
is not a trust worthy identifier for recognising a node returning its
introspection data, as it can be the same or multiple nodes. It will
also cause unique constraint errors as the database will not allow
multiple bmc_address attribute entries with the same value. This patch
adds detection for ipmi bridging to the get_ipmi_address function, so
if ipmi bridging is enabled then it returns None, and the node is added
without any bmc_address listed.

Change-Id: I09d17dffcde0f4a023bb03e1bce88bcf725cdf0a
Closes-Bug: #1488501
2015-09-17 14:54:27 +01:00
Dmitry Tantsur 676a581411 Revisit required provision states
* Recommend using ENROLL for setting IPMI credentials
* Deprecate using maintenance mode, will be dropped once we stop
  supporting Ironic Kilo
* Drop bits related to Ironic Juno, we no longer support it
* Clarify error message about wrong provision state, stop mentioning
  maintenance mode there

Change-Id: I3a9d3ba24a32c7844cd6fd5e4f8ec4b15b2d9d20
Closes-Bug: #1479331
2015-09-07 19:12:11 +02:00
Dmitry Tantsur 5831723eb6 Make list of ipmi_address-alike driver fields configurable
Add cimc_address approved as part of
http://specs.openstack.org/openstack/ironic-specs/specs/approved/cisco-imc-pxe-driver.html

Change-Id: Id16e0e253eb21def26a089063a528308262d5a01
Closes-Bug: #1488525
2015-09-01 09:25:11 +02:00
Yuiko Takada 6ce87e8f42 Migrate to oslo_log
Use oslo_log instead of logging module.

Change-Id: I0e9c9b9b68ba9c8c4f1c0cdd0746991c53e2d7e5
Closes-bug: #1475690
2015-08-12 09:23:18 +09:00
Dmitry Tantsur 28eeb58faf Use retries provided by ironicclient instead of ad-hoc ones
Change-Id: Iaa8ed03629814c75cb9f5a7ab1ccf9e254dddee1
Closes-Bug: #1469687
2015-07-31 12:41:39 +02:00
Dmitry Tantsur 6f8342955e Require ironic API version 1.6
This is Kilo, so make it clear in README that we actually still
support it (only stand alone case).

Change-Id: I9a5bd97a2a33a12311626bb3fae878bfb5c9d53c
2015-07-29 14:23:42 +02:00
Yuiko Takada 9c44b89967 Load authenticate token from HTTP header
In this patch set, loading authenticate token from HTTP header
and pass it to ironicclient.

Change-Id: Ib12f6b5e88b32b6d580241229bd9c195979687da
2015-07-24 12:06:26 +09:00
Yuiko Takada 43f3a71588 Make endpoint type configurable
Currently, Ironic Inspector talks with Ironic using public API endpoint.
This patch fix this by making endpoint type configurable and also
make default value "internalURL".

Change-Id: I11f8016a69fabe450989174b846cf84eacf83652
Partial-Bug: #1470565
2015-07-21 22:24:30 -04:00