Sync with peer controller deploy state changes

This commit create a generic method to be used when a deploy state
is changed. For every modification on the file it will call the message
class to send the deploy state dataset to peer controller.

Test Plan:

PASS: Deploy state change sent to peer controller on deploy start

Depends-on: https://review.opendev.org/c/starlingx/update/+/904367

Story: 2010676
Task: 49335

Change-Id: Idc06074f059c2f0d683b5f291e594f6a1555d6d5
Signed-off-by: Luis Eduardo Bonatti <LuizEduardo.Bonatti@windriver.com>
This commit is contained in:
Luis Eduardo Bonatti 2023-12-28 17:36:17 -03:00
parent 9f7bddff25
commit cc3c1e896e
1 changed files with 27 additions and 9 deletions

View File

@ -32,7 +32,6 @@ from software.authapi import app as auth_app
from software.constants import DEPLOY_STATES
from software.base import PatchService
from software.exceptions import APTOSTreeCommandFail
from software.db import api as db_api
from software.exceptions import InternalError
from software.exceptions import MetadataFail
from software.exceptions import UpgradeNotSupported
@ -2241,13 +2240,11 @@ class PatchController(PatchService):
def deploy_state_changed(self, deploy_state):
'''Handle 'deploy state change' event, invoked when operations complete. '''
dbapi = db_api.get_instance()
dbapi.update_deploy(deploy_state)
self.db_api_instance.update_deploy(deploy_state)
def host_deploy_state_changed(self, hostname, host_deploy_state):
'''Handle 'host deploy state change' event. '''
dbapi = db_api.get_instance()
dbapi.update_deploy_host(hostname, host_deploy_state)
self.db_api_instance.update_deploy_host(hostname, host_deploy_state)
def software_deploy_start_api(self, deployment: str, force: bool, **kwargs) -> dict:
"""
@ -2271,14 +2268,14 @@ class PatchController(PatchService):
if self._deploy_upgrade_start(to_release):
collect_current_load_for_hosts()
dbapi = db_api.get_instance()
dbapi.create_deploy(SW_VERSION, to_release, True)
dbapi.update_deploy(DEPLOY_STATES.START)
self.update_and_sync_deploy_state(self.db_api_instance.create_deploy,
SW_VERSION, to_release, True)
self.update_and_sync_deploy_state(self.db_api_instance.update_deploy,
DEPLOY_STATES.START)
sw_rel = self.release_collection.get_release_by_id(deployment)
if sw_rel is None:
raise InternalError("%s cannot be found" % to_release)
sw_rel.update_state(constants.DEPLOYING)
self._update_state_to_peer()
msg_info = "Deployment for %s started" % deployment
else:
msg_error = "Deployment for %s failed to start" % deployment
@ -2936,6 +2933,27 @@ class PatchController(PatchService):
return deploy_host_list
def update_and_sync_deploy_state(self, func, *args, **kwargs):
"""
:param func: SoftwareApi method
:param args: arguments passed related to func
:param kwargs: keyword arguments passed related to func
Example:
-------
Usage of *args:
update_and_sync_deploy_state(self.db_api_instance.create_deploy,
release_version, to_release, bool)
Usage of **kwargs:
update_and_sync_deploy_state(self.db_api_instance.update_deploy_host,
hostname=hostname, state=state)
"""
func(*args, **kwargs)
self._update_state_to_peer()
class PatchControllerApiThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)