From 9f5a3fbf8072c15571f0d8b5240227c8b5a097f9 Mon Sep 17 00:00:00 2001 From: Hugo Brito Date: Wed, 12 Jul 2023 08:40:05 -0300 Subject: [PATCH] Centralize installation values in a common file This commit aims to enhance code consistency by consolidating all necessary installation values into a common file: dccommon/consts.py. Previously, these values were spread across multiple files, which could lead to inconsistencies during subcloud installation and upgrade. Test Plan: PASS - Perform a subcloud installation. PASS - Perform a subcloud upgrade. Pass - Perform a subcloud reinstall. Story: 2010611 Task: 48367 Change-Id: I3dfee4e140c060597cbbdbb065c913fe0fcdfc73 Signed-off-by: Hugo Brito --- distributedcloud/dccommon/consts.py | 49 +++++++++++ distributedcloud/dccommon/install_consts.py | 29 ------- distributedcloud/dccommon/subcloud_install.py | 81 +++++-------------- .../dcmanager/api/controllers/v1/subclouds.py | 5 +- .../common/phased_subcloud_deploy.py | 16 +--- .../dcmanager/manager/subcloud_manager.py | 4 +- .../states/upgrade/upgrading_simplex.py | 26 ++---- .../unit/manager/test_subcloud_manager.py | 2 +- 8 files changed, 83 insertions(+), 129 deletions(-) delete mode 100644 distributedcloud/dccommon/install_consts.py diff --git a/distributedcloud/dccommon/consts.py b/distributedcloud/dccommon/consts.py index 541f72e66..853cc6a24 100644 --- a/distributedcloud/dccommon/consts.py +++ b/distributedcloud/dccommon/consts.py @@ -139,3 +139,52 @@ SUPPORTED_OS_TYPES = [OS_CENTOS, OS_DEBIAN] CERT_CA_FILE_CENTOS = "ca-cert.pem" CERT_CA_FILE_DEBIAN = "ca-cert.crt" SSL_CERT_CA_DIR = "/etc/pki/ca-trust/source/anchors/" + +# Subcloud installation values +BMC_INSTALL_VALUES = [ + 'bmc_username', + 'bmc_address', + 'bmc_password', +] + +MANDATORY_INSTALL_VALUES = [ + 'bootstrap_interface', + 'bootstrap_address', + 'bootstrap_address_prefix', + 'install_type', +] + BMC_INSTALL_VALUES + +OPTIONAL_INSTALL_VALUES = [ + 'nexthop_gateway', + 'network_address', + 'network_mask', + 'console_type', + 'bootstrap_vlan', + 'rootfs_device', + 'boot_device', + 'rd.net.timeout.ipv6dad', + 'no_check_certificate', + 'persistent_size', + 'hw_settle', + 'extra_boot_params', +] + +GEN_ISO_OPTIONS = { + 'bootstrap_interface': '--boot-interface', + 'bootstrap_address': '--boot-ip', + 'bootstrap_address_prefix': '--boot-netmask', + 'install_type': '--default-boot', + 'nexthop_gateway': "--boot-gateway", + 'rootfs_device': '--param', + 'boot_device': '--param', + 'rd.net.timeout.ipv6dad': '--param', + 'bootstrap_vlan': '--param', + 'no_check_certificate': '--param', + 'persistent_size': '--param', + 'hw_settle': '--param', + 'extra_boot_params': '--param', +} + +SUPPORTED_INSTALL_TYPES = 6 +ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK = \ + '/usr/share/ansible/stx-ansible/playbooks/install.yml' diff --git a/distributedcloud/dccommon/install_consts.py b/distributedcloud/dccommon/install_consts.py deleted file mode 100644 index e05bbe634..000000000 --- a/distributedcloud/dccommon/install_consts.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2020-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 -# -# 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. -# - -SUPPORTED_INSTALL_TYPES = 6 - -MANDATORY_INSTALL_VALUES = [ - 'bootstrap_interface', - 'bootstrap_address', - 'bootstrap_address_prefix', - 'bmc_address', - 'bmc_username', - 'bmc_password', - 'install_type' -] - -ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK = \ - '/usr/share/ansible/stx-ansible/playbooks/install.yml' diff --git a/distributedcloud/dccommon/subcloud_install.py b/distributedcloud/dccommon/subcloud_install.py index 1281e7794..3f9338c2f 100644 --- a/distributedcloud/dccommon/subcloud_install.py +++ b/distributedcloud/dccommon/subcloud_install.py @@ -13,22 +13,22 @@ # limitations under the License. # +import os +import shutil +import socket +import tempfile + from eventlet.green import subprocess import netaddr -import os from oslo_log import log as logging -import shutil from six.moves.urllib import error as urllib_error from six.moves.urllib import parse from six.moves.urllib import request -import socket -import tempfile from dccommon import consts from dccommon.drivers.openstack.keystone_v3 import KeystoneClient from dccommon.drivers.openstack.sysinv_v1 import SysinvClient from dccommon import exceptions -from dccommon import install_consts from dccommon import utils as dccommon_utils from dcmanager.common import consts as common_consts from dcmanager.common import utils @@ -55,43 +55,6 @@ NETWORK_INTERFACE_PREFIX = 'ifcfg' NETWORK_ROUTE_PREFIX = 'route' LOCAL_REGISTRY_PREFIX = 'registry.local:9001/' -OPTIONAL_INSTALL_VALUES = [ - 'nexthop_gateway', - 'network_address', - 'network_mask', - 'console_type', - 'bootstrap_vlan', - 'rootfs_device', - 'boot_device', - 'rd.net.timeout.ipv6dad', - 'no_check_certificate', - 'persistent_size', - 'hw_settle', - 'extra_boot_params', -] - -GEN_ISO_OPTIONS = { - 'bootstrap_interface': '--boot-interface', - 'bootstrap_address': '--boot-ip', - 'bootstrap_address_prefix': '--boot-netmask', - 'nexthop_gateway': "--boot-gateway", - 'install_type': '--default-boot', - 'rootfs_device': '--param', - 'boot_device': '--param', - 'rd.net.timeout.ipv6dad': '--param', - 'bootstrap_vlan': '--param', - 'no_check_certificate': '--param', - 'persistent_size': '--param', - 'hw_settle': '--param', - 'extra_boot_params': '--param', -} - -BMC_OPTIONS = { - 'bmc_address', - 'bmc_username', - 'bmc_password', -} - class SubcloudInstall(object): """Class to encapsulate the subcloud install operations""" @@ -210,7 +173,7 @@ class SubcloudInstall(object): with open(rvmc_config_file, 'w') as f_out_rvmc_config_file: for k, v in payload.items(): - if k in BMC_OPTIONS or k == 'image': + if k in consts.BMC_INSTALL_VALUES or k == 'image': f_out_rvmc_config_file.write(k + ': ' + v + '\n') def create_install_override_file(self, override_path, payload): @@ -349,48 +312,48 @@ class SubcloudInstall(object): "--timeout", BOOT_MENU_TIMEOUT, "--patches-from-iso", ] - for key in GEN_ISO_OPTIONS: + for key in consts.GEN_ISO_OPTIONS: if key in values: LOG.debug("Setting option from key=%s, option=%s, value=%s", - key, GEN_ISO_OPTIONS[key], values[key]) + key, consts.GEN_ISO_OPTIONS[key], values[key]) if key in ('bootstrap_address', 'nexthop_gateway'): - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], self.format_address(values[key])] elif key == 'no_check_certificate': if str(values[key]) == 'True' and self.get_https_enabled(): - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], 'inst.noverifyssl=True'] elif key in ('rootfs_device', 'boot_device', 'rd.net.timeout.ipv6dad'): - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], (key + '=' + str(values[key]))] elif key == 'bootstrap_vlan': vlan_inteface = "%s.%s:%s" % \ (values['bootstrap_interface'], values['bootstrap_vlan'], values['bootstrap_interface']) - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], ('vlan' + '=' + vlan_inteface)] elif (key == 'bootstrap_interface' and 'bootstrap_vlan' in values): boot_interface = "%s.%s" % (values['bootstrap_interface'], values['bootstrap_vlan']) - update_iso_cmd += [GEN_ISO_OPTIONS[key], boot_interface] + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], boot_interface] elif key == 'persistent_size': - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], ('persistent_size=%s' % str(values[key]))] elif key == 'hw_settle': # translate to 'insthwsettle' boot parameter - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], ('insthwsettle=%s' % str(values[key]))] elif key == 'extra_boot_params': - update_iso_cmd += [GEN_ISO_OPTIONS[key], + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], ('extra_boot_params=%s' % str(values[key]))] else: - update_iso_cmd += [GEN_ISO_OPTIONS[key], str(values[key])] + update_iso_cmd += [consts.GEN_ISO_OPTIONS[key], str(values[key])] if is_subcloud_debian: # Get the base URL. ostree_repo is located within this path @@ -542,13 +505,13 @@ class SubcloudInstall(object): """Update the iso image and create the config files for the subcloud""" LOG.info("Prepare for %s remote install" % (self.name)) iso_values = {} - for k in install_consts.MANDATORY_INSTALL_VALUES: - if k in list(GEN_ISO_OPTIONS.keys()): + for k in consts.MANDATORY_INSTALL_VALUES: + if k in list(consts.GEN_ISO_OPTIONS.keys()): iso_values[k] = payload.get(k) - if k not in BMC_OPTIONS: + if k not in consts.BMC_INSTALL_VALUES: iso_values[k] = payload.get(k) - for k in OPTIONAL_INSTALL_VALUES: + for k in consts.OPTIONAL_INSTALL_VALUES: if k in payload: iso_values[k] = payload.get(k) @@ -596,7 +559,7 @@ class SubcloudInstall(object): self.create_rvmc_config_file(override_path, payload) # remove the bmc values from the payload - for k in BMC_OPTIONS: + for k in consts.BMC_INSTALL_VALUES: if k in payload: del payload[k] diff --git a/distributedcloud/dcmanager/api/controllers/v1/subclouds.py b/distributedcloud/dcmanager/api/controllers/v1/subclouds.py index 827dac2e0..b49db8df4 100644 --- a/distributedcloud/dcmanager/api/controllers/v1/subclouds.py +++ b/distributedcloud/dcmanager/api/controllers/v1/subclouds.py @@ -45,7 +45,6 @@ from dccommon.drivers.openstack.patching_v1 import PatchingClient from dccommon.drivers.openstack.sdk_platform import OpenStackDriver from dccommon.drivers.openstack.sysinv_v1 import SysinvClient from dccommon import exceptions as dccommon_exceptions -from dccommon import install_consts from keystoneauth1 import exceptions as keystone_exceptions @@ -755,7 +754,7 @@ class SubcloudsController(object): ) pecan.abort(400, _(msg)) - for k in install_consts.MANDATORY_INSTALL_VALUES: + for k in dccommon_consts.MANDATORY_INSTALL_VALUES: if k not in install_values: if original_install_values: pecan.abort(400, _("Mandatory install value %s not present, " @@ -774,7 +773,7 @@ class SubcloudsController(object): payload['install_values'].update({'image': matching_iso}) if (install_values['install_type'] not in - list(range(install_consts.SUPPORTED_INSTALL_TYPES))): + list(range(dccommon_consts.SUPPORTED_INSTALL_TYPES))): pecan.abort(400, _("install_type invalid: %s") % install_values['install_type']) diff --git a/distributedcloud/dcmanager/common/phased_subcloud_deploy.py b/distributedcloud/dcmanager/common/phased_subcloud_deploy.py index d3974c302..39c2193ec 100644 --- a/distributedcloud/dcmanager/common/phased_subcloud_deploy.py +++ b/distributedcloud/dcmanager/common/phased_subcloud_deploy.py @@ -20,7 +20,6 @@ from dccommon.drivers.openstack import patching_v1 from dccommon.drivers.openstack.patching_v1 import PatchingClient from dccommon.drivers.openstack.sdk_platform import OpenStackDriver from dccommon.drivers.openstack.sysinv_v1 import SysinvClient -from dccommon import install_consts from dcmanager.common import consts from dcmanager.common import exceptions from dcmanager.common.i18n import _ @@ -510,7 +509,7 @@ def validate_install_values(payload, subcloud=None): pecan.abort(400, _("hw_settle of %s seconds is less than 0") % (str(hw_settle))) - for k in install_consts.MANDATORY_INSTALL_VALUES: + for k in dccommon_consts.MANDATORY_INSTALL_VALUES: if k not in install_values: if original_install_values: pecan.abort(400, _("Mandatory install value %s not present, " @@ -529,7 +528,7 @@ def validate_install_values(payload, subcloud=None): payload['install_values'].update({'image': matching_iso}) if (install_values['install_type'] not in - list(range(install_consts.SUPPORTED_INSTALL_TYPES))): + list(range(dccommon_consts.SUPPORTED_INSTALL_TYPES))): pecan.abort(400, _("install_type invalid: %s") % install_values['install_type']) @@ -818,16 +817,7 @@ def get_subcloud_db_install_values(subcloud): install_values = json.loads(subcloud.data_install) - # mandatory install parameters - mandatory_install_parameters = [ - 'bootstrap_interface', - 'bootstrap_address', - 'bootstrap_address_prefix', - 'bmc_username', - 'bmc_address', - 'bmc_password', - ] - for p in mandatory_install_parameters: + for p in dccommon_consts.MANDATORY_INSTALL_VALUES: if p not in install_values: msg = _("Failed to get %s from data_install" % p) LOG.exception(msg) diff --git a/distributedcloud/dcmanager/manager/subcloud_manager.py b/distributedcloud/dcmanager/manager/subcloud_manager.py index 5c337e0b0..ba52de907 100644 --- a/distributedcloud/dcmanager/manager/subcloud_manager.py +++ b/distributedcloud/dcmanager/manager/subcloud_manager.py @@ -77,8 +77,6 @@ ANSIBLE_SUBCLOUD_BACKUP_RESTORE_PLAYBOOK = \ '/usr/share/ansible/stx-ansible/playbooks/restore_subcloud_backup.yml' ANSIBLE_SUBCLOUD_PLAYBOOK = \ '/usr/share/ansible/stx-ansible/playbooks/bootstrap.yml' -ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK = \ - '/usr/share/ansible/stx-ansible/playbooks/install.yml' ANSIBLE_SUBCLOUD_REHOME_PLAYBOOK = \ '/usr/share/ansible/stx-ansible/playbooks/rehome_subcloud.yml' ANSIBLE_SUBCLOUD_UPDATE_PLAYBOOK = \ @@ -234,7 +232,7 @@ class SubcloudManager(manager.Manager): ansible_subcloud_inventory_file, software_version=None): install_command = [ - "ansible-playbook", ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, + "ansible-playbook", dccommon_consts.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, "-i", ansible_subcloud_inventory_file, "--limit", subcloud_name, "-e", "@%s" % consts.ANSIBLE_OVERRIDES_PATH + "/" + diff --git a/distributedcloud/dcmanager/orchestrator/states/upgrade/upgrading_simplex.py b/distributedcloud/dcmanager/orchestrator/states/upgrade/upgrading_simplex.py index da50da060..36b16c989 100644 --- a/distributedcloud/dcmanager/orchestrator/states/upgrade/upgrading_simplex.py +++ b/distributedcloud/dcmanager/orchestrator/states/upgrade/upgrading_simplex.py @@ -8,18 +8,15 @@ import keyring import os from oslo_serialization import base64 +from tsconfig.tsconfig import SW_VERSION -from dccommon.consts import AVAILABILITY_OFFLINE -from dccommon.install_consts import ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK +from dccommon import consts as dccommon_consts from dccommon.subcloud_install import SubcloudInstall - from dcmanager.common import consts from dcmanager.common import utils from dcmanager.db import api as db_api from dcmanager.orchestrator.states.base import BaseState -from tsconfig.tsconfig import SW_VERSION - class UpgradingSimplexState(BaseState): """Upgrade state for upgrading a simplex subcloud host""" @@ -238,20 +235,7 @@ class UpgradingSimplexState(BaseState): if persistent_size is not None: upgrade_data_install.update({'persistent_size': persistent_size}) - # optional bootstrap parameters - optional_bootstrap_parameters = [ - 'nexthop_gateway', # default route address - 'network_address', # static route address - 'network_mask', # static route mask - 'bootstrap_vlan', - 'wait_for_timeout', - 'no_check_certificate', - 'rd.net.timeout.ipv6dad', - 'hw_settle', - 'extra_boot_params', - ] - - for p in optional_bootstrap_parameters: + for p in dccommon_consts.OPTIONAL_INSTALL_VALUES: if p in data_install: upgrade_data_install.update({p: data_install.get(p)}) @@ -374,7 +358,7 @@ class UpgradingSimplexState(BaseState): # SubcloudInstall.prep creates data_install.yml (install overrides) install_command = [ - "ansible-playbook", ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, + "ansible-playbook", dccommon_consts.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, "-i", ansible_subcloud_inventory_file, "-e", "@%s" % consts.ANSIBLE_OVERRIDES_PATH + "/" + strategy_step.subcloud.name + '/' + "install_values.yml" @@ -383,7 +367,7 @@ class UpgradingSimplexState(BaseState): # Run the remote install playbook db_api.subcloud_update( self.context, strategy_step.subcloud_id, - availability_status=AVAILABILITY_OFFLINE, + availability_status=dccommon_consts.AVAILABILITY_OFFLINE, deploy_status=consts.DEPLOY_STATE_INSTALLING) try: install.install(consts.DC_ANSIBLE_LOG_DIR, install_command) diff --git a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py index 48c01a4e6..f55e2327c 100644 --- a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py +++ b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py @@ -1593,7 +1593,7 @@ class TestSubcloudManager(base.DCManagerTestCase): install_command, [ 'ansible-playbook', - subcloud_manager.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, + dccommon_consts.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK, '-i', f'{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1_inventory.yml', '--limit', 'subcloud1', '-e', f"@{consts.ANSIBLE_OVERRIDES_PATH}/subcloud1/install_values.yml",