Files
distcloud/distributedcloud/dcmanager/manager/states/upgrade/installing_license.py
albailey 5e5c416a9b Implement import-load and starting-upgrade strategy states
This commit allows the state machine to be defined through an
ordered list of states. The states are mapped to by a dictionary
to state handler classes.

This greatly simplifies the software upgrade orch thread so that it
can be refactored in the future to share functionality with other orch
thread strategy types.

The following states have been implemented:
 - 'importing load'
 - 'starting upgrade'
 - 'activating upgrade'
 - 'completing upgrade'

The 'installing license' state now uses this design pattern.
Its functionality and unit tests are now in their own files.

The 'unlocking' state requires additional changes for the
'activating' and 'completing' states to pass.

Change-Id: Iedc40bdea406461dd4c2ce3887a37be6ec3c999f
Story: 2007403
Task: 40001
Signed-off-by: albailey <Al.Bailey@windriver.com>
2020-06-09 15:34:27 -05:00

87 lines
3.7 KiB
Python

#
# Copyright (c) 2020 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from dcmanager.common import consts
from dcmanager.common import exceptions
from dcmanager.manager.states.base import BaseState
# When a license is not installed, this will be part of the API error string
LICENSE_FILE_NOT_FOUND_SUBSTRING = "License file not found"
class InstallingLicenseState(BaseState):
"""Upgrade state action for installing a license"""
def __init__(self):
super(InstallingLicenseState, self).__init__()
@staticmethod
def license_up_to_date(target_license, existing_license):
return target_license == existing_license
def perform_state_action(self, strategy_step):
"""Install the License for a software upgrade in this subcloud
Any exceptions raised by this method set the strategy to FAILED
Returning normally from this method set the strategy to the next step
"""
# check if the the system controller has a license
local_ks_client = self.get_keystone_client()
local_sysinv_client = \
self.get_sysinv_client(consts.DEFAULT_REGION_NAME,
local_ks_client.session)
system_controller_license = local_sysinv_client.get_license()
# get_license returns a dictionary with keys: content and error
# 'content' can be an empty string in success or failure case.
# 'error' is an empty string only in success case.
target_license = system_controller_license.get('content')
target_error = system_controller_license.get('error')
# If the system controller does not have a license, do not attempt
# to install licenses on subclouds, simply proceed to the next stage
if len(target_error) != 0:
if LICENSE_FILE_NOT_FOUND_SUBSTRING in target_error:
self.info_log(strategy_step,
"System Controller License missing: %s."
% target_error)
return True
else:
# An unexpected error occurred querying the license
raise exceptions.LicenseInstallError(
subcloud_id=consts.SYSTEM_CONTROLLER_NAME)
# retrieve the keystone session for the subcloud and query its license
subcloud_ks_client = \
self.get_keystone_client(strategy_step.subcloud.name)
subcloud_sysinv_client = \
self.get_sysinv_client(strategy_step.subcloud.name,
subcloud_ks_client.session)
subcloud_license_response = subcloud_sysinv_client.get_license()
subcloud_license = subcloud_license_response.get('content')
subcloud_error = subcloud_license_response.get('error')
# Skip license install if the license is already up to date
# If there was not an error, there might be a license
if len(subcloud_error) == 0:
if self.license_up_to_date(target_license, subcloud_license):
self.info_log(strategy_step, "License up to date.")
return True
else:
self.debug_log(strategy_step, "License mismatch. Updating.")
else:
self.debug_log(strategy_step, "License missing. Installing.")
# Install the license
install_rc = subcloud_sysinv_client.install_license(target_license)
install_error = install_rc.get('error')
if len(install_error) != 0:
raise exceptions.LicenseInstallError(
subcloud_id=strategy_step.subcloud_id)
# The license has been successfully installed. Move to the next stage
self.info_log(strategy_step, "License installed.")
return True