Use ansible playbook for creating overcloudrc

This uses the new playbook to create the rc files.

Depends-On: https://review.opendev.org/725511
Change-Id: I6fe6d2f7f2c41214e501daf4fc16673f1ab47472
changes/13/725513/2
Rabi Mishra 3 years ago
parent 5951a20650
commit 6268bdea73

@ -51,9 +51,6 @@ class UtilsOvercloudFixture(fixtures.Fixture):
self.mock_utils_endpoint = self.useFixture(fixtures.MockPatch(
'tripleoclient.utils.get_overcloud_endpoint')
).mock
self.mock_create_ocrc = self.useFixture(fixtures.MockPatch(
'tripleoclient.utils.write_overcloudrc')
).mock
self.mock_update_deployment_status = self.useFixture(
fixtures.MockPatch(
'tripleoclient.utils.update_deployment_status')

@ -28,31 +28,18 @@ class TestOvercloudCredentials(test_plugin.TestPluginV1):
self.tripleoclient = mock.Mock()
self.app.client_manager.tripleoclient = self.tripleoclient
self.rc_action_patcher = mock.patch(
'tripleo_common.actions.deployment.OvercloudRcAction',
autospec=True)
self.mock_rc_action = self.rc_action_patcher.start()
self.addCleanup(self.rc_action_patcher.stop)
@mock.patch('os.chmod')
def test_ok(self, mock_chmod):
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
def test_ok(self, mock_run_playbook):
arglist = ['overcloud', ]
verifylist = [
('plan', 'overcloud'),
('directory', '.')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
with mock.patch("tripleoclient.utils.open", create=True) as m:
self.cmd.take_action(parsed_args)
self.assertIn(mock.call('./overcloudrc', 'w'), m.call_args_list)
mock_chmod.assert_has_calls([
mock.call('./overcloudrc', 384)])
self.check_parser(self.cmd, arglist, verifylist)
@mock.patch('os.chmod')
def test_okay_custom_dir(self, mock_chmod):
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
def test_okay_custom_dir(self, mock_run_playbook):
temp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, temp)
@ -62,13 +49,4 @@ class TestOvercloudCredentials(test_plugin.TestPluginV1):
('plan', 'overcloud'),
('directory', temp)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
with mock.patch("tripleoclient.utils.open", create=True) as m:
self.cmd.take_action(parsed_args)
path = "{}/overcloudrc".format(temp)
self.assertIn(mock.call(path, 'w'), m.call_args_list)
mock_chmod.assert_has_calls([
mock.call(path, 384)])
self.check_parser(self.cmd, arglist, verifylist)

@ -268,6 +268,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
object_client.put_container.assert_called_once_with(
'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'})
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('tripleoclient.utils.copy_clouds_yaml')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_get_undercloud_host_entry', autospec=True,
@ -289,7 +291,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_get_template_contents, mock_validate_args,
mock_breakpoints_cleanup, mock_postconfig,
mock_invoke_plan_env_wf,
mock_get_undercloud_host_entry, mock_copy):
mock_get_undercloud_host_entry,
mock_copy, mock_overcloudrc):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
@ -404,7 +407,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
@mock.patch('tempfile.mkdtemp', autospec=True)
def test_tht_deploy_with_plan_environment_file(
self, mock_tmpdir, mock_get_template_contents,
mock_write_overcloudrc,
mock_overcloudrc,
mock_create_tempest_deployer, mock_create_parameters_env,
mock_validate_args,
mock_breakpoints_cleanup,
@ -519,6 +522,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
object_client.put_container.assert_called_once_with(
'overcloud', headers={'x-container-meta-usage-tripleo': 'plan'})
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('os.chdir')
@mock.patch('tripleoclient.utils.copy_clouds_yaml')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
@ -545,7 +550,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_create_parameters_env, mock_validate_args,
mock_breakpoints_cleanup,
mock_postconfig, mock_deprecated_params, mock_stack_network_check,
mock_get_undercloud_host_entry, mock_copy, mock_chdir):
mock_get_undercloud_host_entry, mock_copy,
mock_chdir, mock_overcloudrc):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
plane_management_fixture = deployment.PlanManagementFixture()
@ -993,7 +999,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.assertFalse(utils_fixture.mock_deploy_tht.called)
self.assertFalse(utils_fixture.mock_create_ocrc.called)
self.assertFalse(mock_create_tempest_deployer_input.called)
@mock.patch('tripleoclient.utils.copy_clouds_yaml')
@ -1038,13 +1043,13 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
test_answerfile = self.tmp_dir.join('answerfile')
with open(test_answerfile, 'w') as answerfile:
yaml.dump(
{'templates':
'/usr/share/openstack-tripleo-heat-templates/',
'environments': [test_env]
},
answerfile
)
yaml.dump(
{'templates':
'/usr/share/openstack-tripleo-heat-templates/',
'environments': [test_env]
},
answerfile
)
arglist = ['--answers-file', test_answerfile,
'--environment-file', test_env2,
@ -1065,7 +1070,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.cmd.take_action(parsed_args)
self.assertTrue(mock_heat_deploy.called)
self.assertTrue(utils_fixture.mock_create_ocrc.called)
self.assertTrue(utils_fixture.mock_deploy_tht.called)
# Check that Heat was called with correct parameters:
@ -1089,14 +1093,12 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
@mock.patch('tripleoclient.utils.check_stack_network_matches_env_files')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_create_parameters_env', autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc')
@mock.patch('heatclient.common.template_utils.'
'process_environment_and_files', autospec=True)
@mock.patch('heatclient.common.template_utils.get_template_contents',
autospec=True)
def test_ntp_server_mandatory(self, mock_get_template_contents,
mock_process_env,
mock_write_overcloudrc,
mock_create_parameters_env,
mock_stack_network_check,
mock_get_undercloud_host_entry):
@ -1426,14 +1428,13 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
@mock.patch('tripleoclient.utils.create_tempest_deployer_input',
autospec=True)
@mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_tripleo_heat_templates_tmpdir', autospec=True)
def test_config_download_fails(
self, mock_deploy_tmpdir,
mock_overcloudrc, mock_write_overcloudrc,
mock_overcloudrc,
mock_overcloud_endpoint,
mock_create_tempest_deployer_input,
mock_get_undercloud_host_entry):

