Merge "Add the subcloud deploy config option to dcmanager"

This commit is contained in:
Zuul 2023-06-27 16:25:39 +00:00 committed by Gerrit Code Review
commit 03fd4552b1
4 changed files with 100 additions and 1 deletions

View File

@ -48,3 +48,9 @@ class phased_subcloud_deploy_manager(base.ResourceManager):
files = kwargs.get('files')
url = BASE_URL + "%s/bootstrap" % subcloud_ref
return self._deploy_operation(url, files, data, "patch")
def subcloud_deploy_config(self, subcloud_ref, **kwargs):
data = kwargs.get('data')
files = kwargs.get('files')
url = BASE_URL + "%s/configure" % subcloud_ref
return self._deploy_operation(url, files, data, method='patch')

View File

@ -186,3 +186,66 @@ class BootstrapPhasedSubcloudDeploy(base.DCManagerShowOne):
return dcmanager_client.subcloud_deploy_bootstrap(
subcloud_ref, files=files, data=data)
class ConfigPhasedSubcloudDeploy(base.DCManagerShowOne):
"""Configure a subcloud."""
def _get_format_function(self):
return utils.subcloud_detail_format
def get_parser(self, prog_name):
parser = super(ConfigPhasedSubcloudDeploy, self).get_parser(prog_name)
parser.add_argument(
'subcloud',
help='Name or ID of the subcloud to update.'
)
parser.add_argument(
'--deploy-config',
required=False,
help='YAML file containing subcloud variables to be passed to the '
'deploy playbook.'
)
parser.add_argument(
'--sysadmin-password',
required=False,
help='sysadmin password of the subcloud to be configured, '
'if not provided you will be prompted.'
)
return parser
def _get_resources(self, parsed_args):
subcloud_ref = parsed_args.subcloud
dcmanager_client = self.app.client_manager.\
phased_subcloud_deploy_manager.phased_subcloud_deploy_manager
files = dict()
data = dict()
# Get the deploy config yaml file
if parsed_args.deploy_config is not None:
if not os.path.isfile(parsed_args.deploy_config):
error_msg = "deploy-config file does not exist: %s" % \
parsed_args.deploy_config
raise exceptions.DCManagerClientException(error_msg)
files['deploy_config'] = parsed_args.deploy_config
# Prompt the user for the subcloud's password if it isn't provided
if parsed_args.sysadmin_password is not None:
data['sysadmin_password'] = base64.b64encode(
parsed_args.sysadmin_password.encode("utf-8"))
else:
password = utils.prompt_for_password()
data["sysadmin_password"] = base64.b64encode(
password.encode("utf-8"))
try:
return dcmanager_client.subcloud_deploy_config(
subcloud_ref=subcloud_ref, files=files, data=data)
except Exception as e:
print(e)
error_msg = "Unable to configure subcloud %s" % (subcloud_ref)
raise exceptions.DCManagerClientException(error_msg)

View File

@ -546,6 +546,7 @@ class DCManagerShell(app.App):
'subcloud-group update': gm.UpdateSubcloudGroup,
'subcloud deploy create': psdm.CreatePhasedSubcloudDeploy,
'subcloud deploy bootstrap': psdm.BootstrapPhasedSubcloudDeploy,
'subcloud deploy config': psdm.ConfigPhasedSubcloudDeploy,
'subcloud-deploy upload': sdm.SubcloudDeployUpload,
'subcloud-deploy show': sdm.SubcloudDeployShow,
'alarm summary': am.ListAlarmSummary,

View File

@ -4,11 +4,13 @@
# SPDX-License-Identifier: Apache-2.0
#
import mock
import os
import tempfile
import mock
from dcmanagerclient.commands.v1 import phased_subcloud_deploy_manager as cmd
from dcmanagerclient.exceptions import DCManagerClientException
from dcmanagerclient.tests import base
@ -57,3 +59,30 @@ class TestCLIPhasedSubcloudDeployManagerV1(base.BaseCommandTest):
'--bootstrap-values', bootstrap_file_path,
])
self.assertEqual(base.SUBCLOUD_FIELD_RESULT_LIST, actual_call[1])
@mock.patch('getpass.getpass', return_value='testpassword')
def test_success_configure_subcloud(self, getpass):
self.client.subcloud_deploy_config.return_value = [
base.SUBCLOUD_RESOURCE]
with tempfile.NamedTemporaryFile() as f:
file_path = os.path.abspath(f.name)
actual_call = self.call(
cmd.ConfigPhasedSubcloudDeploy,
app_args=[base.NAME, '--deploy-config', file_path])
self.assertEqual(base.SUBCLOUD_FIELD_RESULT_LIST, actual_call[1])
@mock.patch('getpass.getpass', return_value='testpassword')
def test_configure_file_does_not_exist(self, getpass):
self.client.subcloud_deploy_config.return_value = [
base.SUBCLOUD_RESOURCE]
with tempfile.NamedTemporaryFile() as f:
file_path = os.path.abspath(f.name)
e = self.assertRaises(DCManagerClientException,
self.call,
cmd.ConfigPhasedSubcloudDeploy,
app_args=[base.NAME,
'--deploy-config', file_path])
self.assertTrue('deploy-config file does not exist' in str(e))