From b5de5357042c146a930097d52c3920808af89c42 Mon Sep 17 00:00:00 2001 From: Joel Diaz Date: Fri, 27 Jan 2017 20:39:06 +0000 Subject: oc_label ansible module used for adding/removing labels on various OpenShift objects --- .../src/test/integration/filter_plugins/filters.py | 25 ++ .../src/test/integration/oc_label.yml | 404 +++++++++++++++++++++ 2 files changed, 429 insertions(+) create mode 100644 roles/lib_openshift/src/test/integration/filter_plugins/filters.py create mode 100755 roles/lib_openshift/src/test/integration/oc_label.yml (limited to 'roles/lib_openshift/src/test/integration') diff --git a/roles/lib_openshift/src/test/integration/filter_plugins/filters.py b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py new file mode 100644 index 000000000..6acbb47ec --- /dev/null +++ b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: expandtab:tabstop=4:shiftwidth=4 +''' +Custom filters for use in testing +''' + +class FilterModule(object): + ''' Custom ansible filters ''' + + @staticmethod + def label_dict_to_key_value_list(label_dict): + ''' given a dict of labels/values, return list of key: value: pairs''' + + label_list = [] + for key in label_dict: + label_list.append({'key': key, 'value': label_dict[key]}) + + return label_list + + def filters(self): + ''' returns a mapping of filters to methods ''' + return { + "label_dict_to_key_value_list": self.label_dict_to_key_value_list, + } diff --git a/roles/lib_openshift/src/test/integration/oc_label.yml b/roles/lib_openshift/src/test/integration/oc_label.yml new file mode 100755 index 000000000..0a2d438bd --- /dev/null +++ b/roles/lib_openshift/src/test/integration/oc_label.yml @@ -0,0 +1,404 @@ +#!/usr/bin/ansible-playbook --module-path=../../../library/ +# ./oc_label.yml -e "cli_master_test=$OPENSHIFT_MASTER -e "cli_node_test=ip-172-0-31-1.ec2" +--- +- hosts: "{{ cli_master_test }}" + gather_facts: no + user: root + + vars: + - def_namespace: default + - def_kind: node + + pre_tasks: + - name: ensure needed vars are defined + fail: + msg: "{{ item }} not defined" + when: "{{ item }} is not defined" + with_items: + - cli_node_test #openshift node to be used to add/remove labels to + - cli_master_test #ansible inventory instance to run playbook against + + tasks: + - name: delete test labels (start from known starting position) + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + - key: testlabel3 + + - name: list to check whether our test labels already exist + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: original_labels + - name: assert that testlabel2 and testlabel3 test labels don't exist + assert: + that: original_labels['results']['labels'][0]['testlabel2'] is not defined and + original_labels['results']['labels'][0]['testlabel3'] is not defined + msg: "{{ original_labels['results']['labels'] }}" + + - name: add label + oc_label: + state: add + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + value: "yes" + register: label_out + - name: assert adding label marked as changed + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: test if add label succeeded + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: assert that testlabel2 label actually added + assert: + that: label_out['results']['labels'][0]['testlabel2'] is defined and + label_out['results']['labels'][0]['testlabel2'] == "yes" + msg: "{{ label_out }}" + + - name: test that re-adding does nothing + oc_label: + state: add + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + value: "yes" + register: label_out + - name: assert that re-adding made no changes + assert: + that: label_out['changed'] == False + msg: "{{ label_out }}" + + - name: test that modifying existing label marked modified + oc_label: + state: add + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + value: "different" + register: label_out + - name: assert that modifying existing label marked modified + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: test if modify label actually did modification + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: assert that testlabel2 label actually modified + assert: + that: label_out['results']['labels'][0]['testlabel2'] is defined and + label_out['results']['labels'][0]['testlabel2'] == "different" + msg: "{{ label_out['results']['labels'] }}" + + - name: delete non-existant label + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabelnone + register: label_out + - name: assert that deleting non-existant label marked not changed + assert: + that: label_out['changed'] == False + msg: "{{ label_out }}" + + - name: delete label + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + register: label_out + - name: assert that deleting existing label marked changed + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: re-delete label + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + register: label_out + - name: assert that re-deleting label marked not changed + assert: + that: label_out['changed'] == False + msg: "{{ label_out }}" + + - name: check whether really deleted + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: assert label actually deleted + assert: + that: label_out['results']['labels'][0]['testlabel2'] is not defined + msg: "{{ label_out }}" + + - name: add two labels + oc_label: + state: add + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + value: "yes" + - key: testlabel3 + value: "yes" + register: label_out + - name: assert that adding two labels marked as changed + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: check whether both labels are there + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: assert that both labels actually exist + assert: + that: label_out['results']['labels'][0]['testlabel2'] is defined and + label_out['results']['labels'][0]['testlabel2'] == 'yes' and + label_out['results']['labels'][0]['testlabel3'] is defined and + label_out['results']['labels'][0]['testlabel3'] == 'yes' + msg: "{{ label_out['results']['labels'] }}" + + - name: check whether two deletes work + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + - key: testlabel3 + register: label_out + - name: assert that change were made when delete both labels + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: check whether re-two deletes makes no changes + oc_label: + state: absent + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: + - key: testlabel2 + - key: testlabel3 + register: label_out + - name: assert that change was not made when re-delete both labels + assert: + that: label_out['changed'] == False + msg: "{{ label_out }}" + + - set_fact: + original_labels_as_key_value_list: "{{ original_labels['results']['labels'][0] | label_dict_to_key_value_list }}" + + - name: check that present with original label list makes no changes + oc_label: + state: present + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: "{{ original_labels_as_key_value_list }}" + register: label_out + - name: assert that no changes are made when current list matches existing list + assert: + that: label_out['changed'] == False + msg: "{{ label_out }}" + + - name: check that present with extra item makes changes + oc_label: + state: present + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: "{{ original_labels_as_key_value_list + [{'key': 'testlabel2', 'value': 'yes'}] }}" + register: label_out + - name: assert that changes were made + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: get current label list + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: asssert that new label was actually added + assert: + that: label_out['results']['labels'][0]['testlabel2'] is defined and + label_out['results']['labels'][0]['testlabel2'] == 'yes' + msg: "{{ label_out['results']['labels'] }}" + + - name: check that present with changed item makes changes + oc_label: + state: present + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: "{{ original_labels_as_key_value_list + [{'key': 'testlabel2', 'value': 'different'}]}}" + register: label_out + - name: assert that changes were made when existing key's value is changed + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: get current label list + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: asssert that changed label was actually changed + assert: + that: label_out['results']['labels'][0]['testlabel2'] is defined and + label_out['results']['labels'][0]['testlabel2'] == 'different' + msg: "{{ label_out['results']['labels'] }}" + + - name: check that present with removed extra item makes changes + oc_label: + state: present + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + labels: "{{ original_labels_as_key_value_list }}" + register: label_out + - name: assert that changes were made + assert: + that: label_out['changed'] == True + msg: "{{ label_out }}" + + - name: get current label list + oc_label: + state: list + namespace: "{{ def_namespace }}" + kind: "{{ def_kind }}" + name: "{{ cli_node_test }}" + register: label_out + - name: asssert that present-removed actually removed + assert: + that: label_out['results']['labels'][0]['testlabel2'] is not defined + msg: "{{ label_out }}" + + + + + + + + + + + +# - name: create route +# oc_route: +# name: test +# namespace: default +# tls_termination: edge +# cert_content: testing cert +# cacert_content: testing cacert +# key_content: key content +# service_name: test +# host: test.example +# register: routeout +# - debug: var=routeout +# +# - assert: +# that: "routeout.results.results[0]['metadata']['name'] == 'test'" +# msg: route create failed +# +# - name: get route +# oc_route: +# state: list +# name: test +# namespace: default +# register: routeout +# - debug: var=routeout +# +# - assert: +# that: "routeout.results[0]['metadata']['name'] == 'test'" +# msg: get route failed +# +# - name: delete route +# oc_route: +# state: absent +# name: test +# namespace: default +# register: routeout +# - debug: var=routeout +# +# - assert: +# that: "routeout.results.returncode == 0" +# msg: delete route failed +# +# - name: create route +# oc_route: +# name: test +# namespace: default +# tls_termination: edge +# cert_content: testing cert +# cacert_content: testing cacert +# key_content: testing key +# service_name: test +# host: test.example +# register: routeout +# - debug: var=routeout +# +# - name: create route noop +# oc_route: +# name: test +# namespace: default +# tls_termination: edge +# cert_content: testing cert +# cacert_content: testing cacert +# key_content: testing key +# service_name: test +# host: test.example +# register: routeout +# - debug: var=routeout +# +# - assert: +# that: "routeout.changed == False" +# msg: Route create not idempotent -- cgit v1.2.3 From f94417164f57891eb016ca5e98c6e713e1f66726 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 2 Feb 2017 09:36:01 -0500 Subject: Fixing linters. --- .../src/test/integration/filter_plugins/filters.py | 1 + .../src/test/integration/oc_label.yml | 85 +--------------------- 2 files changed, 3 insertions(+), 83 deletions(-) (limited to 'roles/lib_openshift/src/test/integration') diff --git a/roles/lib_openshift/src/test/integration/filter_plugins/filters.py b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py index 6acbb47ec..71a29ab7d 100644 --- a/roles/lib_openshift/src/test/integration/filter_plugins/filters.py +++ b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py @@ -5,6 +5,7 @@ Custom filters for use in testing ''' + class FilterModule(object): ''' Custom ansible filters ''' diff --git a/roles/lib_openshift/src/test/integration/oc_label.yml b/roles/lib_openshift/src/test/integration/oc_label.yml index 0a2d438bd..ce9bc25bb 100755 --- a/roles/lib_openshift/src/test/integration/oc_label.yml +++ b/roles/lib_openshift/src/test/integration/oc_label.yml @@ -15,8 +15,8 @@ msg: "{{ item }} not defined" when: "{{ item }} is not defined" with_items: - - cli_node_test #openshift node to be used to add/remove labels to - - cli_master_test #ansible inventory instance to run playbook against + - cli_node_test # openshift node to be used to add/remove labels to + - cli_master_test # ansible inventory instance to run playbook against tasks: - name: delete test labels (start from known starting position) @@ -321,84 +321,3 @@ assert: that: label_out['results']['labels'][0]['testlabel2'] is not defined msg: "{{ label_out }}" - - - - - - - - - - - -# - name: create route -# oc_route: -# name: test -# namespace: default -# tls_termination: edge -# cert_content: testing cert -# cacert_content: testing cacert -# key_content: key content -# service_name: test -# host: test.example -# register: routeout -# - debug: var=routeout -# -# - assert: -# that: "routeout.results.results[0]['metadata']['name'] == 'test'" -# msg: route create failed -# -# - name: get route -# oc_route: -# state: list -# name: test -# namespace: default -# register: routeout -# - debug: var=routeout -# -# - assert: -# that: "routeout.results[0]['metadata']['name'] == 'test'" -# msg: get route failed -# -# - name: delete route -# oc_route: -# state: absent -# name: test -# namespace: default -# register: routeout -# - debug: var=routeout -# -# - assert: -# that: "routeout.results.returncode == 0" -# msg: delete route failed -# -# - name: create route -# oc_route: -# name: test -# namespace: default -# tls_termination: edge -# cert_content: testing cert -# cacert_content: testing cacert -# key_content: testing key -# service_name: test -# host: test.example -# register: routeout -# - debug: var=routeout -# -# - name: create route noop -# oc_route: -# name: test -# namespace: default -# tls_termination: edge -# cert_content: testing cert -# cacert_content: testing cacert -# key_content: testing key -# service_name: test -# host: test.example -# register: routeout -# - debug: var=routeout -# -# - assert: -# that: "routeout.changed == False" -# msg: Route create not idempotent -- cgit v1.2.3 From 4b054d7da5f404dfd8eb238b617e4dcf7dc93b17 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 2 Feb 2017 22:21:23 -0500 Subject: Doc enhancements. --- roles/lib_openshift/src/test/integration/filter_plugins/filters.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'roles/lib_openshift/src/test/integration') diff --git a/roles/lib_openshift/src/test/integration/filter_plugins/filters.py b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py index 71a29ab7d..6990a11a8 100644 --- a/roles/lib_openshift/src/test/integration/filter_plugins/filters.py +++ b/roles/lib_openshift/src/test/integration/filter_plugins/filters.py @@ -7,11 +7,14 @@ Custom filters for use in testing class FilterModule(object): - ''' Custom ansible filters ''' + ''' Custom filters for use in integration testing ''' @staticmethod def label_dict_to_key_value_list(label_dict): - ''' given a dict of labels/values, return list of key: value: pairs''' + ''' Given a dict of labels/values, return list of key: value: pairs + + These are only used in integration testing. + ''' label_list = [] for key in label_dict: -- cgit v1.2.3