Files
distcloud/distributedcloud/dcmanager/orchestrator/states/patch/pre_check.py
Gustavo Herzmann bd7d2a6922 Refactor distributed cloud patch orchestration
Makes PatchOrchThread a subclass of the OrchThread, following the same
design used in the other types of orchestration. It also removes the
strategy step to orchestrate the system controller patching, as it
should be done separately, before initializing the patch orchestration
to patch the subclouds.

The alarm checks that were executed inside the 'updating' state are now
part of a new 'pre-check' state that runs at the beggining of the
orchestration process.

It also refactors the unit tests to be in line with the unit tests of
the other orchestrator types by using the TestSwUpdate base class.

Test Plan:
1. PASS - Verify successfull patch orchestration by applying and
          removing a NRR patch;
2. PASS - Verify successfull patch orchestration by applying and
          removing a RR patch;
3. PASS - Induce a management affecting alarm in a subcloud and verify
          that orchestration fails for that subcloud;
4. PASS - Induce a 900.001 alarm by partially apply a patch in a
          subcloud beforehand and verify that orchestration completes
          successfully for that subcloud;
5. PASS - Create a DC orch patch strategy, then manually patch a
          subcloud using the sw-manager patch-strategy command and
          then apply the DC orch patch strategy, verifying if the
          state machine skips from the 'creating VIM patch strategy'
          state directly to the 'finishing patch strategy' state;
6. PASS - Verify that no strategy step is created for the system
          controller;
7. PASS - Execute another orchestration type (e.g. prestage) and
          verify that it still works as expected.

Story: 2010584
Task: 47371

Co-Authored-By: Al Bailey <al.bailey@windriver.com>
Signed-off-by: Gustavo Herzmann <gustavo.herzmann@windriver.com>
Change-Id: I2c37bd59696e6f9e4fd706f3b3c97f8f9e4499b0
2023-02-27 09:48:14 -03:00

52 lines
1.8 KiB
Python

#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from dcmanager.common import consts
from dcmanager.orchestrator.states.base import BaseState
IGNORED_ALARMS_IDS = ("900.001",) # Patch in progress
class PreCheckState(BaseState):
"""Pre check patch orchestration state"""
def __init__(self, region_name):
super(PreCheckState, self).__init__(
next_state=consts.STRATEGY_STATE_UPDATING_PATCHES,
region_name=region_name)
def has_mgmt_affecting_alarms(self, ignored_alarms=()):
alarms = self.get_fm_client(self.region_name).get_alarms()
for alarm in alarms:
if alarm.mgmt_affecting == "True" and \
alarm.alarm_id not in ignored_alarms:
return True
# No management affecting alarms
return False
def perform_state_action(self, strategy_step):
"""Pre check region status"""
self.info_log(strategy_step, "Checking subcloud alarm status")
# Stop patching if the subcloud contains management affecting alarms.
message = None
try:
if self.has_mgmt_affecting_alarms(ignored_alarms=IGNORED_ALARMS_IDS):
message = ("Subcloud contains one or more management affecting"
" alarm(s). It will not be patched. Please resolve"
" the alarm condition(s) and try again.")
except Exception as e:
self.exception_log(strategy_step,
"Failed to obtain subcloud alarm report")
message = ("Failed to obtain subcloud alarm report due to: (%s)."
" Please see /var/log/dcmanager/orchestrator.log for"
" details" % str(e))
if message:
raise Exception(message)
return self.next_state