Commit Graph

346 Commits

Author SHA1 Message Date
James Page 6b38affa15
tests: Fix syntax error in hacking test
Under Python 3.12 this results in a syntax error rather than
M329 being detected on line 8 of the test code.

Change-Id: Ia1bb4dfb43b00115cde1158681d34d6ad7c7d744
2024-01-22 20:18:43 +00:00
Stephen Finucane 5647c6b132 db: Don't rely on implicit autocommit
Resolve the following RemovedIn20Warning warning:

  The current statement is being autocommitted using implicit
  autocommit, which will be removed in SQLAlchemy 2.0. Use the .begin()
  method of Engine or Connection in order to use an explicit transaction
  for DML and DDL statements.

This is the beefiest one due to our extensive reliance on auto-commit.

Change-Id: Iebf9d022c312b8f5457ff34eb497cdb851aa4901
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-24 03:36:11 +00:00
Stephen Finucane bbc4f7edd0 db: Don't use legacy select() calling style
Resolve the following RemovedIn20Warning warning:

  The legacy calling style of select() is deprecated and will be removed
  in SQLAlchemy 2.0.  Please use the new calling style described at
  select().

Change-Id: I00206489e97468d98a3a516c7c081c70348e3998
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-24 01:39:29 +00:00
Stephen Finucane 6f2a704556 db: Don't use strings to indicate paths
Resolve the following RemovedIn20Warning warning:

  Using strings to indicate column or relationship paths in loader
  options is deprecated and will be removed in SQLAlchemy 2.0.  Please
  use the class-bound attribute directly.

Change-Id: I1b71331796c2730713797043489b6c11710b9851
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-23 06:10:48 +00:00
Stephen Finucane 69d62e3e6d db: Don't pass strings to Connection.execute()
Resolve the following RemovedIn20Warning warning:

  Passing a string to Connection.execute() is deprecated and will be
  removed in version 2.0.  Use the text() construct, or the
  Connection.exec_driver_sql() method to invoke a driver-level SQL
  string.

We do the latter.

Change-Id: I0ee518022772beeb0298e12b5b36279fd384fb4a
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-23 04:25:12 +00:00
Stephen Finucane 4545fdf69f tests: Resolve various warnings
These are highlighted by the new WarningsFixture.

Change-Id: If9a27784e4f4fde61dff73c1f6fde99324e1aa07
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-23 02:42:08 +00:00
Stephen Finucane 88950e33ba tests: Enable SQLAlchemy 2.0 deprecation warnings
Well, sort of. We enable them but immediately filter out the ones we're
actually seeing, the rationale being that we can address these in a
piecemeal fashion without the risk of introducing new issues.

There's a lot more to be done here. However, the work done in oslo.db
[1], nova [2], cinder [2] etc. should provide a guide for how to resolve
the outstanding issues.

[1] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/oslo.db
[2] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/nova
[3] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/cinder

Change-Id: If13c14f1d968f1ef968ae440087227691cf966b0
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 15:57:44 +00:00
Stephen Finucane df3fdb4f4e db: Remove legacy migrations
These are no longer used. Curiously, sqlalchemy-migrate is not in the
dependencies and was instead being pulled in as a transitive dependency
of oslo.db. This will therefore disappear when oslo.db is bumped to 13.x
or later in upper-constraints, since that version removes
sqlalchemy-migrate support.

Change-Id: I4ea8ae36c9f8d3e5e5a9ac9548c5fe8f975cd666
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 09:24:36 +00:00
Stephen Finucane 6823ea5ed1 db: Migrate to alembic
This is easier than Cinder, Nova etc. but more difficult than Heat.
Masakari hasn't had many database migrations in recent cycles but it did
have on in Antelope. This means we need to handle people doing
skip-level upgrades and validate which version of the legacy migrations
they are currently on. We support users coming from both Zed and
Antelope and anyone else will need to go through an older version of
Masakari to update their database migrations first. Other than this
difference, the logic is pretty similar: as with other projects, we
simply determine if we're upgrading a deployment that was previously
using sqlalchemy-migrate, upgrading a deployment that has already
migrated to alembic, or deploying a new deployment, and adjust
accordingly.

