Raphael Lima 458a3f35a9 Update id specification in subcloud audits bulk update
This commit updates the query introduced in [1] to bulk update the
audit_finished_at timestamp in order to fix the id being used from the
subcloud's id to the subcloud_audits' id.
Additionally, it also adds a validation in audit utils to only change
the subcloud_audits table when a value is specified, avoiding a deadlock
issue that was caused by having an empty values sent.

Test plan:
1. PASS: restart the audit process in a scale system and verify that no
   deadlock errors occur.
2. PASS: restart the system and verify that no StaleDataError occurs.
3. PASS: verify that the subcloud_audits is updated with the correct
   audit finifhed at for a subcloud.

[1] https://review.opendev.org/c/starlingx/distcloud/+/926447

Story: 2011106
Task: 50996

Change-Id: Ia69af8663cce1e99963410cfbf2efc190bffaaf1
Signed-off-by: Raphael Lima <Raphael.Lima@windriver.com>
2024-09-10 15:59:21 -03:00

73 lines
2.4 KiB
Python

# Copyright (c) 2021, 2024 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#
# The right to copy, distribute, modify, or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
from oslo_log import log as logging
from dcmanager.db import api as db_api
LOG = logging.getLogger(__name__)
def request_subcloud_audits(
context,
update_subcloud_state=False,
audit_patch=False,
audit_load=False,
audit_firmware=False,
audit_kubernetes=False,
audit_kube_rootca=False,
audit_software=False,
):
values = {}
if update_subcloud_state:
values["state_update_requested"] = True
if audit_patch:
values["patch_audit_requested"] = True
if audit_load:
values["load_audit_requested"] = True
if audit_firmware:
values["firmware_audit_requested"] = True
if audit_kubernetes:
values["kubernetes_audit_requested"] = True
if audit_kube_rootca:
values["kube_rootca_update_audit_requested"] = True
if audit_software:
values["spare_audit_requested"] = True
if values:
db_api.subcloud_audits_update_all(context, values)
def filter_endpoint_data(context, subcloud, endpoint_data):
if endpoint_data:
LOG.debug(
f"Endpoint status before filtering for {subcloud.name}: {endpoint_data}"
)
subcloud_statuses = db_api.subcloud_status_get_all(context, subcloud.id)
for subcloud_status in subcloud_statuses:
endpoint_type = subcloud_status.endpoint_type
if (
endpoint_type in endpoint_data
and endpoint_data[endpoint_type] == subcloud_status.sync_status
):
del endpoint_data[endpoint_type]
LOG.debug(
f"Endpoint status after filtering for {subcloud.name}: {endpoint_data}"
)