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. --- roles/lib_openshift/library/oc_label.py | 11 +-- roles/lib_openshift/src/ansible/oc_label.py | 4 +- roles/lib_openshift/src/class/oc_label.py | 7 +- .../src/test/integration/filter_plugins/filters.py | 1 + .../src/test/integration/oc_label.yml | 85 +--------------------- roles/lib_openshift/src/test/unit/oc_label.py | 6 +- 6 files changed, 17 insertions(+), 97 deletions(-) (limited to 'roles/lib_openshift/src/test/integration') diff --git a/roles/lib_openshift/library/oc_label.py b/roles/lib_openshift/library/oc_label.py index 8840bfefa..2096f0a1d 100644 --- a/roles/lib_openshift/library/oc_label.py +++ b/roles/lib_openshift/library/oc_label.py @@ -1265,7 +1265,7 @@ class OCLabel(OpenShiftCLI): for current_host_labels in self.current_labels: rbool = self.compare_labels(current_host_labels) - if rbool == False: + if not rbool: return False return True @@ -1318,8 +1318,8 @@ class OCLabel(OpenShiftCLI): if len(extra_labels) > 0: return True - else: - return False + + return False def replace(self): ''' replace currently stored labels with user provided labels ''' @@ -1401,6 +1401,7 @@ class OCLabel(OpenShiftCLI): return self.openshift_cmd(cmd) + # pylint: disable=too-many-branches,too-many-return-statements @staticmethod def run_ansible(params, check_mode=False): ''' run the idempotent ansible code @@ -1517,14 +1518,14 @@ def main(): choices=['present', 'absent', 'list', 'add']), debug=dict(default=False, type='bool'), kind=dict(default=None, type='str', required=True, - choices=['node', 'pod', 'namespace']), + choices=['node', 'pod', 'namespace']), name=dict(default=None, type='str'), namespace=dict(default=None, type='str'), labels=dict(default=None, type='list'), selector=dict(default=None, type='str'), ), supports_check_mode=True, - mutually_exclusive = (['name', 'selector']), + mutually_exclusive=(['name', 'selector']), ) results = OCLabel.run_ansible(module.params, module.check_mode) diff --git a/roles/lib_openshift/src/ansible/oc_label.py b/roles/lib_openshift/src/ansible/oc_label.py index 149b965d8..685712963 100644 --- a/roles/lib_openshift/src/ansible/oc_label.py +++ b/roles/lib_openshift/src/ansible/oc_label.py @@ -11,14 +11,14 @@ def main(): choices=['present', 'absent', 'list', 'add']), debug=dict(default=False, type='bool'), kind=dict(default=None, type='str', required=True, - choices=['node', 'pod', 'namespace']), + choices=['node', 'pod', 'namespace']), name=dict(default=None, type='str'), namespace=dict(default=None, type='str'), labels=dict(default=None, type='list'), selector=dict(default=None, type='str'), ), supports_check_mode=True, - mutually_exclusive = (['name', 'selector']), + mutually_exclusive=(['name', 'selector']), ) results = OCLabel.run_ansible(module.params, module.check_mode) diff --git a/roles/lib_openshift/src/class/oc_label.py b/roles/lib_openshift/src/class/oc_label.py index 4fc2ffc13..8e1ba9ceb 100644 --- a/roles/lib_openshift/src/class/oc_label.py +++ b/roles/lib_openshift/src/class/oc_label.py @@ -54,7 +54,7 @@ class OCLabel(OpenShiftCLI): for current_host_labels in self.current_labels: rbool = self.compare_labels(current_host_labels) - if rbool == False: + if not rbool: return False return True @@ -107,8 +107,8 @@ class OCLabel(OpenShiftCLI): if len(extra_labels) > 0: return True - else: - return False + + return False def replace(self): ''' replace currently stored labels with user provided labels ''' @@ -190,6 +190,7 @@ class OCLabel(OpenShiftCLI): return self.openshift_cmd(cmd) + # pylint: disable=too-many-branches,too-many-return-statements @staticmethod def run_ansible(params, check_mode=False): ''' run the idempotent ansible code 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 diff --git a/roles/lib_openshift/src/test/unit/oc_label.py b/roles/lib_openshift/src/test/unit/oc_label.py index 875b97c42..3f7162070 100755 --- a/roles/lib_openshift/src/test/unit/oc_label.py +++ b/roles/lib_openshift/src/test/unit/oc_label.py @@ -78,7 +78,6 @@ class OCLabelTest(unittest.TestCase): } }''' - mock_cmd.side_effect = [ (0, ns, ''), ] @@ -166,7 +165,6 @@ class OCLabelTest(unittest.TestCase): } }''' - mock_cmd.side_effect = [ (0, ns, ''), (0, '', ''), @@ -176,8 +174,8 @@ class OCLabelTest(unittest.TestCase): results = OCLabel.run_ansible(params, False) self.assertTrue(results['changed']) - self.assertTrue(results['results']['results']['labels'][0] == \ - {'storage_pv_quota': 'False', 'awesomens': 'testinglabel'}) + self.assertTrue(results['results']['results']['labels'][0] == + {'storage_pv_quota': 'False', 'awesomens': 'testinglabel'}) def tearDown(self): '''TearDown method''' -- 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/library/oc_label.py | 36 +++++++++++++++++++--- roles/lib_openshift/src/ansible/oc_label.py | 2 +- roles/lib_openshift/src/doc/label | 34 ++++++++++++++++++-- .../src/test/integration/filter_plugins/filters.py | 7 +++-- 4 files changed, 69 insertions(+), 10 deletions(-) (limited to 'roles/lib_openshift/src/test/integration') diff --git a/roles/lib_openshift/library/oc_label.py b/roles/lib_openshift/library/oc_label.py index 2096f0a1d..9481d2a47 100644 --- a/roles/lib_openshift/library/oc_label.py +++ b/roles/lib_openshift/library/oc_label.py @@ -55,7 +55,11 @@ description: options: state: description: - - State represents whether to create, modify, delete, or list + - State controls the action that will be taken with resource + - 'present' will create or update and object to the desired state + - 'absent' will ensure certain labels are removed + - 'list' will read the labels + - 'add' will insert labels to the already existing labels default: present choices: ["present", "absent", "list", "add"] aliases: [] @@ -82,7 +86,9 @@ options: aliases: [] labels: description: - - A list of labels to for the resource. + - A list of labels for the resource. + - Each list consists of a key and a value. + - eg, {'key': 'foo', 'value': 'bar'} required: false default: None aliases: [] @@ -98,7 +104,7 @@ extends_documentation_fragment: [] ''' EXAMPLES = ''' -- name: Add label to node +- name: Add a single label to a node's existing labels oc_label: name: ip-172-31-5-23.ec2.internal state: add @@ -106,6 +112,28 @@ EXAMPLES = ''' labels: - key: logging-infra-fluentd value: 'true' + +- name: remove a label from a node + oc_label: + name: ip-172-31-5-23.ec2.internal + state: absent + kind: node + labels: + - key: color + value: blue + +- name: Ensure node has these exact labels + oc_label: + name: ip-172-31-5-23.ec2.internal + state: present + kind: node + labels: + - key: color + value: green + - key: type + value: master + - key: environment + value: production ''' # -*- -*- -*- End included fragment: doc/label -*- -*- -*- @@ -1517,7 +1545,7 @@ def main(): state=dict(default='present', type='str', choices=['present', 'absent', 'list', 'add']), debug=dict(default=False, type='bool'), - kind=dict(default=None, type='str', required=True, + kind=dict(default='node', type='str', required=True, choices=['node', 'pod', 'namespace']), name=dict(default=None, type='str'), namespace=dict(default=None, type='str'), diff --git a/roles/lib_openshift/src/ansible/oc_label.py b/roles/lib_openshift/src/ansible/oc_label.py index 685712963..28f004621 100644 --- a/roles/lib_openshift/src/ansible/oc_label.py +++ b/roles/lib_openshift/src/ansible/oc_label.py @@ -10,7 +10,7 @@ def main(): state=dict(default='present', type='str', choices=['present', 'absent', 'list', 'add']), debug=dict(default=False, type='bool'), - kind=dict(default=None, type='str', required=True, + kind=dict(default='node', type='str', required=True, choices=['node', 'pod', 'namespace']), name=dict(default=None, type='str'), namespace=dict(default=None, type='str'), diff --git a/roles/lib_openshift/src/doc/label b/roles/lib_openshift/src/doc/label index e206d0d06..fb3ed2503 100644 --- a/roles/lib_openshift/src/doc/label +++ b/roles/lib_openshift/src/doc/label @@ -10,7 +10,11 @@ description: options: state: description: - - State represents whether to create, modify, delete, or list + - State controls the action that will be taken with resource + - 'present' will create or update and object to the desired state + - 'absent' will ensure certain labels are removed + - 'list' will read the labels + - 'add' will insert labels to the already existing labels default: present choices: ["present", "absent", "list", "add"] aliases: [] @@ -37,7 +41,9 @@ options: aliases: [] labels: description: - - A list of labels to for the resource. + - A list of labels for the resource. + - Each list consists of a key and a value. + - eg, {'key': 'foo', 'value': 'bar'} required: false default: None aliases: [] @@ -53,7 +59,7 @@ extends_documentation_fragment: [] ''' EXAMPLES = ''' -- name: Add label to node +- name: Add a single label to a node's existing labels oc_label: name: ip-172-31-5-23.ec2.internal state: add @@ -61,4 +67,26 @@ EXAMPLES = ''' labels: - key: logging-infra-fluentd value: 'true' + +- name: remove a label from a node + oc_label: + name: ip-172-31-5-23.ec2.internal + state: absent + kind: node + labels: + - key: color + value: blue + +- name: Ensure node has these exact labels + oc_label: + name: ip-172-31-5-23.ec2.internal + state: present + kind: node + labels: + - key: color + value: green + - key: type + value: master + - key: environment + value: production ''' 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