Add a switch to dcmanager orchestrator

Add a switch to dcmanager orchestrator to allow the orchestrator
to use the new usm api. Use a service flag to define whether patching/upgrade
or usm api will be used by the orchestrator. Once the usm api is complete,
this switch will be removed.

Story: 2010676
Task: 48530
Depends-On: https://review.opendev.org/c/starlingx/distcloud/+/884442

Test Case:
PASS: turn the usm switch on and verify that the USM API is used.
PASS: turn the usm switch off and verify that the patch API is
used and the regular states are used.

Signed-off-by: Christopher Souza <Christopher.DeOliveiraSouza@windriver.com>
Change-Id: I3045f62f1541bacd2dd65392692432f4b0519dd1
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Christopher Souza 2023-08-07 13:00:38 -03:00 committed by Christopher de Oliveira Souza
parent 0c51734bd7
commit 83e5d159a8
3 changed files with 102 additions and 16 deletions

View File

@ -1,5 +1,5 @@
# Copyright 2016 Ericsson AB
# Copyright (c) 2017-2022 Wind River Systems, Inc.
# Copyright (c) 2017-2023 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
@ -164,6 +164,11 @@ common_opts = [
help='global ansible playbook timeout (seconds)'),
]
usm_opts = [
cfg.BoolOpt('use_usm', default=False,
help='parameter to enable usm api')
]
scheduler_opt_group = cfg.OptGroup(name='scheduler',
title='Scheduler options for periodic job')
keystone_opt_group = cfg.OptGroup(name='keystone_authtoken',
@ -186,6 +191,7 @@ def list_opts():
yield pecan_group.name, pecan_opts
yield None, global_opts
yield None, common_opts
yield None, usm_opts
def register_options():

View File

@ -0,0 +1,63 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from oslo_log import log as logging
from dccommon.drivers.openstack import vim
from dcmanager.common import consts
from dcmanager.db import api as db_api
from dcmanager.orchestrator.orch_thread import OrchThread
LOG = logging.getLogger(__name__)
class SoftwareOrchThread(OrchThread):
"""Software Orchestration Thread
This thread is responsible for executing the software orchestration strategy.
Here is how it works:
- The user creates an update strategy from CLI (or REST API) of 'usm'
- This ends up being handled by the SwUpdateManager class, which
runs under the main dcmanager thread. The strategy is created and stored
in the database.
- The user then applies the strategy from the CLI (or REST API). The
SwUpdateManager code updates the state of the strategy in the database.
- The SoftwareOrchThread wakes up periodically and checks the database for
a strategy that is in an active state (applying, aborting, etc...). If
so, it executes the strategy, updating the strategy and steps in the
database as it goes, with state and progress information.
"""
def __init__(self, strategy_lock, audit_rpc_client):
super(SoftwareOrchThread, self).__init__(
strategy_lock,
audit_rpc_client,
consts.SW_UPDATE_TYPE_UPGRADE, # software update strategy type
vim.STRATEGY_NAME_SW_UPGRADE, # strategy type used by vim
consts.STRATEGY_STATE_COMPLETE) # starting state
def trigger_audit(self):
"""Trigger an audit for upgrade (which is combined with patch audit)"""
self.audit_rpc_client.trigger_patch_audit(self.context)
def delete(self, sw_update_strategy):
super(SoftwareOrchThread, self).delete(sw_update_strategy)
def apply(self, sw_update_strategy):
LOG.info("(%s) Applying update strategy" % self.update_type)
LOG.info("(%s) Strategy application is complete."
% self.update_type)
with self.strategy_lock:
db_api.sw_update_strategy_update(
self.context,
state=consts.SW_UPDATE_STATE_COMPLETE,
update_type=self.update_type)
self.subcloud_workers.clear()
# Trigger audit to update the sync status for each subcloud.
self.trigger_audit()
return

View File

@ -18,6 +18,7 @@ import os
import shutil
import threading
from oslo_config import cfg
from oslo_log import log as logging
from tsconfig.tsconfig import SW_VERSION
@ -37,6 +38,7 @@ from dcmanager.orchestrator.kube_upgrade_orch_thread \
import KubeUpgradeOrchThread
from dcmanager.orchestrator.patch_orch_thread import PatchOrchThread
from dcmanager.orchestrator.prestage_orch_thread import PrestageOrchThread
from dcmanager.orchestrator.software_orch_thread import SoftwareOrchThread
from dcmanager.orchestrator.sw_upgrade_orch_thread import SwUpgradeOrchThread
LOG = logging.getLogger(__name__)
@ -56,17 +58,27 @@ class SwUpdateManager(manager.Manager):
# Used to notify dcmanager-audit
self.audit_rpc_client = dcmanager_audit_rpc_client.ManagerAuditClient()
# Define which API will be used
self.use_usm = cfg.CONF.use_usm
# todo(abailey): refactor/decouple orch threads into a list
# Start worker threads
# - patch orchestration thread
self.patch_orch_thread = PatchOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.patch_orch_thread.start()
# - sw upgrade orchestration thread
self.sw_upgrade_orch_thread = SwUpgradeOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.sw_upgrade_orch_thread.start()
# - fw update orchestration thread
if self.use_usm:
# - software orchestration thread
self.software_orch_thread = SoftwareOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.software_orch_thread.start()
else:
# - patch orchestration thread
self.patch_orch_thread = PatchOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.patch_orch_thread.start()
# - sw upgrade orchestration thread
self.sw_upgrade_orch_thread = SwUpgradeOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.sw_upgrade_orch_thread.start()
# - fw update orchestration thread
self.fw_update_orch_thread = FwUpdateOrchThread(self.strategy_lock,
self.audit_rpc_client)
self.fw_update_orch_thread.start()
@ -87,12 +99,17 @@ class SwUpdateManager(manager.Manager):
def stop(self):
# Stop (and join) the worker threads
# - patch orchestration thread
self.patch_orch_thread.stop()
self.patch_orch_thread.join()
# - sw upgrade orchestration thread
self.sw_upgrade_orch_thread.stop()
self.sw_upgrade_orch_thread.join()
if self.use_usm:
# - software orchestration thread
self.software_orch_thread.stop()
self.software_orch_thread.join()
else:
# - patch orchestration thread
self.patch_orch_thread.stop()
self.patch_orch_thread.join()
# - sw upgrade orchestration thread
self.sw_upgrade_orch_thread.stop()
self.sw_upgrade_orch_thread.join()
# - fw update orchestration thread
self.fw_update_orch_thread.stop()
self.fw_update_orch_thread.join()