ansible/test/integration/targets/ansible-galaxy/runme.sh

433 lines
14 KiB
Bash
Raw Normal View History

galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
#!/usr/bin/env bash
set -eux -o pipefail
ansible-playbook setup.yml "$@"
2018-02-10 19:48:44 +01:00
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
trap 'ansible-playbook ${ANSIBLE_PLAYBOOK_DIR}/cleanup.yml' EXIT
2019-10-17 15:21:08 +02:00
# Very simple version test
ansible-galaxy --version
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Need a relative custom roles path for testing various scenarios of -p
galaxy_relative_rolespath="my/custom/roles/path"
# Status message function (f_ to designate that it's a function)
f_ansible_galaxy_status()
{
printf "\n\n\n### Testing ansible-galaxy: %s\n" "${@}"
}
# Use to initialize a repository. Must call the post function too.
f_ansible_galaxy_create_role_repo_pre()
{
repo_name=$1
repo_dir=$2
pushd "${repo_dir}"
ansible-galaxy init "${repo_name}"
pushd "${repo_name}"
git init .
# Prep git, because it doesn't work inside a docker container without it
git config user.email "tester@ansible.com"
git config user.name "Ansible Tester"
# f_ansible_galaxy_create_role_repo_post
}
# Call after f_ansible_galaxy_create_repo_pre.
f_ansible_galaxy_create_role_repo_post()
{
repo_name=$1
repo_tar=$2
# f_ansible_galaxy_create_role_repo_pre
git add .
git commit -m "local testing ansible galaxy role"
git archive \
--format=tar \
--prefix="${repo_name}/" \
master > "${repo_tar}"
popd # "${repo_name}"
popd # "${repo_dir}"
}
# Prep the local git repos with role and make a tar archive so we can test
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# different things
galaxy_local_test_role="test-role"
galaxy_local_test_role_dir=$(mktemp -d)
galaxy_local_test_role_git_repo="${galaxy_local_test_role_dir}/${galaxy_local_test_role}"
galaxy_local_test_role_tar="${galaxy_local_test_role_dir}/${galaxy_local_test_role}.tar"
f_ansible_galaxy_create_role_repo_pre "${galaxy_local_test_role}" "${galaxy_local_test_role_dir}"
f_ansible_galaxy_create_role_repo_post "${galaxy_local_test_role}" "${galaxy_local_test_role_tar}"
galaxy_local_parent_role="parent-role"
galaxy_local_parent_role_dir=$(mktemp -d)
galaxy_local_parent_role_git_repo="${galaxy_local_parent_role_dir}/${galaxy_local_parent_role}"
galaxy_local_parent_role_tar="${galaxy_local_parent_role_dir}/${galaxy_local_parent_role}.tar"
# Create parent-role repository
f_ansible_galaxy_create_role_repo_pre "${galaxy_local_parent_role}" "${galaxy_local_parent_role_dir}"
cat <<EOF > meta/requirements.yml
- src: git+file:///${galaxy_local_test_role_git_repo}
EOF
f_ansible_galaxy_create_role_repo_post "${galaxy_local_parent_role}" "${galaxy_local_parent_role_tar}"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Galaxy install test case
#
# Install local git repo
f_ansible_galaxy_status "install of local git repo"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
ansible-galaxy install git+file:///"${galaxy_local_test_role_git_repo}" "$@"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Test that the role was installed to the expected directory
[[ -d "${HOME}/.ansible/roles/${galaxy_local_test_role}" ]]
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
rm -fr "${HOME}/.ansible/roles/${galaxy_local_test_role}"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Galaxy install test case
#
# Install local git repo and ensure that if a role_path is passed, it is in fact used
f_ansible_galaxy_status "install of local git repo with -p \$role_path"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
mkdir -p "${galaxy_relative_rolespath}"
ansible-galaxy install git+file:///"${galaxy_local_test_role_git_repo}" -p "${galaxy_relative_rolespath}" "$@"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Test that the role was installed to the expected directory
[[ -d "${galaxy_relative_rolespath}/${galaxy_local_test_role}" ]]
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
# Galaxy install test case
#
# Install local git repo with a meta/requirements.yml
f_ansible_galaxy_status "install of local git repo with meta/requirements.yml"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
ansible-galaxy install git+file:///"${galaxy_local_parent_role_git_repo}" "$@"
# Test that the role was installed to the expected directory
[[ -d "${HOME}/.ansible/roles/${galaxy_local_parent_role}" ]]
# Test that the dependency was also installed
[[ -d "${HOME}/.ansible/roles/${galaxy_local_test_role}" ]]
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
rm -fr "${HOME}/.ansible/roles/${galaxy_local_parent_role}"
rm -fr "${HOME}/.ansible/roles/${galaxy_local_test_role}"
# Galaxy install test case
#
# Install local git repo with a meta/requirements.yml + --no-deps argument
f_ansible_galaxy_status "install of local git repo with meta/requirements.yml + --no-deps argument"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
ansible-galaxy install git+file:///"${galaxy_local_parent_role_git_repo}" --no-deps "$@"
# Test that the role was installed to the expected directory
[[ -d "${HOME}/.ansible/roles/${galaxy_local_parent_role}" ]]
# Test that the dependency was not installed
[[ ! -d "${HOME}/.ansible/roles/${galaxy_local_test_role}" ]]
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
rm -fr "${HOME}/.ansible/roles/${galaxy_local_test_role}"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
# Galaxy install test case
#
# Ensure that if both a role_file and role_path is provided, they are both
# honored
#
# Protect against regression (GitHub Issue #35217)
# https://github.com/ansible/ansible/issues/35217
f_ansible_galaxy_status \
"install of local git repo and local tarball with -p \$role_path and -r \$role_file" \
"Protect against regression (Issue #35217)"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
git clone "${galaxy_local_test_role_git_repo}" "${galaxy_local_test_role}"
ansible-galaxy init roles-path-bug "$@"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
pushd roles-path-bug
cat <<EOF > ansible.cfg
[defaults]
roles_path = ../:../../:../roles:roles/
EOF
cat <<EOF > requirements.yml
---
- src: ${galaxy_local_test_role_tar}
name: ${galaxy_local_test_role}
EOF
ansible-galaxy install -r requirements.yml -p roles/ "$@"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
popd # roles-path-bug
# Test that the role was installed to the expected directory
[[ -d "${galaxy_testdir}/roles-path-bug/roles/${galaxy_local_test_role}" ]]
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
# Galaxy role list tests
#
# Basic tests to ensure listing roles works
f_ansible_galaxy_status "role list"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
ansible-galaxy install git+file:///"${galaxy_local_test_role_git_repo}" "$@"
ansible-galaxy role list | tee out.txt
ansible-galaxy role list test-role | tee -a out.txt
[[ $(grep -c '^- test-role' out.txt ) -eq 2 ]]
popd # ${galaxy_testdir}
# Galaxy role test case
#
# Test listing a specific role that is not in the first path in ANSIBLE_ROLES_PATH.
# https://github.com/ansible/ansible/issues/60167#issuecomment-585460706
f_ansible_galaxy_status \
"list specific role not in the first path in ANSIBLE_ROLES_PATH"
role_testdir=$(mktemp -d)
pushd "${role_testdir}"
mkdir testroles
ansible-galaxy role init --init-path ./local-roles quark
ANSIBLE_ROLES_PATH=./local-roles:${HOME}/.ansible/roles ansible-galaxy role list quark | tee out.txt
[[ $(grep -c 'not found' out.txt) -eq 0 ]]
ANSIBLE_ROLES_PATH=${HOME}/.ansible/roles:./local-roles ansible-galaxy role list quark | tee out.txt
[[ $(grep -c 'not found' out.txt) -eq 0 ]]
popd # ${role_testdir}
rm -fr "${role_testdir}"
# Galaxy role info tests
# Get info about role that is not installed
f_ansible_galaxy_status "role info"
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
ansible-galaxy role info samdoran.fish | tee out.txt
[[ $(grep -c 'not found' out.txt ) -eq 0 ]]
[[ $(grep -c 'Role:.*samdoran\.fish' out.txt ) -eq 1 ]]
popd # ${galaxy_testdir}
f_ansible_galaxy_status \
"role info non-existant role"
role_testdir=$(mktemp -d)
pushd "${role_testdir}"
ansible-galaxy role info notaroll | tee out.txt
grep -- '- the role notaroll was not found' out.txt
f_ansible_galaxy_status \
"role info description offline"
mkdir testroles
ansible-galaxy role init testdesc --init-path ./testroles
# Only galaxy_info['description'] exists in file
sed -i -e 's#[[:space:]]\{1,\}description:.*$# description: Description in galaxy_info#' ./testroles/testdesc/meta/main.yml
ansible-galaxy role info -p ./testroles --offline testdesc | tee out.txt
grep 'description: Description in galaxy_info' out.txt
# Both top level 'description' and galaxy_info['description'] exist in file
# Use shell-fu instead of sed to prepend a line to a file because BSD
# and macOS sed don't work the same as GNU sed.
echo 'description: Top level' | \
cat - ./testroles/testdesc/meta/main.yml > tmp.yml && \
mv tmp.yml ./testroles/testdesc/meta/main.yml
ansible-galaxy role info -p ./testroles --offline testdesc | tee out.txt
grep 'description: Top level' out.txt
# Only top level 'description' exists in file
sed -i.bak '/^[[:space:]]\{1,\}description: Description in galaxy_info/d' ./testroles/testdesc/meta/main.yml
ansible-galaxy role info -p ./testroles --offline testdesc | tee out.txt
grep 'description: Top level' out.txt
# test multiple role listing
ansible-galaxy role init otherrole --init-path ./testroles
ansible-galaxy role info -p ./testroles --offline testdesc otherrole | tee out.txt
grep 'Role: testdesc' out.txt
grep 'Role: otherrole' out.txt
popd # ${role_testdir}
rm -fr "${role_testdir}"
# Properly list roles when the role name is a subset of the path, or the role
# name is the same name as the parent directory of the role. Issue #67365
#
# ./parrot/parrot
# ./parrot/arr
# ./testing-roles/test
f_ansible_galaxy_status \
"list roles where the role name is the same or a subset of the role path (#67365)"
role_testdir=$(mktemp -d)
pushd "${role_testdir}"
mkdir parrot
ansible-galaxy role init --init-path ./parrot parrot
ansible-galaxy role init --init-path ./parrot parrot-ship
ansible-galaxy role init --init-path ./parrot arr
ansible-galaxy role list -p ./parrot | tee out.txt
[[ $(grep -Ec '\- (parrot|arr)' out.txt) -eq 3 ]]
ansible-galaxy role list test-role | tee -a out.txt
popd # ${role_testdir}
rm -rf "${role_testdir}"
f_ansible_galaxy_status \
"Test role with non-ascii characters"
role_testdir=$(mktemp -d)
pushd "${role_testdir}"
mkdir nonascii
ansible-galaxy role init --init-path ./nonascii nonascii
touch nonascii/ÅÑŚÌβŁÈ.txt
tar czvf nonascii.tar.gz nonascii
ansible-galaxy role install -p ./roles nonascii.tar.gz
popd # ${role_testdir}
rm -rf "${role_testdir}"
#################################
# ansible-galaxy collection tests
#################################
# TODO: Move these to ansible-galaxy-collection
galaxy_testdir=$(mktemp -d)
pushd "${galaxy_testdir}"
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
## ansible-galaxy collection list tests
# Create more collections and put them in various places
f_ansible_galaxy_status \
"setting up for collection list tests"
rm -rf ansible_test/* install/*
NAMES=(zoo museum airport)
for n in "${NAMES[@]}"; do
ansible-galaxy collection init "ansible_test.$n"
ansible-galaxy collection build "ansible_test/$n"
done
ansible-galaxy collection install ansible_test-zoo-1.0.0.tar.gz
ansible-galaxy collection install ansible_test-museum-1.0.0.tar.gz -p ./install
ansible-galaxy collection install ansible_test-airport-1.0.0.tar.gz -p ./local
# Change the collection version and install to another location
sed -i -e 's#^version:.*#version: 2.5.0#' ansible_test/zoo/galaxy.yml
ansible-galaxy collection build ansible_test/zoo
ansible-galaxy collection install ansible_test-zoo-2.5.0.tar.gz -p ./local
# Test listing a collection that contains a galaxy.yml
ansible-galaxy collection init "ansible_test.development"
mv ./ansible_test/development "${galaxy_testdir}/local/ansible_collections/ansible_test/"
export ANSIBLE_COLLECTIONS_PATH=~/.ansible/collections:${galaxy_testdir}/local
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
f_ansible_galaxy_status \
"collection list all collections"
ansible-galaxy collection list -p ./install | tee out.txt
[[ $(grep -c ansible_test out.txt) -eq 5 ]]
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
f_ansible_galaxy_status \
"collection list specific collection"
ansible-galaxy collection list -p ./install ansible_test.airport | tee out.txt
[[ $(grep -c 'ansible_test\.airport' out.txt) -eq 1 ]]
f_ansible_galaxy_status \
"collection list specific collection which contains galaxy.yml"
ansible-galaxy collection list -p ./install ansible_test.development 2>&1 | tee out.txt
[[ $(grep -c 'ansible_test\.development' out.txt) -eq 1 ]]
[[ $(grep -c 'WARNING' out.txt) -eq 0 ]]
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
f_ansible_galaxy_status \
"collection list specific collection found in multiple places"
ansible-galaxy collection list -p ./install ansible_test.zoo | tee out.txt
[[ $(grep -c 'ansible_test\.zoo' out.txt) -eq 2 ]]
f_ansible_galaxy_status \
"collection list all with duplicate paths"
ansible-galaxy collection list -p ~/.ansible/collections | tee out.txt
[[ $(grep -c '# /root/.ansible/collections/ansible_collections' out.txt) -eq 1 ]]
f_ansible_galaxy_status \
"collection list invalid collection name"
ansible-galaxy collection list -p ./install dirty.wraughten.name "$@" 2>&1 | tee out.txt || echo "expected failure"
grep 'ERROR! Invalid collection name' out.txt
f_ansible_galaxy_status \
"collection list path not found"
ansible-galaxy collection list -p ./nope "$@" 2>&1 | tee out.txt || echo "expected failure"
grep '\[WARNING\]: - the configured path' out.txt
f_ansible_galaxy_status \
"collection list missing ansible_collections dir inside path"
mkdir emptydir
ansible-galaxy collection list -p ./emptydir "$@"
rmdir emptydir
unset ANSIBLE_COLLECTIONS_PATH
Add ansible-galaxy collection list command (#65022) * Start adding ansible-galaxy collection list options * Working list all collections and list a specific collection * Nuke debugging cruft * Use to_text to get a string of the FQCN for sorting * Improve collection output formatting - add header - display collection name and version in separate columns - width of columns is dynamic based on collection name and version length * Make role list output match collection output list - add header - add columns for role name and version - make column width dynamic based on name and version length * remove debug statemnt and extra header * Revert "Make role list output match collection output list" This reverts commit a0b3db47bb3b198aafd34c1f1be5b6561af2f928. * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Use validate_collection_path * Do not warn if a specific collection in found in any search path * Fix extraneous warning and remove duplicate code Do not warn when listing a specific collection and it does not exist in other collection paths. Restructure the code that loops through collection paths to remove duplicate conditional code. * Indicate role path was found * Use new function name * WIP Save Point * Use separate functions for role and collection list * Wrap error message There may be a better way to do this besides hard coding a line break, but this does make the message a lot more readable. * Add validate_collection_path function (#66441) * Add validate_collection_path function Utility function for ensuring a collection target ends with 'ansible_collection' * Fix bad syntax * Correct docstring * Bikeshed the names * Properly list a single role * Simplify _display_warnings() Only display warnings. Move exception raise back to each caller. * Move private methods to private functions They don't need self, so it makes sense to have them as functions Get rid of _display_warnings() function since it doesn't do anything worthy of an independent function. * Add integration tests for ansible-galaxy collection list * Fix docs sanity test * Fix bug where ansible_collections dir does not exist The path may exist, but if there is no ansible_collections dir inside that path, an exception was raised in find_existing_collections(). Add integration test for this scenario * Put execute_list() method back * Add some informational messages for debugging * Add unit tests Units tests for the various private methods in support of collection list * Start adding unit tests for test_execute_list * Display collection path when listing specific collection * Add unit tests for listing all collections and specific collection - Create fixture for creating test objects - Add function for controlling os.path.isdir results * Set defaults for minimum collection widths Ensure that collections with small FQCNs display correctly. Add unit tests * Split up unit tests and fix fixtures Add more fixtures for mocking objects during the specific collection tests * Change help message for -p in list subcommand Give accurate description of what it actually does rather than trying to use language shared between sub commands. * Disable colorized output in unit test * Add docs for collection list * Fix integration test on macOS The temp file path is really long on macOS, so the warning message gets wrapped across multiple lines. That make seth grep fail. Switch to matching on a smaller part of the warning. * Recreate common path options for collections Improve help about what the '-p' option does and how it works. * Remove unnecessary elif after continue statements * Account for duplicate paths in collections_searh_paths If someone specifies the same path via '-p' that is the COLLECTIONS_PATHS, do not list the collections twice. * Docs updates
2020-02-14 21:00:00 +01:00
## end ansible-galaxy collection list
popd # ${galaxy_testdir}
rm -fr "${galaxy_testdir}"
galaxy remove incorrect check for role path before extraction (#35259) * galaxy remove incorrect check for role path before extraction Fixes #35217 Currently lib/ansible/galaxy/role.py checks roles_path and will ignore paths that don't currently exist which it should not because the path will attempt to be created by the role extraction process (which is valid and expected behavior) and if unable to write at the time of role extraction into the role_path, that error will be handled properly at that point in the process. Signed-off-by: Adam Miller <admiller@redhat.com> * add test case for galaxy install with rolefile and rolepath Verify we don't regress GitHub Issue #35217 Signed-off-by: Adam Miller <admiller@redhat.com> * fix the integration test Signed-off-by: Adam Miller <admiller@redhat.com> * double quote for shellcheck glob warning Signed-off-by: Adam Miller <admiller@redhat.com> * fix galaxy install tests to not need remote resources Signed-off-by: Adam Miller <admiller@redhat.com> * make shellcheck sanity tests happy Signed-off-by: Adam Miller <admiller@redhat.com> * prep git global conf for running the galaxy install tests in docker Signed-off-by: Adam Miller <admiller@redhat.com> * move ansible-galaxy tests into their own target, make git conf non-global Signed-off-by: Adam Miller <admiller@redhat.com> * fix up tests based on feedback Signed-off-by: Adam Miller <admiller@redhat.com> * remove extra newline from aliases file Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-30 17:40:25 +01:00
rm -fr "${galaxy_local_test_role_dir}"