From 22bddb434aca9b3c746ee1522e60cc96911b4a30 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 13 Feb 2019 16:53:43 +0530 Subject: [PATCH] test for ipaddr filter (#52088) based upon work of mscherer Signed-off-by: Abhijeet Kasurde --- test/integration/targets/filters/runme.sh | 3 +- .../targets/filters/tasks/main.yml | 34 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/test/integration/targets/filters/runme.sh b/test/integration/targets/filters/runme.sh index c3a63730e30..6ddd65f1e68 100755 --- a/test/integration/targets/filters/runme.sh +++ b/test/integration/targets/filters/runme.sh @@ -4,6 +4,7 @@ set -eux # Requirements have to be installed prior to running ansible-playbook # because plugins and requirements are loaded before the task runs -pip install jmespath + +pip install jmespath netaddr ANSIBLE_ROLES_PATH=../ ansible-playbook filters.yml -i ../../inventory -e @../../integration_config.yml "$@" diff --git a/test/integration/targets/filters/tasks/main.yml b/test/integration/targets/filters/tasks/main.yml index 89815fe9ff7..99aa9beeb36 100644 --- a/test/integration/targets/filters/tasks/main.yml +++ b/test/integration/targets/filters/tasks/main.yml @@ -1,20 +1,7 @@ -# test code -# (c) 2014, Michael DeHaan - -# 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 code for filters +# Copyright: (c) 2014, Michael DeHaan +# Copyright: (c) 2019, Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: a dummy task to test the changed and success filters shell: echo hi @@ -266,3 +253,16 @@ that: - "unions|type_debug == 'list'" - "unions|length == 4" + +- name: Test ipaddr filter + assert: + that: + - "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'" + - "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'" + - "not '192.168.0.1/31' | ipaddr('broadcast')" + - "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'" + - "'192.168.0.1/24' | ipaddr('prefix') == 24" + - "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'" + - "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'" + - "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'" + - "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'"