In addition, we also have to consider Taskflow's migrations. These were
previously being run once as part of the legacy
006_add_persistence_tables migrations. Since Taskflow uses Alembic under
the hood, it's safe to run every time. The presence of Taskflow does
force us to use a different table name in Masakari though.

Note that one curious side-effect of this is that the order than table
rows are purged change. This appears to be happening because the
notification table is now being created in the initial Alembic
migration, which alters the return value of 'MetaData.sorted_tables'.
In any case, the fix is simply a case of adjusting this order in the
tests.

Change-Id: I5285d7cc3c6da0059c0908cedc195b2262cb1fce
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 07:31:12 +00:00
Stephen Finucane 85fd89726c tests: Validate number of rows _before_ purging
A nice sanity check.

Change-Id: I387fa387f392d2511d75ef955ae69df3978c65cb
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 07:05:33 +00:00
Stephen Finucane d7a918f2b1 db: Sync alembic, sqlalchemy-migrate migrations
Alembic's auto-generate functionality doesn't preserve index names or
column order. This causes comparisons between databases to fail. Update
the initial alembic migration to match the schema's generated by
sqlalchemy-migrate.

Change-Id: I16763a82cc2db9138882ace2dad6f0cae330b9e8
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 05:31:48 +00:00
Stephen Finucane ed872b3fe0 db: Add initial alembic migration
This was generated using the same approach first used in heat [1], but
with a difference to account for the fact that, unlike heat, we have a
migration added in recent times. We generate our initial schema
automatically based on our models using alembic's auto-generate
functionality:

  alembic --config masakari/db/sqlalchemy/alembic.ini \
    revision -m 'Initial empty revision'
  alembic --config masakari/db/sqlalchemy/alembic.ini \
    upgrade head
  alembic --config masakari/db/sqlalchemy/alembic.ini \
    revision -m 'Auto-generated revision' --autogenerate

The two files were then combined, formatting and imports adjusted. We
then *remove* the parts of the migration related to the 'vm_moves' table
and run the autogeneration step again:

  alembic --config masakari/db/sqlalchemy/alembic.ini \
    revision -m 'Add vm moves table' --autogenerate

As noted above, this is necessary since we're going to need to support
alembic-based migrations for users jumping from e.g. Zed to Bobcat.
Once done, the schema of these migrations and the sqlalchemy-migrate
migrations are compared. This step was done by comparing the schemas of
a database created by the sqlalchemy-migrate tool to the one created by
alembic. First, we compared the initial alembic migration which
corresponds to the state of the database after sqlalchemy-migrate
migration 007:

  alembic --config masakari/db/sqlalchemy/alembic.ini \
    upgrade 8f848eb45d03
  python masakari/db/sqlalchemy/migrate_repo/manage.py version_control \
    sqlite:///masakari-old.db 000
  python masakari/db/sqlalchemy/migrate_repo/manage.py upgrade \
    sqlite:///masakari-old.db 007

With the two databases created, we can compare them using the
methodologies described in [2]. Once this is done, we do the same things
for the final migration to generate its own alembic variation of the
migration.

  alembic --config masakari/db/sqlalchemy/alembic.ini \
    upgrade head
  python masakari/db/sqlalchemy/migrate_repo/manage.py upgrade \
    sqlite:///masakari-old.db

These last steps highlight some small differences between the schemas.
These changes are kept to a separate change to make them more obvious.

[1] https://review.opendev.org/c/openstack/heat/+/878350
[2] https://that.guru/blog/comparing-nova-db-migrations/

