Commit Graph

50 Commits

Author SHA1 Message Date
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
Dmitry Tantsur cee5922674 Hacking: enforce usage of autospec=True in tests
Using autospec ensures that mocked functions are called with correct
arguments, so it's highly desired to have it.

Change-Id: I9c8395adf852495d2ef6db732d727990e8abd5d7
2020-04-28 12:27:41 +02:00
Harald Jensås 079b458db0 Use autospec=True in mocks
This is a follow up to comments on https://review.opendev.org/720010.
Adding autospect=True requires an update to ironic_inspector.test.\
base.BaseTest.assertCalledWithPatch.

Also add autospec=True in several mocks where it was not used.

Change-Id: Ia340d7a8ecde1c8cf191555de87b11b19b30f06c
2020-04-22 14:10:53 +02:00
Sean McGinnis a9f7f67de5
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Ic67f09a223ae2d0cb460771a10a4122307afa05b
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 16:15:28 -05:00
Riccardo Pittau 3accdfbbc6 Use openstacksdk for ironic module
This patches removes the ironic-client dependency from the
ironic module in favor of openstacksdk.

Increase minimum required version of openstacksdk to use
recent added features.

Change-Id: I31964179835ad454e8205a59f483b419de4fb62d
2020-03-23 14:28:09 +01:00
Riccardo Pittau 9b1450398c Stop using six library
Since we've dropped support for Python 2.7, it's time to look at
the bright future that Python 3.x will bring and stop forcing
compatibility with older versions.
This patch removes the six library from requirements, not
looking back.

Change-Id: Ic443c7e4d5a5a849c4dc220207f8957e4c90bf53
2019-12-17 09:23:01 +01:00
Dmitry Tantsur 85267e881c Stop trying to power off nodes if manage_boot is False
When manage_boot is False, we do not power on the machines on starting
introspection, nor do we power them off on aborting. We should not
power off on finishing introspection either, let's leave it up to ironic.

Change-Id: If8115f8d592e1b24b07ef52bcd703d10763c1f00
Story: #1528920
2019-10-18 13:53:17 +02:00
Julia Kreger 0c9447d53b Active node introspection for nodes not in cache
When an active node introspection is performed
where an entry already exists in ironic, but inspector
has never seen the node before, we enter a state where
we should allow introspection to occur, but that we don't
have a cache record.

As a result of no cache entry, we presently fail hard claiming
the node's port already exists. In the case of active nodes,
This will always be the case, so we need to add a cache
entry and allow the process to... somewhat continue as if
normal introspeciton is occuring.

Co-Authored-By: Dmitry Tantsur <dtantsur@redhat.com>
Change-Id: Ib20b4a4e4d46ba23b8a4d87791cf30a957f1f9f9
Story: 2006233
Task: 35834
2019-07-19 17:08:56 +02:00
Kaifeng Wang 1f0be4a6a8 Adds an abstract locking layer
Adds a base lock class and encapsulates current semaphore based lock
into a subclass.

Change-Id: I26eb658ce6fb219bac6df1c2407a8179499358be
2019-07-09 09:14:51 +08:00
Julia Kreger 46a90d6dad Enable processing of active nodes
Change-Id: Ie369251bb11f36006c3921b3b40800288b49bbc2
Story: 2005896
Task: 33755
2019-07-03 20:10:12 +00: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
Zuul fe8f909619 Merge "Simplify locking code" 2019-06-14 17:26:43 +00:00
Kaifeng Wang d57179411d Simplify locking code
NodeInfo accepts a lock instance when instantiated, it is only used
in the node clean up periodic task, such implementation introduces
complexity on the lock abstraction. This patch moves node locking
out of get_node.

_get_lock_ctx is removed for it only duplicates _get_lock according to
current usage.

Change-Id: I4e946942ce684b27062d1a42c68faf1d92569489
2019-06-10 10:10:10 +08:00
Zuul 9819bf3012 Merge "Remove deprecated store_data_location" 2019-05-24 13:44:21 +00:00
Kaifeng Wang 29d8515f50 Support reapply with supplied introspection data
This patch adds support to provide unprocessed introspection data
to reapply a node. The provided introspection data will be save to
current introspection storage backend.

Change-Id: I969ae9c32f53f89c006a64a006388ddea9542aa5
Story: 1564863
Task: 11344
2019-04-15 15:04:33 +00:00
Kaifeng Wang 0e11af26b5 Remove deprecated store_data_location
The deprecated configuration option [processing]store_data_location was
removed.

