Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Roles tests against Role/Collection installed from Ansible Galaxy #75

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions roles/conjur_host_identity/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ RUN apt-get update && \
RUN apt-get update && apt-get install -y gcc build-essential
RUN apt-add-repository -y ppa:brightbox/ruby-ng && apt-get update && apt-get install -y ruby2.4 ruby2.4-dev
RUN gem install conjur-cli

# install Ansible Conjur Collection
RUN ansible-galaxy collection install cyberark.conjur && \
ansible-galaxy install cyberark.conjur-host-identity
Comment on lines +45 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about this, some considerations...

  1. This repo should really be testing its own source code, instead of what is on Ansible Galaxy
  2. The standalone role is separate to the collection, and I think any test for it should reside in the standalone role's repo. All that to maintain a separation of concerns.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For (1) I think if we want a smoke test to ensure that we can always install the role from galaxy then we should define that separate to the tests that currently exist.

1 change: 0 additions & 1 deletion roles/conjur_host_identity/tests/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ host_key_checking = False
error_on_undefined_vars = True
timeout = 60
inventory = inventory.tmp
roles_path = /cyberark
remote_tmp = /tmp
2 changes: 1 addition & 1 deletion roles/conjur_host_identity/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ services:
# see https://docs.ansible.com/ansible/latest/reference_appendices/config.html#avoiding-security-risks-with-ansible-cfg-in-the-current-directory.
ANSIBLE_CONFIG: ./ansible.cfg
volumes:
- ..:/cyberark/cyberark.conjur.conjur-host-identity/
- .:/cyberark/tests/
- /var/run/docker.sock:/var/run/docker.sock

pg:
image: postgres:9.3

Expand Down
8 changes: 5 additions & 3 deletions roles/conjur_host_identity/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ function setup_conjur {

function run_test_cases {
for test_case in test_cases/*; do
teardown_and_setup
run_test_case "$(basename -- "$test_case")"
if [ "${test_case}" != "test_cases/common" ]; then
teardown_and_setup
run_test_case "$(basename -- "$test_case")"
fi
done
}

Expand All @@ -71,7 +73,7 @@ function run_test_case {
"
docker exec "${ansible_cid}" bash -ec "
cd tests
py.test --junitxml=./junit/${test_case} --connection docker -v test_cases/${test_case}/tests/test_default.py
py.test --junitxml=./junit/${test_case} --connection docker -v test_cases/common/test_default.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially my feedback was going to be. Let's add a comment up top to clarify why we avoid this folder, and a comment here to clarify that the common folder contains the code for the shared common test cases. Now I'm thinking that we should perhaps

  1. Have common folder that has those common test cases in test_default.py
  2. Retain the convention/interface of each test case needing to specify a test_default.py so that line 76 statys as
py.test --junitxml=./junit/${test_case} --connection docker -v test_cases/common/test_default.py
  1. In each test case's test_default.py it can just import (1)

"
else
echo ERROR: run_test called with no argument 1>&2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Configuring conjur identity on remote hosts
hosts: testapp
roles:
- role: "cyberark.conjur.conjur-host-identity"
- role: cyberark.conjur.conjur_host_identity
conjur_account: cucumber
conjur_appliance_url: "https://conjur-proxy-nginx"
conjur_host_factory_token: "{{lookup('env', 'HFTOKEN')}}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Configuring conjur identity on remote hosts from Role
hosts: testapp
roles:
- role: cyberark.conjur-host-identity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea how this is still working given the role name constraints ?

conjur_account: cucumber
conjur_appliance_url: "https://conjur-proxy-nginx"
conjur_host_factory_token: "{{lookup('env', 'HFTOKEN')}}"
conjur_host_name: "conjur_{{ ansible_hostname }}"
conjur_ssl_certificate: "{{lookup('file', '../../conjur.pem')}}"
conjur_validate_certs: yes