Change-Id: I6d0f27ba1d81e75010e8b56c70172ccf32c1abb3
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 02:38:43 +00:00
Stephen Finucane 13ae6c01c9 db: Wire up for auto-generation
Change-Id: I81b4c80b592230befb7bb315411b9f0b1214aee3
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-22 01:03:57 +00:00
Stephen Finucane 50a46964a2 db: Add initial alembic configuration
No migrations yet: this is simply the output of 'alembic init' with some
minor tweaks.

Change-Id: Ib9423c2f751d7ec0a0dec89bdc39f9b6ab043655
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-21 15:57:33 +00:00
Stephen Finucane 962cf0abed db: Remove configurable backends
oslo.db has killed the idea of the migration wrappers. This knob is
therefore no longer useful.

Change-Id: Ia61b3291668b17b13d5f674c0dceff29a7b9b4cf
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-21 11:06:20 +00:00
Stephen Finucane 94257be795 pre-commit: Update dependencies
We also bump the hacking version and remove some unnecessary notes from
the top of the requirements files: these don't apply with the dependency
resolver introduced in pip 20.3.

Change-Id: Ifebaec916264bfd10eec13040295719fd47ae107
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-12-21 09:13:09 +00:00
suzhengwei e6ab50131e fix ci broken
1.Add sqlalchemy-migrate dependence in test-requirements.txt.

It will remove the dependence after this project switchs to alembic.
Remove "check-requirements" temporarily.

2.Fix unit tests broken by olso.utils

Some of the object unit tests grub Mock object unintentionally, and
that results in failure during initializing an versioned object,
because the Mock object does not present its version correctly.

3.make functional jobs not voting

Fix functional jobs later.

Change-Id: Id3c952a54e77952cfd0d76d259f49a14edca1d8b
2023-12-21 13:36:46 +08:00
Jay Faulkner 636df88983 Fix compatability with new oslo.messaging
A recent change to oslo.messaging to redact contexts before sending them
to a notification bus broke masakari due to the invalid default for
read_deleted. This ensures that a "None" value for read_deleted ends up
being interpreted as a 'none'.

Related-bug: #2030976
Change-Id: Ic9b895601f301c1e9ba135766493d4234fa9b50b
2023-09-08 14:06:04 -07:00
suzhengwei bad1f2fe6e log when set host on maintenance
Change-Id: I44b1db763d3a0ed9eb4c007278c8f131db9b57dd
2023-06-29 18:54:49 +08:00
suzhengwei dcb7c0b7e1 extend wait period for process notification
Change-Id: I99247ebd2d1384930eb5c3d3f01fdab1687570bd
2023-06-01 20:01:02 +08:00
suzhengwei b2f2a58e3c use looping call with timeout
When period call, use loopingcall with timeout instead of etimeout.

Change-Id: I5c7d77a0578bbf96ba9d13f6b2784eb912fc548a
2023-03-20 18:02:04 +08:00
suzhengwei 3e1b85133a vmoves table purge support
Change-Id: I10b4793d0471a26df4381988670334a695067d27
2023-02-16 11:11:01 +08:00
suzhengwei 72a35ed293 update api microversion for masakari vmoves
Change-Id: If85a1dc8e0801fc52effdaf17f0fa6da11688eab
2023-02-02 10:12:04 +08:00
Zuul e8db24c637 Merge "vm moves for host notification" 2023-01-28 13:19:42 +00:00
suzhengwei 23c6c31409 vm moves for host notification
This feature is mainly to persist vm moves information of one host
notification into the database. It also provides a new 'VMove' api,
which could help users to insight the process or result of the host
recovery workflow, such as which vms evacuated succeed or failed, and
which ones are still evacuating.

Implements: BP vm-evacuations-for-host-recovery
Change-Id: I334af06ef526bf11dfe5030e8cba210b98f1ceea
2023-01-28 11:01:24 +00:00
Tobias Urdin 73e35991ff Use new get_rpc_client API from oslo.messaging
Use the new API that is consistent with
the existing API instead of instantiating the client
class directly.