Change-Id: I3f66af7fe67284e0b391188bef7d949cec8feb40
2019-04-09 08:45:04 +08:00
Dmitry Tantsur 4ca182bf04 Reset cached extension managers in the unit tests
We haven't been doing it consistently, let's do it in the base test.

Change-Id: I5b48a7147c32313a9678e54ab8896e9f301f1c04
2019-03-08 13:18:02 +01:00
Kaifeng Wang 9f8f3fc08d Introspection data storage backend follow up
An issue is spotted during implementing [1], we have a solely code
path from api, do_reapply, reapply, to _reapply. Inspector now reads
intrspection data ahead, so there is no need to do so in _reapply,
reading introspection data there is never reached.

The patch removes unecessary code and corresponding tests.

[1] https://storyboard.openstack.org/#!/story/1564863

Change-Id: I5558bce2bc49de3d1c5dba59e203de4824a3addd
Story: 1726713
Task: 11373
2019-01-24 17:33:00 +08: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 269d92b19c Fix lock leaks in unit tests
Following message was seen during unit tests:
"BUG: node lock was not released by the moment node info object is deleted."

Though the bug was marked invalid before, apparently it had never been resolved.
Tests involved in this patch were located by saving stack at NodeInfo.__init__ and
printing out at NodeInfo.__del__, without promises, but hopefully covers all tests
in current repo.

Change-Id: I678407b350bd07926eb98db30f24cc83747fa84c
Story: #1533595
Task: #11296
2018-08-06 19:32:15 +08:00
Kaifeng Wang 0c159b021e test_failure_to_write fails with root user
The test test_failure_to_write will fail with root.

This patch add a mock to prevent path creation, makes the test
fits for root and non-root user.

Change-Id: I7e55c4070c41927f05c2cfdd284c8d542f1d8906
Closes-Bug: #1693129
2018-03-20 16:09:50 +08:00
John L. Villalovos 15d5958e17 Replace use of functools.wraps() with six.wraps()
In Python 2.7, functools.wraps() does not provide the '__wrapped__'
attribute. This attribute is used by
oslo_utils.reflection.get_signature() when getting the signature of a
function. If a function is decorated without the '__wrapped__'
attribute then the signature will be of the decorator rather than the
underlying function.

From the six documentation for six.wraps():
    This is exactly the functools.wraps() decorator, but it sets the
    __wrapped__ attribute on what it decorates as functools.wraps()
    does on Python versions after 3.2.

Change-Id: I11bf2fa945d36bfbc89ec8239e7c9259e3e12496
2018-02-01 16:32:48 -08:00
dparalen 7e72ceffd1 Terminal state transitions in transactions
Multiple spots were not using DB transactions when processing the terminal
state transitions (error, abort, finish, timeout). The pattern looked like
this:

    node_info.fsm_event(istate.Events.error)
    # more code
    node_info.finished(error='Oops!')

which led to brief periodes of state inconsistency of NodeInfo records in
the DB.

This patch refactors the NodeInfo.finished() method to require a terminal state
transition to perform as part of the NodeInfo state update:

   NodeInfo().finished(istate.Events.finish)
   NodeInfo().finished(istate.Events.abort, 'Canceled by operator')

This patch also introduces a new state: aborting to allow the inspector to
try call power-off the node before marking the introspection aborted.

There's a new DB migration since the new state implies a schema change too
(Enum).

Closes-Bug: #1721233
Closes-Bug: #1721230
Closes-Bug: #1723384

Change-Id: I0bb051d1956a996ed006d55a5ca2d670d9455047
2017-12-19 18:15:31 +01:00
dparalen 7b27585463 Refactoring the firewall
Adopting the PXE filter interface/driver concept

Related-Bug: 1665666
Change-Id: If83db978080b9c4e5d51ba50bbe8ed26e29abe83
2017-10-19 16:38:15 +02:00
Dmitry Tantsur a1d19d97b5 Do not rely on the older ipmi_address field on lookup
We need to always use bmc_address from inventory, the ipmi_address field is
there only for compatibility with older processing hooks.

Change-Id: Ibf00ecd9278af4ee9318ada44c7c670d13ac22aa
Closes-Bug: #1714944
2017-09-04 14:43:13 +02: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
Dmitry Tantsur e05257035c Completely remove support for setting IPMI credentials
This experimental feature was deprecated in the Ocata release,
as it was found unstable, untested and dangerous.

API version is bumped to 1.12 to indicate this change to users.

Change-Id: I1aad6ddfd03946edc19ae510accd6c8daf5fc268
Closes-Bug: #1654318
2017-05-26 14:29:13 +02:00
Dmitry Tantsur 782ee92c45 Set pxe_enabled on new and existing ports on introspection
Set it to True for the PXE-booting port, to False for all the others.
Create an extended functional tests covering various operations with ports.

