From d158ec382c2bc50fd34e08d763cfb89e032cdfcf Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 20 Feb 2014 15:23:51 -0500 Subject: [PATCH] Adding new test for hash behavior (merge vs. replace) --- tests_new/integration/Makefile | 5 ++- tests_new/integration/group_vars/all | 2 + tests_new/integration/group_vars/local | 2 + tests_new/integration/host_vars/all | 1 - tests_new/integration/host_vars/testhost | 2 + .../test_hash_behavior/defaults/main.yml | 21 ++++++++++ .../roles/test_hash_behavior/meta/main.yml | 18 +++++++++ .../roles/test_hash_behavior/tasks/main.yml | 38 +++++++++++++++++++ .../roles/test_hash_behavior/vars/main.yml | 21 ++++++++++ tests_new/integration/test_hash.yml | 20 ++++++++++ tests_new/integration/vars/test_hash_vars.yml | 3 ++ 11 files changed, 131 insertions(+), 2 deletions(-) delete mode 100644 tests_new/integration/host_vars/all create mode 100644 tests_new/integration/roles/test_hash_behavior/defaults/main.yml create mode 100644 tests_new/integration/roles/test_hash_behavior/meta/main.yml create mode 100644 tests_new/integration/roles/test_hash_behavior/tasks/main.yml create mode 100644 tests_new/integration/roles/test_hash_behavior/vars/main.yml create mode 100644 tests_new/integration/test_hash.yml create mode 100644 tests_new/integration/vars/test_hash_vars.yml diff --git a/tests_new/integration/Makefile b/tests_new/integration/Makefile index 9e80b0d79d..f28d6576dc 100644 --- a/tests_new/integration/Makefile +++ b/tests_new/integration/Makefile @@ -1,4 +1,4 @@ -all: non_destructive destructive # amazon rackspace +all: non_destructive destructive test_hash # amazon rackspace non_destructive: ansible-playbook non_destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS) @@ -6,3 +6,6 @@ non_destructive: destructive: ansible-playbook destructive.yml -i inventory -e @integration_config.yml -v $(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"}}' diff --git a/tests_new/integration/group_vars/all b/tests_new/integration/group_vars/all index 30aa3d6d56..110b628c8b 100644 --- a/tests_new/integration/group_vars/all +++ b/tests_new/integration/group_vars/all @@ -7,3 +7,5 @@ dos: 2 tres: 3 etest: 'from group_vars' inventory_beats_default: 'narf' +test_hash: + group_vars_all: "this is in group_vars/all" diff --git a/tests_new/integration/group_vars/local b/tests_new/integration/group_vars/local index 8feb93fc99..4bb5f3a24c 100644 --- a/tests_new/integration/group_vars/local +++ b/tests_new/integration/group_vars/local @@ -1 +1,3 @@ tres: 'three' +hash_test: + group_vars_local: "this is in group_vars/local" diff --git a/tests_new/integration/host_vars/all b/tests_new/integration/host_vars/all deleted file mode 100644 index e9789525a9..0000000000 --- a/tests_new/integration/host_vars/all +++ /dev/null @@ -1 +0,0 @@ -etest: 'from hostvars' diff --git a/tests_new/integration/host_vars/testhost b/tests_new/integration/host_vars/testhost index accb6b4715..a2480317e5 100644 --- a/tests_new/integration/host_vars/testhost +++ b/tests_new/integration/host_vars/testhost @@ -3,3 +3,5 @@ b: 2 c: 3 d: 4 role_var_beats_inventory: 'should_not_see_this' +test_hash: + host_vars_testhost: "this is in host_vars/testhost" diff --git a/tests_new/integration/roles/test_hash_behavior/defaults/main.yml b/tests_new/integration/roles/test_hash_behavior/defaults/main.yml new file mode 100644 index 0000000000..6d10238a69 --- /dev/null +++ b/tests_new/integration/roles/test_hash_behavior/defaults/main.yml @@ -0,0 +1,21 @@ +# test code for the hash variable behavior +# (c) 2014, James Cammarata + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +--- +test_hash: + default_vars: "this is in role default/main.yml" diff --git a/tests_new/integration/roles/test_hash_behavior/meta/main.yml b/tests_new/integration/roles/test_hash_behavior/meta/main.yml new file mode 100644 index 0000000000..c3dcf7aaf9 --- /dev/null +++ b/tests_new/integration/roles/test_hash_behavior/meta/main.yml @@ -0,0 +1,18 @@ +# test code for the hash variable behavior +# (c) 2014, James Cammarata + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/tests_new/integration/roles/test_hash_behavior/tasks/main.yml b/tests_new/integration/roles/test_hash_behavior/tasks/main.yml new file mode 100644 index 0000000000..99d9db2293 --- /dev/null +++ b/tests_new/integration/roles/test_hash_behavior/tasks/main.yml @@ -0,0 +1,38 @@ +# test code for the hash variable behavior +# (c) 2014, James Cammarata + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- name: get the hash behavior env setting + shell: env | grep ANSIBLE_HASH_BEHAVIOUR | cut -f2- -d'=' + register: hash_behavior + +- name: debug hash behavior result + debug: var=hash_behavior.stdout + +- name: assert hash behavior is merge or replace + assert: + that: + - "hash_behavior.stdout in ('merge', 'replace')" + +- name: debug test_hash var + debug: var=test_hash + +- name: assert the dictionary values match + assert: + that: + - "hash_behavior.stdout == 'merge' and test_hash == merged_hash or hash_behavior.stdout == 'replace' and test_hash == replaced_hash" + diff --git a/tests_new/integration/roles/test_hash_behavior/vars/main.yml b/tests_new/integration/roles/test_hash_behavior/vars/main.yml new file mode 100644 index 0000000000..2068e9fbaf --- /dev/null +++ b/tests_new/integration/roles/test_hash_behavior/vars/main.yml @@ -0,0 +1,21 @@ +# test code for the hash variable behavior +# (c) 2014, James Cammarata + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +--- +test_hash: + role_vars: "this is in role vars/main.yml" diff --git a/tests_new/integration/test_hash.yml b/tests_new/integration/test_hash.yml new file mode 100644 index 0000000000..36cd82d6bb --- /dev/null +++ b/tests_new/integration/test_hash.yml @@ -0,0 +1,20 @@ +--- +- hosts: testhost + vars_files: + - vars/test_hash_vars.yml + vars: + test_hash: + playbook_vars: "this is a playbook variable" + replaced_hash: + extra_args: "this is an extra arg" + merged_hash: + default_vars: "this is in role default/main.yml" + extra_args: "this is an extra arg" + group_vars_all: "this is in group_vars/all" + host_vars_testhost: "this is in host_vars/testhost" + playbook_vars: "this is a playbook variable" + role_argument: "this is a role argument variable" + role_vars: "this is in role vars/main.yml" + vars_file: "this is in a vars_file" + roles: + - { role: test_hash_behavior, test_hash: {'role_argument':'this is a role argument variable'} } diff --git a/tests_new/integration/vars/test_hash_vars.yml b/tests_new/integration/vars/test_hash_vars.yml new file mode 100644 index 0000000000..e25f8576c3 --- /dev/null +++ b/tests_new/integration/vars/test_hash_vars.yml @@ -0,0 +1,3 @@ +--- +test_hash: + vars_file: "this is in a vars_file"