This was introduced in release 14.1.0 here [1] and
added into oslo.messaging here [2]

[1] https://review.opendev.org/c/openstack/requirements/+/869340
[2] https://review.opendev.org/c/openstack/oslo.messaging/+/862419

Change-Id: Ica14ddd31fa6be22b0d1f4bed26f266c6d9f660f
2023-01-23 19:22:07 +00:00
sue 7ec3edda1a Fix notfication stuck into running status when timeout
For instance or process failure workflow, the failure notification
would stuck into running status if timeout.

Closes-Bug: #1996835
Change-Id: I61e941ab9dd831369fcc46a132ae2b11c1dd23ba
2022-12-05 10:23:01 +08:00
Mitya_Eremeev 0837d7787c Handle host notification without host status
If an user sends host notification without host status:
openstack notification create COMPUTE_HOST <host> <date> '{"event": "STOPPED"}'
logging registers silly error like object None has not method 'upper' and
notification gets status 'running', host is set in maintenance status.
It's impossible to set manually host status to non-maintanence
until there are host-related running notifications.
Running notifications are expired in 24 hours by default.
The patch makes engine to set 'ignore' status for such
notifications.

Closes-Bug: 1960619
Change-Id: Id873b3300b6de49082805654c85414a8868dd925
2022-10-12 15:23:22 +00:00
Zuul 16001fdf02 Merge "Fix stopping stopped instances" 2022-09-09 14:03:28 +00:00
suzhengwei 7241101163 Fix stopping stopped instances
Nova-compute would periodically sync the instance status. So in the
instance failure recovery workflow,it would stop instance random failed
because of conflict, which will terminate the recovery workflow.
This patch can catch the Confict exception and continue the recovery
workflow if the instance already stopped.

Closes-Bug: 1980736
Change-Id: I59a1f9d7078614c1ddc8f4c362e967a15b8ec5e8
2022-09-09 11:24:41 +00:00
suzhengwei 56a9ec2ad8 add notification_uuid into log message
Change-Id: If07f894a924b281c53b5a14b25409acbd1e3e7f2
2022-09-07 08:57:16 +00:00
ljhuang 6ea71cbd55 Replace abc.abstractproperty with property and abc.abstractmethod
Replace abc.abstractproperty with property and abc.abstractmethod,
as abc.abstractproperty has been deprecated since python3.3[1]

[1]https://docs.python.org/3.8/whatsnew/3.3.html?highlight=deprecated#abc

Change-Id: I96dea752c8ef6ff7dddc205090d2ae7ccc4ce9ab
2022-08-03 20:30:38 +08:00
Mitya_Eremeev 9fef8807cf DLM to fix host notification race.
Two concurrent events that host is down
might be accepted by different instances of API
which triggers two evacuation workflows for instances.
Patch introduces distributed lock for creation of
host type notifications. It solves the issue.

Closes-Bug: 1961110
Change-Id: Ie8f10b14f29a8548181560cd8a26b4dc79afc3dc
2022-07-19 09:31:47 +00:00
Takashi Kajinami 2c7d40360b Fix compatibility with oslo.context >= 4.0.0 (one more again)
This change fixes the remaining issue with oslo.context >= 4.0.0.

In oslo.context < 4.0, RequestContext.from_dict looks up 'tenant' key
from dict to set project_id while the method looks up 'project_id' key
since oslo.context 4.0. This change implements a logic to make unit
tests compatible with the both behavior, but the one for older version
can be removed once we get oslo.context >= 4.0.0 in upper-constraints.

Change-Id: I463e34ef36891c5ef29e88cb645c38a6cccac2f2
2022-03-03 23:42:52 +09:00
Takashi Kajinami 1a67234757 Fix compatibility with oslo.context >= 4.0.0 (again)
This is follow-up of c9d01a5327 and fixes
one additional failure found after we merged that fix.

