Integrate SubcloudEnrollmentInit with SubcloudManager
Incorporate enrollment init (reconfiguration) within the overall enrollment process. This involves updating SubcloudManager to initiate enroll-init using the previously introduced SubcloudEnrollmentInit class. Test plan: - PASS: Verify end-to-end enrollment upto init-enroll-complete state - Initiate enrollment from dcmanager (subcloud add --enroll) and ensure the subcloud progresses through the enrollment init states and successfully reaches the pre- enroll state. (ensure state transitions: pre-init-enroll, initiating-enroll, init-enroll-complete, and pre-enroll) - PASS: Verify standalone node enrollment reconfiguration: - Check `openstack endpoint-list`, public endpoints must be updated with the new OAM address. - Check `system oam-show` to verify the OAM address. - Ensure the password is changed. Depends-on: https://review.opendev.org/c/starlingx/ansible-playbooks/+/922363 Story: 2011100 Task: 50389 Change-Id: I8df100ac888978b2b6a18aa3f449aef95909f7a2 Signed-off-by: Salman Rana <salman.rana@windriver.com>
This commit is contained in:
parent
9f90f52cfd
commit
9375d59e99
@ -76,6 +76,23 @@ class SubcloudEnrollmentInit(object):
|
||||
|
||||
return True
|
||||
|
||||
def create_enroll_override_file(self, override_path, payload):
|
||||
enroll_override_file = os.path.join(override_path,
|
||||
'enroll_overrides.yml')
|
||||
|
||||
with open(enroll_override_file, 'w') as f_out_override_file:
|
||||
f_out_override_file.write(
|
||||
'---'
|
||||
'\nenroll_reconfigured_oam: ' +
|
||||
payload['external_oam_floating_address'] + '\n'
|
||||
)
|
||||
|
||||
enroll_overrides = payload['install_values'].get('enroll_overrides', {})
|
||||
|
||||
if enroll_overrides:
|
||||
for k, v in enroll_overrides.items():
|
||||
f_out_override_file.write(f'{k}: {v}')
|
||||
|
||||
def _build_seed_user_config(self, path, iso_values):
|
||||
if not os.path.isdir(path):
|
||||
msg = f'No directory exists: {path}'
|
||||
@ -196,11 +213,18 @@ class SubcloudEnrollmentInit(object):
|
||||
# get the boot image url for bmc
|
||||
image_base_url = SubcloudInstall.get_image_base_url(self.get_https_enabled(),
|
||||
self.sysinv_client)
|
||||
payload['image'] = os.path.join(image_base_url, 'iso',
|
||||
software_version, 'nodes',
|
||||
self.name, consts.ENROLL_INIT_SEED_ISO_NAME)
|
||||
bmc_values = {
|
||||
'bmc_username': payload['install_values']['bmc_username'],
|
||||
'bmc_password': payload['bmc_password'],
|
||||
'bmc_address': payload['install_values']['bmc_address']
|
||||
}
|
||||
bmc_values['image'] = os.path.join(image_base_url, 'iso',
|
||||
software_version, 'nodes',
|
||||
self.name, consts.ENROLL_INIT_SEED_ISO_NAME)
|
||||
|
||||
SubcloudInstall.create_rvmc_config_file(override_path, payload)
|
||||
SubcloudInstall.create_rvmc_config_file(override_path, bmc_values)
|
||||
|
||||
self.create_enroll_override_file(override_path, payload)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -344,8 +344,21 @@ class SubcloudManager(manager.Manager):
|
||||
state):
|
||||
|
||||
if state == "init":
|
||||
LOG.info(f'Initiating enroll for subcloud: {subcloud_name}')
|
||||
return True
|
||||
enroll_command = [
|
||||
"ansible-playbook",
|
||||
dccommon_consts.ANSIBLE_SUBCLOUD_INSTALL_PLAYBOOK,
|
||||
"-i", ansible_subcloud_inventory_file,
|
||||
"--limit", subcloud_name,
|
||||
"-e", "@%s" % dccommon_consts.ANSIBLE_OVERRIDES_PATH + "/" +
|
||||
subcloud_name + '/' + "enroll_overrides.yml",
|
||||
"-e", "install_release_version=%s" %
|
||||
software_version if software_version else SW_VERSION,
|
||||
"-e", "rvmc_config_file=%s" %
|
||||
os.path.join(dccommon_consts.ANSIBLE_OVERRIDES_PATH,
|
||||
subcloud_name,
|
||||
dccommon_consts.RVMC_CONFIG_FILE_NAME)]
|
||||
|
||||
return enroll_command
|
||||
elif state == "enroll":
|
||||
extra_vars = "override_files_dir='%s' region_name=%s" % (
|
||||
dccommon_consts.ANSIBLE_OVERRIDES_PATH, subcloud_region)
|
||||
@ -1590,8 +1603,6 @@ class SubcloudManager(manager.Manager):
|
||||
)
|
||||
|
||||
subcloud = db_api.subcloud_get(context, subcloud_id)
|
||||
enrollment = SubcloudEnrollmentInit(subcloud.name)
|
||||
enrollment.prep(dccommon_consts.ANSIBLE_OVERRIDES_PATH, payload)
|
||||
|
||||
if self.subcloud_init_enroll(context, subcloud.id, payload):
|
||||
try:
|
||||
@ -1807,16 +1818,21 @@ class SubcloudManager(manager.Manager):
|
||||
:return: success status
|
||||
"""
|
||||
|
||||
# Retrieve the subcloud details from the database
|
||||
subcloud = db_api.subcloud_update(
|
||||
context,
|
||||
subcloud_id,
|
||||
deploy_status=consts.DEPLOY_STATE_INITIATING_ENROLL,
|
||||
data_install=json.dumps(payload['install_values']))
|
||||
subcloud = db_api.subcloud_get(context, subcloud_id)
|
||||
|
||||
LOG.info("Initiating subcloud %s enrollment." % subcloud.name)
|
||||
|
||||
try:
|
||||
enrollment = SubcloudEnrollmentInit(subcloud.name)
|
||||
enrollment.prep(dccommon_consts.ANSIBLE_OVERRIDES_PATH, payload)
|
||||
|
||||
# Retrieve the subcloud details from the database
|
||||
subcloud = db_api.subcloud_update(
|
||||
context,
|
||||
subcloud_id,
|
||||
deploy_status=consts.DEPLOY_STATE_INITIATING_ENROLL,
|
||||
data_install=json.dumps(payload['install_values']))
|
||||
|
||||
# TODO(glyraper): log_file to be used in the playbook execution
|
||||
# log_file = (
|
||||
# os.path.join(consts.DC_ANSIBLE_LOG_DIR, subcloud.name)
|
||||
@ -1827,7 +1843,7 @@ class SubcloudManager(manager.Manager):
|
||||
init_enroll_command = self._deploy_install_prep(
|
||||
subcloud, payload, ansible_subcloud_inventory_file,
|
||||
init_enroll=True)
|
||||
if init_enroll_command:
|
||||
if enrollment.enroll_init(consts.DC_ANSIBLE_LOG_DIR, init_enroll_command):
|
||||
LOG.info('Subcloud enrollment initial phase successful '
|
||||
f'for subcloud {subcloud.name}')
|
||||
|
||||
|
@ -1384,9 +1384,13 @@ class TestSubcloudDeploy(BaseTestSubcloudManager):
|
||||
|
||||
@mock.patch.object(subcloud_enrollment.SubcloudEnrollmentInit,
|
||||
'prep')
|
||||
@mock.patch.object(subcloud_enrollment.SubcloudEnrollmentInit,
|
||||
'enroll_init')
|
||||
@mock.patch.object(cutils, 'get_region_name')
|
||||
def test_subcloud_deploy_enroll_run_playbook_failed(
|
||||
self, mock_get_region_name, mock_subcloud_enrollment_prep):
|
||||
self, mock_get_region_name,
|
||||
mock_subcloud_enrollment_prep,
|
||||
mock_subcloud_enrollment_enroll_init):
|
||||
|
||||
self.mock_ansible_run_playbook.side_effect = PlaybookExecutionFailed()
|
||||
mock_get_region_name.return_value = "11111"
|
||||
|
Loading…
Reference in New Issue
Block a user