Support passing additional function arguments to kolla-ansible
This commit is contained in:
parent
447b678e3e
commit
efed119813
@ -89,7 +89,7 @@ def _validate_args(parsed_args, inventory_filename):
|
||||
|
||||
|
||||
def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
||||
tags=None, verbose_level=None):
|
||||
tags=None, verbose_level=None, extra_args=None):
|
||||
"""Build arguments required for running Kolla Ansible."""
|
||||
venv_activate = os.path.join(parsed_args.kolla_venv, "bin", "activate")
|
||||
cmd = ["source", venv_activate, "&&"]
|
||||
@ -113,17 +113,20 @@ def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
||||
if parsed_args.kolla_tags or tags:
|
||||
all_tags = [t for t in [parsed_args.kolla_tags, tags] if t]
|
||||
cmd += ["--tags", ",".join(all_tags)]
|
||||
if extra_args:
|
||||
cmd += extra_args
|
||||
return cmd
|
||||
|
||||
|
||||
def run(parsed_args, command, inventory_filename, extra_vars=None,
|
||||
tags=None, quiet=False, verbose_level=None):
|
||||
tags=None, quiet=False, verbose_level=None, extra_args=None):
|
||||
"""Run a Kolla Ansible command."""
|
||||
_validate_args(parsed_args, inventory_filename)
|
||||
cmd = build_args(parsed_args, command,
|
||||
inventory_filename=inventory_filename,
|
||||
extra_vars=extra_vars, tags=tags,
|
||||
verbose_level=verbose_level)
|
||||
verbose_level=verbose_level,
|
||||
extra_args=extra_args)
|
||||
try:
|
||||
utils.run_command(" ".join(cmd), quiet=quiet, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
@ -152,7 +152,8 @@ class TestCase(unittest.TestCase):
|
||||
kwargs = {
|
||||
"extra_vars": {"ev_name2": "ev_value2"},
|
||||
"tags": "tag3,tag4",
|
||||
"verbose_level": 1
|
||||
"verbose_level": 1,
|
||||
"extra_args": ["--arg1", "--arg2"],
|
||||
}
|
||||
kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs)
|
||||
expected_cmd = [
|
||||
@ -163,6 +164,7 @@ class TestCase(unittest.TestCase):
|
||||
"-e", "ev_name1=ev_value1",
|
||||
"-e", "ev_name2=ev_value2",
|
||||
"--tags", "tag1,tag2,tag3,tag4",
|
||||
"--arg1", "--arg2",
|
||||
]
|
||||
expected_cmd = " ".join(expected_cmd)
|
||||
mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
|
||||
|
Loading…
Reference in New Issue
Block a user