Support extra-vars in bifrost-cli

Use it to provide git_url_root in the CI

Change-Id: I99a3a202125f5ca805030a2363729aa81c8f5b4e
This commit is contained in:
Dmitry Tantsur 2020-07-09 13:21:56 +02:00
parent be7f82e6c6
commit b67115d48c
3 changed files with 29 additions and 5 deletions

View File

@ -51,10 +51,15 @@ def log(*message, only_if=True):
print(*message, file=sys.stderr) print(*message, file=sys.stderr)
def ansible(playbook, inventory, verbose=False, env=None, **params): def ansible(playbook, inventory, verbose=False, env=None, extra_vars=None,
extra = COMMON_PARAMS + list(itertools.chain.from_iterable( **params):
extra = COMMON_PARAMS[:]
extra.extend(itertools.chain.from_iterable(
('-e', '%s=%s' % pair) for pair in params.items() ('-e', '%s=%s' % pair) for pair in params.items()
if pair[1] is not None)) if pair[1] is not None))
if extra_vars:
extra.extend(itertools.chain.from_iterable(
('-e', item) for item in extra_vars))
if verbose: if verbose:
extra.append('-vvvv') extra.append('-vvvv')
args = [ANSIBLE, playbook, '-i', inventory] + extra args = [ANSIBLE, playbook, '-i', inventory] + extra
@ -119,6 +124,7 @@ def cmd_testenv(args):
test_vm_domain_type=args.domain_type, test_vm_domain_type=args.domain_type,
baremetal_json_file=os.path.abspath(args.inventory), baremetal_json_file=os.path.abspath(args.inventory),
baremetal_nodes_json=os.path.abspath(args.output), baremetal_nodes_json=os.path.abspath(args.output),
extra_vars=args.extra_vars,
**kwargs) **kwargs)
log('Inventory generated in', args.output) log('Inventory generated in', args.output)
@ -157,6 +163,7 @@ def cmd_install(args):
testing=args.testenv, testing=args.testenv,
use_cirros=args.testenv, use_cirros=args.testenv,
use_tinyipa=args.testenv, use_tinyipa=args.testenv,
extra_vars=args.extra_vars,
**kwargs) **kwargs)
log("Ironic is installed and running, try it yourself:\n", log("Ironic is installed and running, try it yourself:\n",
" $ source %s/bin/activate\n" % VENV, " $ source %s/bin/activate\n" % VENV,
@ -190,6 +197,8 @@ def parse_args():
testenv.add_argument('--inventory', default='baremetal-inventory.json', testenv.add_argument('--inventory', default='baremetal-inventory.json',
help='output file with the inventory for using ' help='output file with the inventory for using '
'with dynamic playbooks') 'with dynamic playbooks')
testenv.add_argument('-e', '--extra-vars', action='append',
help='additional vars to pass to ansible')
testenv.add_argument('-o', '--output', default='baremetal-nodes.json', testenv.add_argument('-o', '--output', default='baremetal-nodes.json',
help='output file with the nodes information for ' help='output file with the nodes information for '
'importing into ironic') 'importing into ironic')
@ -217,6 +226,8 @@ def parse_args():
action='store_true', default=False, action='store_true', default=False,
help='enable full disk cleaning between ' help='enable full disk cleaning between '
'deployments (can take a lot of time)') 'deployments (can take a lot of time)')
install.add_argument('-e', '--extra-vars', action='append',
help='additional vars to pass to ansible')
args = parser.parse_args() args = parser.parse_args()
if getattr(args, 'func', None) is None: if getattr(args, 'func', None) is None:

View File

@ -0,0 +1,6 @@
---
features:
- |
Extra parameters for ansible can now be passed to ``bifrost-cli`` via
the ``-e``/``--extra-vars`` flag. The format is the same as for
ansible-playbook.

View File

@ -54,6 +54,10 @@ if [ "$ZUUL_BRANCH" != "" ]; then
VM_SETUP_EXTRA="--storage-pool-path /opt/libvirt/images" VM_SETUP_EXTRA="--storage-pool-path /opt/libvirt/images"
fi fi
if [ -d "${WORKSPACE:-}" ]; then
BIFROST_CLI_EXTRA="${BIFROST_CLI_EXTRA:-} --extra-vars copy_from_local_path=true"
fi
source $SCRIPT_HOME/env-setup.sh source $SCRIPT_HOME/env-setup.sh
# Note(cinerama): activate is not compatible with "set -u"; # Note(cinerama): activate is not compatible with "set -u";
@ -123,7 +127,9 @@ done
--memory ${VM_MEMORY_SIZE:-512} \ --memory ${VM_MEMORY_SIZE:-512} \
--disk ${VM_DISK:-5} \ --disk ${VM_DISK:-5} \
--inventory "${BAREMETAL_DATA_FILE}" \ --inventory "${BAREMETAL_DATA_FILE}" \
${VM_SETUP_EXTRA:-} --extra-vars git_url_root="${WORKSPACE:-https://opendev.org}" \
${VM_SETUP_EXTRA:-} \
${BIFROST_CLI_EXTRA:-}
if [ ${USE_DHCP} = "true" ]; then if [ ${USE_DHCP} = "true" ]; then
# reduce the number of nodes in JSON file # reduce the number of nodes in JSON file
@ -136,8 +142,9 @@ if [ ${USE_DHCP} = "true" ]; then
fi fi
if [ ${CLI_TEST} = "true" ]; then if [ ${CLI_TEST} = "true" ]; then
# FIXME(dtantsur): bifrost-cli does not use opendev-provided repos. ../bifrost-cli --debug install --testenv \
../bifrost-cli --debug install --testenv --extra-vars git_url_root="${WORKSPACE:-https://opendev.org}" \
${BIFROST_CLI_EXTRA:-}
fi fi
set +e set +e