Change-Id: Ica9f080c3ec52b6cc1746c952251b2ae8a18422e
2022-03-03 15:30:33 +09:00
Takashi Kajinami c9d01a5327 Fix compatibility with oslo.context >= 4.0.0
The tenant argument of RequestContext is longer available since
oslo.context 4.0.0. This change removes usage of the deprecated
argument to prepare for version bump.

Change-Id: If237c6abf791526a7c20e393525e83c0a2d1a9ed
2022-03-01 17:37:02 +09:00
Radosław Piliszek 37042807d0 Make functional tests consume all config
This makes functional testing compatible with tls-proxy which
requires setting cacert.

Change-Id: Ia7c5fc2c3ce08149c8af63bf2240f756ddb1993f
2021-09-07 18:26:51 +00:00
Zuul 958bbfe341 Merge "Set "disabled reason" for compute service." 2021-08-19 06:08:56 +00:00
Mitya_Eremeev c861437b52 Set "disabled reason" for compute service.
Masakari never sets reason why compute service was disabled.
"disabled reason" was added in config.

Closes-Bug: 1936181
Change-Id: I998f7884195b93927773c7186d61c13670a53662
2021-08-17 13:11:53 +03:00
Zuul 86f57b71be Merge "tests: Remove use of 'oslo_db.sqlalchemy.test_base'" 2021-08-16 08:47:01 +00:00
Zuul ac120ee5e0 Merge "Fix Masakari API to properly return error codes" 2021-08-07 10:41:19 +00:00
Stephen Finucane 0f64cb1408 tests: Remove use of 'oslo_db.sqlalchemy.test_base'
The various test cases and mixins in 'oslo_db.sqlalchemy.test_base' have
been deprecated since oslo.db 4.34.0 (March 2018). Remove use of these.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I8f4d55c397f61777bec830855f229e5fe5af90dc
2021-07-28 18:05:50 +01:00
Mitya_Eremeev 5c6fd44504 Fix Masakari API to properly return error codes
Change-Id: I538b9b143c868d9419709356daf0ffc48e2f0df9
Closes-Bug: #1932194
2021-07-23 18:46:50 +00:00
minruigao f2e830f927 Fix a spelling mistakes in unit test
The patch fix a spelling mistakes in unit test.In notification unit test,
test use fake host named 'fake_host1',normally it is 'fake_host_1'.

Change-Id: Ic607edef6ce6c8b90eb46a840f483210ba6019f6
2021-06-24 09:24:26 +00:00
sue d51cefe238 uuid in log information
Change-Id: I998fe80c2afe5f9b6c120846922a1127564e1254
2021-05-18 11:13:05 +08:00
Zuul 2c6e500dc1 Merge "Replace getargspec with getfullargspec" 2021-05-17 14:24:52 +00:00
Zuul 15aef6e0f8 Merge "Make unit tests compatible with SQLAlchemy 1.4" 2021-05-14 13:59:04 +00:00
Takashi Natsume 563049ebd4 Replace getargspec with getfullargspec
inspect.getargspec() is deprecated since py3

[1] https://docs.python.org/3/library/inspect.html#inspect.getargspec

Signed-off-by: Takashi Natsume <takanattie@gmail.com>
Change-Id: I5e59ec22ca01c8a8a3575e4c2d58fa97a241b475
2021-05-13 21:31:05 +09:00
Radosław Piliszek e5246e282f Make unit tests compatible with SQLAlchemy 1.4
The .count() method is gone from the Table class.
Let's use func.count in its stead.

Closes-Bug: #1926399
Change-Id: Ica81271fe85478fdffae4ea0b6f4ed3b168f4552
2021-05-07 10:12:52 +00:00
dengzhaosen b547219c29 Ussuri+ is python3 only and update python to python3
Change-Id: I24f0313f52423e674f9085216727acfb9fe3b4ba
2021-05-06 10:15:27 +08:00