Change-Id: I435a5c04884b6c4da70cb7260b305fbde23eebc0
Closes-Bug: #1667472
2017-04-18 10:20:49 +00:00
Annie Lezil 43c89efcb7 Reapply doesn't update started_at time
The reapply API/Action(openstack baremetal introspection reprocess UUID)
doesn't update the started_at time when Ironic Inspector begins processing
the node.

This adds the started_at time when the reapply API/Action is performed.

Change-Id: Ic79db4ba9305841fb662afcb56f556ad4a57a500
Closes-Bug: #1625180
2017-03-07 21:28:13 +00:00
Moshe Levi 1dce3b12d3 Adding InfiniBand Support
InfiniBand is computer-networking communications standard
used in high-performance computing, features very high
throughput and very low latency.
This patch allow ironic-inspector to add the client_id
to ironic port extra. The client_id option allow pxe boot
from InfiniBand interface.

Closes-Bug: #1532534
Depends-On: Ifad453977e5d3be64b34e544f269835a72b4d73f
Change-Id: I479d54c29bcacb6bd5c1ab20033ae6e428b0e744
2017-02-01 08:34:38 -05:00
Anton Arefiev 71099c9248 Change (started|finished)_at column type
Db column started_at and finished_at are defined as float type, but
float time doesn't fit into default db Float size. This change migrates
columns type to DateTime.

Closes-Bug: 1658975
Change-Id: I13bbb3c9a3e6e8bc744473437a378453ebc81318
2017-01-25 09:23:00 +00:00
Jenkins 2a80a41c51 Merge "Use oslo_serialization.base64 to follow OpenStack Python3" 2016-12-15 17:47:20 +00:00
Luong Anh Tuan f6d02e1cb9 Use oslo_serialization.base64 to follow OpenStack Python3
This patch replaces python standard base64 library call to
oslo_serialization.base64 to follow OpenStack Python3 porting
standard [1].

Use base64 encoding takes 8-bit binary byte data and encodes it. On
Python3, A string is a sequence of Unicode characters thus base64 has
no idea what to do with Unicode data, it's not 8-bit[2]. We use
oslo_serialization.base64 for python2 and python3.

[1] https://wiki.openstack.org/wiki/Python3
[2] http://stackoverflow.com/questions/8908287/base64-encoding-in-python-3

Change-Id: Ibf24df3a90ecbcdec400a0570f2818f89b78ea0a
2016-12-15 10:35:16 +00: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
Jenkins a35cb10896 Merge "Set node to the error if reapply fails" 2016-09-12 11:26:13 +00:00
Galyna Zholtkevych f29a71f576 Set node to the error if reapply fails
Setting node to the error status with error message
if reapply fails to get introspection data from swift.

Change-Id: Idccb68847d14d5050c735facf3da7b3ec108adbe
Closes-Bug: #1618833
2016-09-06 16:08:03 +03:00
Moshe Levi 027642246f Replace assertRaisesRegexp with assertRaisesRegex
assertRaisesRegexp is deprecated in python3
https://docs.python.org/3.2/library/unittest.html

Co-Authored-By: edan david <edand@mellanox.com>

Change-Id: I9446e745239d64ac9adf8fd1a8f95b5befc8cf06
2016-09-05 08:57:47 -04:00
Edan David f9979c1228 Inherit from oslotest base
Oslotest base class should be used as the base for unit test classes.
In addtion the oslotest BaseTestCase inherits from testtools.testCase,
according to fixtures docs "testtools has it’s own implementation of
useFixture so there is no need to use fixtures.TestWithFixtures with
testtools.TestCase."

Co-Authored-By: moshe levi <moshele@mellanox.com>
Change-Id: I7296d59ee30230ec2de6d55649c9f57a33534435
2016-09-05 08:57:25 -04:00
Zhenguo Niu a97c8cb6a3 Add config to skip power off after introspection
This adds configuration option 'processing.power_off'
defaulting to True, which will prevent powering off the
node after introspection

Change-Id: I16eb6b73fd57e84175bbce81c79e432ed8d1d3fa
Closes-Bug: #1488534
2016-07-19 19:44:06 +08:00
Dmitry Tantsur c98d3f479b Allow customizing ramdisk logs file names and simplify the default
The template for ramdisk logs file names can now be changed via
the configuration. The default now contains only node UUID and datetime.
Also a proper tar.gz extension is appended to avoid confusion.

