Update playbooks to use consistent working dir
Updates the cli-enable-ssh-admin.yaml and cli-grant-local-access.yaml ansible playbook executions to use the consistent working directory instead of a temporary directory. Adds reproduce_command=True to the calls to utils.run_ansible_playbook so that the workflows can be re-run out of the deployment for reproducability. Change-Id: Id4880be3a0d936e67bfc77ed28145eb1b9de162e Signed-off-by: James Slagle <jslagle@redhat.com>
This commit is contained in:
parent
12d9efbdae
commit
b7b934b6ea
|
@ -1387,7 +1387,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
# assuming heat deploy consumed a 3m out of total 451m timeout
|
||||
with mock.patch('time.time', side_effect=[1585820346,
|
||||
12345678, 0, 0,
|
||||
1585820526, 0]):
|
||||
1585820526, 0,
|
||||
0, 0, 0]):
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.assertIn([
|
||||
mock.call(
|
||||
|
|
|
@ -232,6 +232,7 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
workdir=mock.ANY,
|
||||
playbook_dir='/usr/share/ansible/tripleo-playbooks',
|
||||
verbosity=mock.ANY,
|
||||
reproduce_command=True,
|
||||
extra_vars={
|
||||
'access_path': os.path.join(os.environ.get('HOME'),
|
||||
'config-download'),
|
||||
|
|
|
@ -80,6 +80,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.cmd.working_dir = mock.Mock()
|
||||
self.cmd.take_action(parsed_args)
|
||||
mock_usercheck.assert_called_once()
|
||||
|
||||
|
@ -93,6 +94,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
parsed_args.overcloud_ssh_user,
|
||||
mock.ANY,
|
||||
parsed_args.overcloud_ssh_port_timeout,
|
||||
self.cmd.working_dir,
|
||||
mock.ANY
|
||||
)
|
||||
|
||||
|
|
|
@ -39,5 +39,6 @@ class TestAdminAuthorize(test_plugin.TestPluginV1):
|
|||
parsed_args.overcloud_ssh_user,
|
||||
mock.ANY,
|
||||
parsed_args.overcloud_ssh_port_timeout,
|
||||
self.cmd.working_dir,
|
||||
mock.ANY
|
||||
)
|
||||
|
|
|
@ -36,13 +36,14 @@ class TestDeploymentWorkflows(utils.TestCommand):
|
|||
shutil.rmtree(deployment.DEFAULT_WORK_DIR)
|
||||
deployment.DEFAULT_WORK_DIR = self.orig_workdir
|
||||
|
||||
@mock.patch('os.path.join')
|
||||
@mock.patch('shutil.rmtree')
|
||||
@mock.patch('os.chdir')
|
||||
@mock.patch('tripleoclient.utils.tempfile')
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_enable_ssh_admin(self, mock_rmtree, mock_chdir, mock_tempfile,
|
||||
mock_playbook):
|
||||
def test_enable_ssh_admin(self, mock_playbook, mock_tempfile,
|
||||
mock_chdir, mock_rmtree, mock_join):
|
||||
hosts = 'a', 'b', 'c'
|
||||
ssh_user = 'test-user'
|
||||
ssh_key = 'test-key'
|
||||
|
@ -53,7 +54,8 @@ class TestDeploymentWorkflows(utils.TestCommand):
|
|||
hosts,
|
||||
ssh_user,
|
||||
ssh_key,
|
||||
timeout
|
||||
timeout,
|
||||
mock.Mock()
|
||||
)
|
||||
|
||||
# once for ssh-keygen, then twice per host
|
||||
|
|
|
@ -69,6 +69,13 @@ class Authorize(command.Command):
|
|||
type=int,
|
||||
default=constants.ENABLE_SSH_ADMIN_SSH_PORT_TIMEOUT
|
||||
)
|
||||
parser.add_argument(
|
||||
'--working-dir',
|
||||
action='store',
|
||||
help=_('The working directory for the deployment where all '
|
||||
'input, output, and generated files will be stored.\n'
|
||||
'Defaults to "$HOME/overcloud-deploy/<stack>"')
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -78,11 +85,19 @@ class Authorize(command.Command):
|
|||
self.log.debug("take_action({})".format(parsed_args))
|
||||
clients = self.app.client_manager
|
||||
stack = oooutils.get_stack(clients.orchestration, parsed_args.stack)
|
||||
|
||||
if not parsed_args.working_dir:
|
||||
self.working_dir = oooutils.get_default_working_dir(
|
||||
parsed_args.stack)
|
||||
else:
|
||||
self.working_dir = parsed_args.working_dir
|
||||
|
||||
deployment.get_hosts_and_enable_ssh_admin(
|
||||
stack,
|
||||
parsed_args.overcloud_ssh_network,
|
||||
parsed_args.overcloud_ssh_user,
|
||||
self.get_key_pair(parsed_args),
|
||||
parsed_args.overcloud_ssh_port_timeout,
|
||||
working_dir=self.working_dir,
|
||||
verbosity=oooutils.playbook_verbosity(self=self)
|
||||
)
|
||||
|
|
|
@ -1157,6 +1157,7 @@ class DeployOvercloud(command.Command):
|
|||
parsed_args.overcloud_ssh_user,
|
||||
self.get_key_pair(parsed_args),
|
||||
parsed_args.overcloud_ssh_port_timeout,
|
||||
self.working_dir,
|
||||
verbosity=utils.playbook_verbosity(self=self),
|
||||
heat_type=parsed_args.heat_type
|
||||
)
|
||||
|
|
|
@ -105,6 +105,7 @@ class UpgradePrepare(DeployOvercloud):
|
|||
parsed_args.overcloud_ssh_user,
|
||||
self.get_key_pair(parsed_args),
|
||||
parsed_args.overcloud_ssh_port_timeout,
|
||||
working_dir=self.working_dir,
|
||||
verbosity=oooutils.playbook_verbosity(self=self)
|
||||
)
|
||||
|
||||
|
|
|
@ -139,7 +139,8 @@ def get_overcloud_hosts(stack, ssh_network):
|
|||
def get_hosts_and_enable_ssh_admin(stack, overcloud_ssh_network,
|
||||
overcloud_ssh_user, overcloud_ssh_key,
|
||||
overcloud_ssh_port_timeout,
|
||||
verbosity=0, heat_type='installed'):
|
||||
working_dir, verbosity=0,
|
||||
heat_type='installed'):
|
||||
"""Enable ssh admin access.
|
||||
|
||||
Get a list of hosts from a given stack and enable admin ssh across all of
|
||||
|
@ -172,6 +173,7 @@ def get_hosts_and_enable_ssh_admin(stack, overcloud_ssh_network,
|
|||
overcloud_ssh_user,
|
||||
overcloud_ssh_key,
|
||||
overcloud_ssh_port_timeout,
|
||||
working_dir,
|
||||
verbosity=verbosity,
|
||||
heat_type=heat_type
|
||||
)
|
||||
|
@ -185,7 +187,7 @@ def get_hosts_and_enable_ssh_admin(stack, overcloud_ssh_network,
|
|||
|
||||
|
||||
def enable_ssh_admin(stack, hosts, ssh_user, ssh_key, timeout,
|
||||
verbosity=0, heat_type='installed'):
|
||||
working_dir, verbosity=0, heat_type='installed'):
|
||||
"""Run enable ssh admin access playbook.
|
||||
|
||||
:param stack: Stack data.
|
||||
|
@ -220,22 +222,25 @@ def enable_ssh_admin(stack, hosts, ssh_user, ssh_key, timeout,
|
|||
try:
|
||||
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
||||
tc_heat_utils.heatclient.save_environment()
|
||||
with utils.TempDirs() as tmp:
|
||||
utils.run_ansible_playbook(
|
||||
playbook='cli-enable-ssh-admin.yaml',
|
||||
inventory=','.join(hosts),
|
||||
workdir=tmp,
|
||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
key=ssh_key,
|
||||
ssh_user=ssh_user,
|
||||
verbosity=verbosity,
|
||||
extra_vars={
|
||||
"ssh_user": ssh_user,
|
||||
"ssh_servers": hosts,
|
||||
'tripleo_cloud_name': stack.stack_name
|
||||
},
|
||||
ansible_timeout=timeout
|
||||
)
|
||||
playbook = 'cli-enable-ssh-admin.yaml'
|
||||
ansible_work_dir = os.path.join(
|
||||
working_dir, os.path.splitext(playbook)[0])
|
||||
utils.run_ansible_playbook(
|
||||
playbook=playbook,
|
||||
inventory=','.join(hosts),
|
||||
workdir=ansible_work_dir,
|
||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
key=ssh_key,
|
||||
ssh_user=ssh_user,
|
||||
verbosity=verbosity,
|
||||
reproduce_command=True,
|
||||
extra_vars={
|
||||
"ssh_user": ssh_user,
|
||||
"ssh_servers": hosts,
|
||||
'tripleo_cloud_name': stack.stack_name
|
||||
},
|
||||
ansible_timeout=timeout
|
||||
)
|
||||
finally:
|
||||
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
||||
tc_heat_utils.heatclient.restore_environment()
|
||||
|
@ -350,18 +355,21 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
|||
else:
|
||||
skip_tags = 'opendev-validation'
|
||||
|
||||
with utils.TempDirs() as tmp:
|
||||
utils.run_ansible_playbook(
|
||||
playbook='cli-grant-local-access.yaml',
|
||||
inventory='localhost,',
|
||||
workdir=tmp,
|
||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
verbosity=verbosity,
|
||||
extra_vars={
|
||||
'access_path': output_dir,
|
||||
'execution_user': getpass.getuser()
|
||||
}
|
||||
)
|
||||
playbook = 'cli-grant-local-access.yaml'
|
||||
ansible_work_dir = os.path.join(
|
||||
working_dir, os.path.splitext(playbook)[0])
|
||||
utils.run_ansible_playbook(
|
||||
playbook=playbook,
|
||||
inventory='localhost,',
|
||||
workdir=ansible_work_dir,
|
||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
verbosity=verbosity,
|
||||
reproduce_command=True,
|
||||
extra_vars={
|
||||
'access_path': output_dir,
|
||||
'execution_user': getpass.getuser()
|
||||
}
|
||||
)
|
||||
|
||||
_log_and_print(
|
||||
message='Checking for blacklisted hosts from stack: {}'.format(
|
||||
|
@ -387,7 +395,7 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
|||
ansible_work_dir = os.path.join(
|
||||
working_dir, os.path.splitext(playbook)[0])
|
||||
utils.run_ansible_playbook(
|
||||
playbook='cli-config-download.yaml',
|
||||
playbook=playbook,
|
||||
inventory='localhost,',
|
||||
workdir=ansible_work_dir,
|
||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
|
|
Loading…
Reference in New Issue