From 5c9dc33e415c7dc28db330099236fa2ffcdf009e Mon Sep 17 00:00:00 2001 From: James Laska Date: Wed, 12 Mar 2014 14:28:48 -0400 Subject: [PATCH 1/2] Additional test_git scenarios Includes coverage for accept_hostkey and additional scm URL formats. --- .../integration/roles/test_git/tasks/main.yml | 85 ++++++++++++++++--- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/test/integration/roles/test_git/tasks/main.yml b/test/integration/roles/test_git/tasks/main.yml index a7072d1ab52..d5b92c8366c 100644 --- a/test/integration/roles/test_git/tasks/main.yml +++ b/test/integration/roles/test_git/tasks/main.yml @@ -16,11 +16,15 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: set where to extract the repo - set_fact: checkout_dir={{ output_dir }}/git - -- name: set what repo to use - set_fact: repo=https://github.com/jimi-c/test_role +- name: set role facts + set_fact: + checkout_dir: '{{ output_dir }}/git' + repo_format1: 'https://github.com/jimi-c/test_role' + repo_format2: 'git@github.com:jimi-c/test_role.git' + repo_format3: 'ssh://git@github.com/jimi-c/test_role.git' + known_host_files: + - "{{ lookup('env','HOME') }}/.ssh/known_hosts" + - '/etc/ssh/ssh_known_hosts' - name: clean out the output_dir shell: rm -rf {{ output_dir }}/* @@ -28,28 +32,26 @@ - name: verify that git is installed so this test can continue shell: which git +# +# Test repo=https://github.com/... +# + - name: initial checkout - git: repo={{ repo }} dest={{ checkout_dir }} + git: repo={{ repo_format1 }} dest={{ checkout_dir }} register: git_result -- debug: var=git_result - -- shell: ls ~/ansible_testing/git - - name: verify information about the initial clone assert: that: - "'before' in git_result" - "'after' in git_result" - "not git_result.before" - - "git_result.changed" + - "git_result.changed" - name: repeated checkout - git: repo={{ repo }} dest={{ checkout_dir }} + git: repo={{ repo_format1 }} dest={{ checkout_dir }} register: git_result2 -- debug: var=git_result2 - - name: check for tags stat: path={{ checkout_dir }}/.git/refs/tags register: tags @@ -74,6 +76,61 @@ that: - "not git_result2.changed" +# +# Test repo=git@github.com:/... +# Requires variable: github_ssh_private_key +# + +- name: clear checkout_dir + file: state=absent path={{ checkout_dir }} +- name: remove known_host files + file: state=absent path={{ item }} + with_items: known_host_files +- name: checkout ssh://git@github.com repo without accept_hostkey (expected fail) + git: repo={{ repo_format2 }} dest={{ checkout_dir }} + register: git_result + ignore_errors: true +- assert: + that: + - 'git_result.failed' + - 'git_result.msg == "github.com has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module"' + +- name: checkout git@github.com repo with accept_hostkey (expected pass) + git: + repo: '{{ repo_format2 }}' + dest: '{{ checkout_dir }}' + accept_hostkey: true + key_file: '{{ github_ssh_private_key }}' + register: git_result + when: github_ssh_private_key is defined + +- assert: + that: + - 'git_result.changed' + when: not git_result|skipped + +# +# Test repo=ssh://git@github.com/... +# Requires variable: github_ssh_private_key +# + +- name: clear checkout_dir + file: state=absent path={{ checkout_dir }} + +- name: checkout ssh://git@github.com repo with accept_hostkey (expected pass) + git: + repo: '{{ repo_format3 }}' + dest: '{{ checkout_dir }}' + version: 'master' + accept_hostkey: false # should already have been accepted + key_file: '{{ github_ssh_private_key }}' + register: git_result + when: github_ssh_private_key is defined + +- assert: + that: + - 'git_result.changed' + when: not git_result|skipped From bc678e7d7b04b10e755042ff3df9a1d7920fdaea Mon Sep 17 00:00:00 2001 From: James Laska Date: Wed, 12 Mar 2014 14:37:15 -0400 Subject: [PATCH 2/2] Add credentials.template and support custom INVENTORY Testers may override the inventory and vars-file using the environment variables 'INVENTORY' and 'VARS_FILE'. --- test/integration/Makefile | 19 +++++++++++-------- test/integration/credentials.template | 7 +++++++ 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 test/integration/credentials.template diff --git a/test/integration/Makefile b/test/integration/Makefile index 33ffc3a969b..7a4072d44ae 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -1,17 +1,20 @@ +INVENTORY ?= inventory +VARS_FILE ?= integration_config.yml + all: non_destructive destructive check_mode test_hash non_destructive: - ansible-playbook non_destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS) + ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS) destructive: - ansible-playbook destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS) + ansible-playbook destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS) check_mode: - ansible-playbook check_mode.yml -i inventory -e @integration_config.yml -v --check $(TEST_FLAGS) + ansible-playbook check_mode.yml -i $(INVENTORY) -e @$(VARS_FILE) -v --check $(TEST_FLAGS) test_hash: - ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' - ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i inventory -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' + ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i $(INVENTORY) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' + ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i $(INVENTORY) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' cloud: amazon rackspace @@ -25,17 +28,17 @@ rackspace_cleanup: @#python cleanup_rax.py -y credentials.yml: - @echo "No credentials.yml file found. A file named 'credentials.yml' is needed to provide credentials needed to run cloud tests." + @echo "No credentials.yml file found. A file named 'credentials.yml' is needed to provide credentials needed to run cloud tests. See sample 'credentials.template' file." @exit 1 amazon: credentials.yml - ansible-playbook amazon.yml -i inventory -e @integration_config.yml -e @credentials.yml -v $(TEST_FLAGS) ; \ + ansible-playbook amazon.yml -i $(INVENTORY) -e @$(VARS_FILE) -e @credentials.yml -v $(TEST_FLAGS) ; \ RC=$$? ; \ make amazon_cleanup ; \ exit $$RC; rackspace: credentials.yml - ansible-playbook rackspace.yml -i inventory -e @integration_config.yml -e @credentials.yml -v $(TEST_FLAGS) ; \ + ansible-playbook rackspace.yml -i $(INVENTORY) -e @$(VARS_FILE) -e @credentials.yml -v $(TEST_FLAGS) ; \ RC=$$? ; \ make rackspace_cleanup ; \ exit $$RC; diff --git a/test/integration/credentials.template b/test/integration/credentials.template new file mode 100644 index 00000000000..0ca34aff7c6 --- /dev/null +++ b/test/integration/credentials.template @@ -0,0 +1,7 @@ +--- +# AWS Credentials +ec2_access_key: FIXME +ec2_secret_key: FIXME + +# GITHUB Credentials +github_ssh_private_key: "{{ lookup('env','HOME') }}/.ssh/id_rsa"