diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..6e83df1a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/kolla-ansible"] + path = src/kolla-ansible + url = https://github.com/chameleoncloud/kolla-ansible diff --git a/cc-ansible b/cc-ansible index 7456f9ba..88d5f7f0 100755 --- a/cc-ansible +++ b/cc-ansible @@ -3,25 +3,16 @@ set -o errexit set -o nounset set -o pipefail -# set -o xtrace DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" VIRTUALENV="$(realpath "${VIRTUALENV:-"$DIR"/venv}")" -FORCE_UPDATES="${FORCE_UPDATES:-no}" -if [[ ! -d "$VIRTUALENV" ]]; then - echo "Creating virtualenv at $VIRTUALENV ..." - python3 -m venv "$VIRTUALENV" - "$VIRTUALENV/bin/pip" install --upgrade pip - FORCE_UPDATES=yes +if [ -f "${VIRTUALENV}/bin/activate" ]; then + # shellcheck source=/dev/null + source "${VIRTUALENV}/bin/activate" + # sourcing this will set the VIRTUAL_ENV, PATH, and PYTHON_HOME env vars fi -set +o nounset -# shellcheck disable=1090 # TODO use standard VIRTUAL_ENV and PATH method -source "$(realpath "$VIRTUALENV/bin/activate")" -set -o nounset - -CHECK_UPDATES=yes declare -a POSARGS=() declare -a TRAPS=() cleanup() { @@ -45,19 +36,13 @@ while [[ $# -gt 0 ]]; do # Add proper flag support for --check as an option for dry-runs export EXTRA_OPTS="${EXTRA_OPTS:-} --check" ;; - decrypt_passwords|edit_passwords|help|init|view_passwords) + decrypt_passwords|edit_passwords|help|install_deps|init|view_passwords) # Special subcommand! command="$key" ;; -h|--help) command=help ;; - --no-update) - CHECK_UPDATES=no - ;; - --force-update) - FORCE_UPDATES=yes - ;; *) POSARGS+=("$key") ;; @@ -70,6 +55,56 @@ done # Subcommands # +install_deps() { + # install kolla-ansible, perform updates if necessary. + + # create virtualenv + python3 -m venv "$VIRTUALENV" + # shellcheck source=/dev/null + source "${VIRTUALENV}/bin/activate" + + # upgrade pip and build tools + pip install --upgrade \ + pip \ + setuptools \ + wheel + + local pip_requirements="$DIR/requirements.txt" + pip install -r "${pip_requirements}" + + # update Ansible Galaxy roles and collections + local galaxy_requirements="$DIR/requirements.yml" + local galaxy_role_path="$DIR/galaxy.ansible.com/ansible_roles/" + ansible-galaxy role install --force -p "$galaxy_role_path" -r "$galaxy_requirements" + local galaxy_collection_path="$DIR/galaxy.ansible.com/" + ansible-galaxy collection install --force -p "$galaxy_collection_path" -r "$galaxy_requirements" + + local submodule_target_commit="$(git submodule status --cached src/kolla-ansible/)" + + echo "Checking if git submodules need updating" + if [ -z "$(git status --porcelain src/kolla-ansible)" ]; then + git submodule update --init src/kolla-ansible + else + echo "WARNING: you've made local changes to src/kolla-ansible, running install_deps will check out commit ${submodule_target_commit}" + echo "To proceed, either run 'git submodule update --init src/kolla-ansible', or commit the new submodule hash to chi-in-a-box" + git status src/kolla-ansible + return 1 + fi + + pip install \ + -r requirements.txt \ + --config-settings editable_mode=strict \ + -e src/kolla-ansible + + # Update/install yq, adding it to the venv bin path + YQ_VERSION=4.9.6 + if [[ "$(type -t yq)" != "file" ]]; then + YQ_BINARY="yq_linux_amd64" + wget https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - \ + | tar xz && mv ${YQ_BINARY} "$VIRTUALENV/bin/yq" + fi +} + init() { local site_config="$CC_ANSIBLE_SITE" @@ -187,10 +222,26 @@ USAGE exit 1 } +# install_deps creates the virtualenv. Exit early if it's not set up +if [ "${command:-}" == "install_deps" ]; then + : +elif [ -z "${VIRTUAL_ENV+x}" ]; then + # VIRTUAL_ENV is present if we have sourced a venv/bin/activate + cat < "$pip_requirements_chksum" +find_kolla_ansible_base_dir () { + kolla_direct_url="$(find ${VIRTUAL_ENV}/lib/python*/site-packages/ -wholename '*kolla_ansible*.dist-info/direct_url.json' -print -quit 1> /dev/null 2>&1)" + if test -n "${kolla_direct_url}"; then + # Editable install in local path + direct_url="$(yq eval '.url' ${kolla_direct_url})" + BASEDIR="${direct_url#file:\/\/}" + else + BASEDIR="${VIRTUAL_ENV}/share/kolla-ansible" fi - - # Update Ansible Galaxy roles - galaxy_collection_path="$DIR/galaxy.ansible.com/" - galaxy_role_path="$DIR/galaxy.ansible.com/ansible_roles/" - galaxy_role_requirements="$DIR/requirements.yml" - galaxy_role_requirements_chksum="$galaxy_role_path/requirements.yml.sha256" - if [[ "$FORCE_UPDATES" == "yes" || ! -f "$galaxy_role_requirements_chksum" ]] || \ - ! sha256sum --quiet --check "$galaxy_role_requirements_chksum"; then - ansible-galaxy role install --force -p "$galaxy_role_path" -r "$galaxy_role_requirements" - ansible-galaxy collection install --force -p "$galaxy_collection_path" -r "$galaxy_role_requirements" - sha256sum "$galaxy_role_requirements" > "$galaxy_role_requirements_chksum" - fi - - kolla_ansible_remote=https://github.com/chameleoncloud/kolla-ansible.git - kolla_ansible_checkout=${KOLLA_ANSIBLE_BRANCH:-chameleoncloud/xena} - kolla_ansible_gitref="$VIRTUALENV/kolla-ansible.gitref" - kolla_ansible_egglink="$VIRTUALENV/src/kolla-ansible" - if [[ "$FORCE_UPDATES" == "yes" || ! -f "$kolla_ansible_gitref" || ! -d "$kolla_ansible_egglink" ]] || \ - ! diff -q >/dev/null \ - "$kolla_ansible_gitref" \ - <(cd "$kolla_ansible_egglink"; git fetch; git show-ref -s -d origin/"$kolla_ansible_checkout"); then - pushd "$VIRTUALENV" || ( echo "pushd error!" && exit 1 ) - pip install -e git+"$kolla_ansible_remote"@"$kolla_ansible_checkout"#egg=kolla-ansible - popd || ( echo "popd error!" && exit 1 ) - # [jca 2020-01-30] TODO: - # Ensure the /share folder is placed; this is not copied when using the "develop" setup.py method. - # This is a bit weird, perhaps there is some way to pass an additional flag to pip to make it - # copy this even though it's installing as source. We use source install to keep track of the Git revision. - mkdir -p "$VIRTUALENV/share" && ln -sf "$kolla_ansible_egglink" "$VIRTUALENV/share/kolla-ansible" - (cd "$kolla_ansible_egglink"; git rev-parse HEAD > "$kolla_ansible_gitref") - fi - - # Update/install yq - YQ_VERSION=4.9.6 - if [[ "$(type -t yq)" != "file" ]]; then - YQ_BINARY="yq_linux_amd64" - wget https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - \ - | tar xz && mv ${YQ_BINARY} "$VIRTUALENV/bin/yq" - fi -fi - -ansible_path="$VIRTUALENV/share/kolla-ansible/ansible" + echo "${BASEDIR}/ansible" +} # Handle subcommands if [[ -n "${command:-}" ]]; then @@ -271,6 +281,7 @@ if [[ -n "${command:-}" ]]; then exit $? fi +ansible_path="$(find_kolla_ansible_base_dir)" if [[ -n "${CC_ANSIBLE_PLAYBOOK:-}" ]]; then echo "**********************************************************************" echo "* Playbook override detected! This playbook will be executed within *" diff --git a/docs/setup-guides/production-baremetal/quickstart.md b/docs/setup-guides/production-baremetal/quickstart.md index 79395fda..9f3dfad5 100644 --- a/docs/setup-guides/production-baremetal/quickstart.md +++ b/docs/setup-guides/production-baremetal/quickstart.md @@ -22,6 +22,15 @@ update-alternatives --install /usr/bin/python python /usr/bin/python3 1 {% endtab %} {% endtabs %} +### Initialize cc-ansible's virtualenv and deps + +* cc-ansible will install all of its own dependencies into a python virtualenv, located inside the chi-in-a-box git checkout directory. You'll need to do this before running other `cc-ansible` subcommands. + +```bash +./cc-ansible install_deps +``` + + ### Initialize the site configuration 1. Check out this repository: diff --git a/requirements.txt b/requirements.txt index 1015e580..4ab7ee3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,4 @@ # Xena release of Kolla-ansible requires ansible release between 2.10 and below 5.x, # This is because it depends on ansible-core 2.11.x # See https://docs.openstack.org/releasenotes/kolla-ansible/xena.html#relnotes-13-0-0-stable-xena-upgrade-notes -ansible>=2.10,<5 - -# ensure the version of pyopenssl installed is compatible with cryptography. May be resolved after ansible 5.x -# https://github.com/pyca/pyopenssl/issues/1114 -pyopenssl - -# Jinja2 3.1 breaks filters, removes py3.6 support -# See https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-0 -jinja2<3.1.0 -docker -kubernetes - -# Client Tools -python-openstackclient -python-doniclient -python-ironicclient -git+https://github.com/chameleoncloud/python-blazarclient@chameleoncloud/xena +ansible>=2.10,<5 \ No newline at end of file diff --git a/src/kolla-ansible b/src/kolla-ansible new file mode 160000 index 00000000..9c519ee9 --- /dev/null +++ b/src/kolla-ansible @@ -0,0 +1 @@ +Subproject commit 9c519ee9906bbeb4d429dbd312abe61f1b2a01de