Merge "Use consistent working dir for ansible-runner"
This commit is contained in:
commit
b887ff62ad
|
@ -216,6 +216,7 @@ class FakeClientWrapper(object):
|
||||||
|
|
||||||
class FakeRunnerConfig(object):
|
class FakeRunnerConfig(object):
|
||||||
env = dict() # noqa
|
env = dict() # noqa
|
||||||
|
artifact_dir = ''
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -63,6 +63,8 @@ class TestRunAnsiblePlaybook(TestCase):
|
||||||
'overcloud'
|
'overcloud'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
ansible_runner.Runner.stdout = mock.MagicMock()
|
||||||
|
ansible_runner.Runner.stdout.read = mock.MagicMock(return_value='')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
utils.constants.DEFAULT_WORK_DIR = self.orig_workdir
|
utils.constants.DEFAULT_WORK_DIR = self.orig_workdir
|
||||||
|
|
|
@ -244,6 +244,7 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
||||||
playbook_dir='/usr/share/ansible/tripleo-playbooks',
|
playbook_dir='/usr/share/ansible/tripleo-playbooks',
|
||||||
verbosity=mock.ANY,
|
verbosity=mock.ANY,
|
||||||
extra_vars=mock.ANY,
|
extra_vars=mock.ANY,
|
||||||
|
reproduce_command=True,
|
||||||
),
|
),
|
||||||
mock.call(
|
mock.call(
|
||||||
playbook=mock.ANY,
|
playbook=mock.ANY,
|
||||||
|
|
|
@ -373,7 +373,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
|
||||||
)
|
)
|
||||||
return ansible_runner.utils.dump_artifact(
|
return ansible_runner.utils.dump_artifact(
|
||||||
inventory,
|
inventory,
|
||||||
ansible_artifact_path,
|
workdir,
|
||||||
constants.ANSIBLE_HOSTS_FILENAME
|
constants.ANSIBLE_HOSTS_FILENAME
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -708,6 +708,14 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
|
||||||
_log_path = r_opts['envvars']['ANSIBLE_LOG_PATH']
|
_log_path = r_opts['envvars']['ANSIBLE_LOG_PATH']
|
||||||
if os.path.isfile(_log_path):
|
if os.path.isfile(_log_path):
|
||||||
os.chown(_log_path, get_uid, -1)
|
os.chown(_log_path, get_uid, -1)
|
||||||
|
# Save files we care about
|
||||||
|
with open(os.path.join(workdir, 'stdout'), 'w') as f:
|
||||||
|
f.write(runner.stdout.read())
|
||||||
|
for output in 'status', 'rc':
|
||||||
|
val = getattr(runner, output)
|
||||||
|
if val:
|
||||||
|
with open(os.path.join(workdir, output), 'w') as f:
|
||||||
|
f.write(str(val))
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
err_msg = (
|
err_msg = (
|
||||||
|
|
|
@ -1066,7 +1066,8 @@ class DeployOvercloud(command.Command):
|
||||||
overcloud_endpoint = utils.get_overcloud_endpoint(stack)
|
overcloud_endpoint = utils.get_overcloud_endpoint(stack)
|
||||||
horizon_url = deployment.get_horizon_url(
|
horizon_url = deployment.get_horizon_url(
|
||||||
stack=stack.stack_name,
|
stack=stack.stack_name,
|
||||||
heat_type=parsed_args.heat_type)
|
heat_type=parsed_args.heat_type,
|
||||||
|
working_dir=self.working_dir)
|
||||||
rc_params = utils.get_rc_params(
|
rc_params = utils.get_rc_params(
|
||||||
self.orchestration_client,
|
self.orchestration_client,
|
||||||
parsed_args.stack)
|
parsed_args.stack)
|
||||||
|
|
|
@ -255,7 +255,8 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
||||||
ansible_playbook_name='deploy_steps_playbook.yaml',
|
ansible_playbook_name='deploy_steps_playbook.yaml',
|
||||||
limit_hosts=None, extra_vars=None, inventory_path=None,
|
limit_hosts=None, extra_vars=None, inventory_path=None,
|
||||||
ssh_user='tripleo-admin', tags=None, skip_tags=None,
|
ssh_user='tripleo-admin', tags=None, skip_tags=None,
|
||||||
deployment_timeout=None, forks=None, setup_only=False):
|
deployment_timeout=None, forks=None, setup_only=False,
|
||||||
|
working_dir=None):
|
||||||
"""Run config download.
|
"""Run config download.
|
||||||
|
|
||||||
:param log: Logging object
|
:param log: Logging object
|
||||||
|
@ -317,6 +318,10 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
||||||
:param setup_only: Only generates the config-download directory
|
:param setup_only: Only generates the config-download directory
|
||||||
without executing the actual playbooks.
|
without executing the actual playbooks.
|
||||||
:type setup_only: Boolean
|
:type setup_only: Boolean
|
||||||
|
|
||||||
|
:param working_dir: Consistent working directory used for generated
|
||||||
|
ansible files.
|
||||||
|
:type working_dir: String
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _log_and_print(message, logger, level='info', print_msg=True):
|
def _log_and_print(message, logger, level='info', print_msg=True):
|
||||||
|
@ -344,6 +349,9 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
||||||
if not output_dir:
|
if not output_dir:
|
||||||
output_dir = DEFAULT_WORK_DIR
|
output_dir = DEFAULT_WORK_DIR
|
||||||
|
|
||||||
|
if not working_dir:
|
||||||
|
working_dir = utils.get_default_working_dir(stack.stack_name)
|
||||||
|
|
||||||
if not deployment_options:
|
if not deployment_options:
|
||||||
deployment_options = dict()
|
deployment_options = dict()
|
||||||
|
|
||||||
|
@ -386,23 +394,26 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
||||||
key_file = utils.get_key(stack.stack_name)
|
key_file = utils.get_key(stack.stack_name)
|
||||||
python_interpreter = deployment_options.get('ansible_python_interpreter')
|
python_interpreter = deployment_options.get('ansible_python_interpreter')
|
||||||
|
|
||||||
with utils.TempDirs() as tmp:
|
playbook = 'cli-config-download.yaml'
|
||||||
utils.run_ansible_playbook(
|
ansible_work_dir = os.path.join(
|
||||||
playbook='cli-config-download.yaml',
|
working_dir, os.path.splitext(playbook)[0])
|
||||||
inventory='localhost,',
|
utils.run_ansible_playbook(
|
||||||
workdir=tmp,
|
playbook='cli-config-download.yaml',
|
||||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
inventory='localhost,',
|
||||||
verbosity=verbosity,
|
workdir=ansible_work_dir,
|
||||||
extra_vars={
|
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||||
'plan': stack.stack_name,
|
verbosity=verbosity,
|
||||||
'output_dir': output_dir,
|
reproduce_command=True,
|
||||||
'ansible_ssh_user': ssh_user,
|
extra_vars={
|
||||||
'ansible_ssh_private_key_file': key_file,
|
'plan': stack.stack_name,
|
||||||
'ssh_network': ssh_network,
|
'output_dir': output_dir,
|
||||||
'python_interpreter': python_interpreter,
|
'ansible_ssh_user': ssh_user,
|
||||||
'inventory_path': inventory_path
|
'ansible_ssh_private_key_file': key_file,
|
||||||
}
|
'ssh_network': ssh_network,
|
||||||
)
|
'python_interpreter': python_interpreter,
|
||||||
|
'inventory_path': inventory_path
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# If we only want to generate config-download directory, we can quit here.
|
# If we only want to generate config-download directory, we can quit here.
|
||||||
if setup_only:
|
if setup_only:
|
||||||
|
@ -484,7 +495,8 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
|
||||||
|
|
||||||
|
|
||||||
def get_horizon_url(stack, verbosity=0,
|
def get_horizon_url(stack, verbosity=0,
|
||||||
heat_type='installed'):
|
heat_type='installed',
|
||||||
|
working_dir=None):
|
||||||
"""Return horizon URL string.
|
"""Return horizon URL string.
|
||||||
|
|
||||||
:params stack: Stack name
|
:params stack: Stack name
|
||||||
|
@ -495,26 +507,29 @@ def get_horizon_url(stack, verbosity=0,
|
||||||
try:
|
try:
|
||||||
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
||||||
tc_heat_utils.heatclient.save_environment()
|
tc_heat_utils.heatclient.save_environment()
|
||||||
with utils.TempDirs() as tmp:
|
playbook = 'cli-undercloud-get-horizon-url.yaml'
|
||||||
horizon_tmp_file = os.path.join(tmp, 'horizon_url')
|
ansible_work_dir = os.path.join(
|
||||||
utils.run_ansible_playbook(
|
working_dir, os.path.splitext(playbook)[0])
|
||||||
playbook='cli-undercloud-get-horizon-url.yaml',
|
horizon_file = os.path.join(ansible_work_dir, 'horizon_url')
|
||||||
inventory='localhost,',
|
utils.run_ansible_playbook(
|
||||||
workdir=tmp,
|
playbook=playbook,
|
||||||
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
inventory='localhost,',
|
||||||
verbosity=verbosity,
|
workdir=ansible_work_dir,
|
||||||
extra_vars={
|
playbook_dir=ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||||
'stack_name': stack,
|
verbosity=verbosity,
|
||||||
'horizon_url_output_file': horizon_tmp_file
|
reproduce_command=True,
|
||||||
}
|
extra_vars={
|
||||||
)
|
'stack_name': stack,
|
||||||
|
'horizon_url_output_file': horizon_file
|
||||||
with open(horizon_tmp_file) as f:
|
}
|
||||||
return f.read().strip()
|
)
|
||||||
finally:
|
finally:
|
||||||
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
if heat_type != 'installed' and tc_heat_utils.heatclient:
|
||||||
tc_heat_utils.heatclient.restore_environment()
|
tc_heat_utils.heatclient.restore_environment()
|
||||||
|
|
||||||
|
with open(horizon_file) as f:
|
||||||
|
return f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
def get_deployment_status(clients, stack_name, working_dir):
|
def get_deployment_status(clients, stack_name, working_dir):
|
||||||
"""Return current deployment status."""
|
"""Return current deployment status."""
|
||||||
|
|
Loading…
Reference in New Issue