@ -42,7 +42,6 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare):
'get_hosts_and_enable_ssh_admin', autospec=True)
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@mock.patch('tripleoclient.utils.prepend_environment', autospec=True)
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@ -67,7 +66,6 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare):
mock_logger,
mock_get_stack,
mock_prepend_env,
mock_write_overcloudrc,
mock_overcloudrc,
mock_enable_ssh_admin,
mock_overcloud_deploy):
@ -92,10 +90,7 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare):
container='mystack',
)
mock_overcloudrc.assert_called_once_with(mock.ANY,
container="mystack")
mock_write_overcloudrc.assert_called_once_with("mystack",
mock.ANY)
mock_overcloudrc.assert_called_once_with(container="mystack")
mock_enable_ssh_admin.assert_called_once_with(
mock_stack,
parsed_args.overcloud_ssh_network,

@ -44,7 +44,6 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
'get_hosts_and_enable_ssh_admin', autospec=True)
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True)
@mock.patch('tripleoclient.utils.prepend_environment', autospec=True)
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@ -68,7 +67,6 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
mock_logger,
mock_get_stack,
add_env,
mock_write_overcloudrc,
mock_overcloudrc,
mock_enable_ssh_admin,
mock_overcloud_deploy):
@ -96,10 +94,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
container='overcloud',
)
mock_overcloudrc.assert_called_once_with(mock.ANY,
container="overcloud")
mock_write_overcloudrc.assert_called_once_with("overcloud",
mock.ANY)
mock_overcloudrc.assert_called_once_with(container="overcloud")
mock_overcloud_deploy.assert_called_once_with(parsed_args)
mock_enable_ssh_admin.assert_called_once_with(
mock_stack,

@ -13,7 +13,6 @@
import logging
from tripleoclient import command
from tripleoclient import utils
from tripleoclient.workflows import deployment
@ -33,10 +32,5 @@ class OvercloudCredentials(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
plan = parsed_args.plan
dir_ = parsed_args.directory
overcloudrcs = deployment.create_overcloudrc(clients, container=plan)
utils.write_overcloudrc(plan, overcloudrcs, dir_)
deployment.create_overcloudrc(container=parsed_args.plan,
output_dir=parsed_args.directory)

@ -609,7 +609,7 @@ class DeployOvercloud(command.Command):
if parsed_args.deployed_server and (parsed_args.run_validations
or not parsed_args.disable_validations):
raise oscexc.CommandError(
raise oscexc.CommandError(
"Error: The --deployed-server cannot be used without "
"the --disable-validations")
@ -1090,14 +1090,12 @@ class DeployOvercloud(command.Command):
# Force fetching of attributes
stack.get()
overcloudrcs = deployment.create_overcloudrc(
self.clients, container=stack.stack_name,
no_proxy=parsed_args.no_proxy)
rcpath = deployment.create_overcloudrc(container=stack.stack_name,
no_proxy=parsed_args.no_proxy)
# Copy clouds.yaml to the cloud user directory
user = getpwuid(os.stat(constants.CLOUD_HOME_DIR).st_uid).pw_name
utils.copy_clouds_yaml(user)
rcpath = utils.write_overcloudrc(stack.stack_name, overcloudrcs)
utils.create_tempest_deployer_input()
# Run postconfig on create or force. Use force to makes sure endpoints

@ -81,9 +81,7 @@ class FFWDUpgradePrepare(DeployOvercloud):
clients, container=stack_name,
container_config='{}-config'.format(stack.stack_name))
overcloudrcs = deployment.create_overcloudrc(
clients, container=stack_name)
oooutils.write_overcloudrc(stack_name, overcloudrcs)
deployment.create_overcloudrc(container=stack_name)
# refresh stack info and enable ssh admin for Ansible-via-Mistral
stack = oooutils.get_stack(clients.orchestration, parsed_args.stack)

@ -77,9 +77,7 @@ class UpgradePrepare(DeployOvercloud):
clients, container=stack_name,
container_config='{}-config'.format(stack.stack_name))
overcloudrcs = deployment.create_overcloudrc(
clients, container=stack_name)
oooutils.write_overcloudrc(stack_name, overcloudrcs)
deployment.create_overcloudrc(container=stack_name)
# refresh stack info and enable ssh admin for Ansible-via-Mistral
stack = oooutils.get_stack(clients.orchestration, parsed_args.stack)

@ -22,10 +22,10 @@ from openstackclient import shell
from swiftclient import exceptions as swiftexceptions
from tripleo_common.actions import ansible
from tripleo_common.actions import config
from tripleo_common.actions import deployment
from tripleo_common.utils import swift as swift_utils
from tripleoclient.constants import ANSIBLE_TRIPLEO_PLAYBOOKS
from tripleoclient.constants import CLOUD_HOME_DIR
from tripleoclient.constants import DEFAULT_WORK_DIR
from tripleoclient import exceptions
from tripleoclient import utils
@ -130,9 +130,23 @@ def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
raise exceptions.DeploymentError("Heat Stack update failed.")
def create_overcloudrc(clients, container="overcloud", no_proxy=''):
context = clients.tripleoclient.create_mistral_context()
return deployment.OvercloudRcAction(container, no_proxy).run(context)
def create_overcloudrc(container="overcloud", no_proxy='',
output_dir=CLOUD_HOME_DIR, verbosity=0):
with utils.TempDirs() as tmp:
utils.run_ansible_playbook(
"cli-generate-overcloudrc.yaml",
'undercloud,',
workdir=tmp,
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=verbosity,
extra_vars={
"container": container,
"no_proxy": no_proxy,
"output_dir": output_dir,
}
)
rcpath = os.path.join(output_dir, container + 'rc')
return rcpath
def get_overcloud_hosts(stack, ssh_network):

Loading…
Cancel
Save