Depends-On: Ie507e2e5c58cffa255bbfb2fa5ffb95cb98ed8c4
Change-Id: I738f9bd35705d0d11c95b0164186ed0b366b5252
2016-07-01 14:30:44 +02:00
Dmitry Tantsur 223ff38dcf Return HTTP 500 from /v1/continue on unexpected exceptions
Currently it returns HTTP 400 which is obviously wrong.

Closes-Bug: #1590302
Change-Id: I56114aa1c0a3248cc80f79d1a5da3ace6c615e52
2016-06-08 09:56:37 +02:00
Jenkins 6a1083d7a1 Merge "Remove support for the old bash ramdisk" 2016-06-06 13:17:03 +00: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
JinLi 52991a1b43 Remove iterated form of side effects to simplify code
remove iterated form of side effects from some test cases
that are simulating single exception/error

Change-Id: I5e9cb760587a48d8bbe059191f3605f6ed547a44
Closes-Bug: #1564392
2016-06-02 18:15:38 +01:00
Dmitry Tantsur af6fbf0717 Support Ironic node names in our API
This change drops check on UUID validness from our API.
It also has a subtle effect of doing Ironic node fetching in
the introspection status and data fetch calls, which might make them
slightly longer (but only when name is used).

A new helper common.ironic.get_node is created to unify how we fetch nodes
from Ironic. It also provides nicer exceptions.

Change-Id: I20cf65e57910568b70a62c3f9269a962e78a07e2
Closes-Bug: #1523902
2016-05-09 15:01:31 +02:00
Dmitry Tantsur b65ab065ea Store ramdisk logs on all processing failures, not only reported by the ramdisk
Previously the ramdisk logs were only stored if the ramdisk reported an error.
However, we are moving from ramdisk-side validation to server-side, so we need
ramdisk logs to be available if processing fails too.

This change moves storing ramdisk logs from a ramdisk_error plugin to core
processing code. As before, it can be disabled by setting ramdisk_logs_dir to
an empty value.

Change-Id: Ib3742ee1c1d4f2f96d29466626e1121694610dc3
Closes-Bug: #1564448
2016-05-04 12:46:59 +02:00
Dmitry Tantsur 5074e3248a Refactor test_process
* Use fixtures instead of a self-invented decorator
* Give proper names to mocks
* Swift from inline mocks to @decorators
* Split TestProcess into several test cases
* Remove the old style of setting side_effect (via iter)

Change-Id: If74221642723b0a6bea439dbcbdd360a43e7172f
2016-04-21 15:31:30 +03:00
dparalen f9e9a88d89 Allow rerunning introspection on stored data
As requested in the related bug, this pull request allows to run the
introspection again on previously stored data.  This should make it simple
to correct mistakes in the introspection rules.

For this purpose, new API entry point was introduced:
/v1/introspection/<UUID>/data/unprocessed that supports an empty POST
method to trigger the introspection over stored data.  New function
`reapply` was introduced that takes care about the entry point and carries
out the introspection.  The `process` function was modified to allow
reusing common parts in the new reapply function.  The storage access
methods were updated to allow saving the "raw" memdisk data besides the
processed introspection data.

Following preconditions are checked the reapply function having been
triggered:
* no data is being sent along with the request
* Swift store is configured and enabled and the stored data is present
  for the node UUID
* node_info object is cached for the UUID and it is possible to lock the
  object

Should the preconditions fail, an immediate response is given to the user:
* 400 if the request contained data or in case Swift store is not enabled
  in configuration
* 409 if it wasn't possible to acquire lock for the node_info object
* 404 in case Ironic didn't keep track of related BM node

If the preconditions are met, a background task is executed to carry out
the processing and a 202 Accepted response is returned to the endpoint
user.

As requested, these steps are performed in the background task:
* preprocessing hooks
* post processing hooks, storing result in Swift
* introspection rules

These steps are avoided, based on the RFE:
* not_found_hook is skipped
* power operations

Limitations:
* IMPI credentials are not updated --- ramdisk not running
* there's no way to update the raw data atm.
* the raw data is never cleaned from the store
* check for stored data presence is performed in background;
  missing data situation still results in a 202 response

Change-Id: Ic027c9d15f7f5475fcc3f599d081d1e8d5e244d4
Closes-Bug: #1525237
2016-04-07 10:40:55 +02:00
Anton Arefiev 30ae1e72f1 Move unit tests to "unit" directory
This refoctor is needed for tempest test work as tempest tests
will placed in test dir. So move unit tests to separate directory
"unit" under test.

Change-Id: Ic99df6111ef30947148a9e38b9435a54f3d37064
2016-04-05 11:15:29 +03:00