From e8f02e60daf2d158a0fa6f08ac7d3ed89f9c5317 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 9 Feb 2017 21:51:12 -0500 Subject: Adding integration test. Fixed issue with node_selector. --- roles/lib_openshift/library/oc_project.py | 11 +-- roles/lib_openshift/src/class/oc_project.py | 11 +-- .../src/test/integration/oc_project.yml | 83 ++++++++++++++++++++++ 3 files changed, 97 insertions(+), 8 deletions(-) create mode 100755 roles/lib_openshift/src/test/integration/oc_project.yml diff --git a/roles/lib_openshift/library/oc_project.py b/roles/lib_openshift/library/oc_project.py index bdfeca5ca..d8a88d12c 100644 --- a/roles/lib_openshift/library/oc_project.py +++ b/roles/lib_openshift/library/oc_project.py @@ -1387,7 +1387,6 @@ class OCProject(OpenShiftCLI): def get(self): '''return project ''' - #result = self.openshift_cmd(['get', self.kind, self.config.name, '-o', 'json'], output=True, output_type='raw') result = self._get(self.kind, self.config.name) if result['returncode'] == 0: @@ -1441,11 +1440,15 @@ class OCProject(OpenShiftCLI): # Check rolebindings and policybindings return False - # pylint: disable=too-many-return-statements + # pylint: disable=too-many-return-statements,too-many-branches @staticmethod def run_ansible(params, check_mode): '''run the idempotent ansible code''' + _ns = None + if params['node_selector'] is not None: + _ns = ','.join(params['node_selector']) + pconfig = ProjectConfig(params['name'], params['name'], params['kubeconfig'], @@ -1453,7 +1456,7 @@ class OCProject(OpenShiftCLI): 'admin_role': {'value': params['admin_role'], 'include': True}, 'description': {'value': params['description'], 'include': True}, 'display_name': {'value': params['display_name'], 'include': True}, - 'node_selector': {'value': ','.join(params['node_selector']), 'include': True}, + 'node_selector': {'value': _ns, 'include': True}, }) oadm_project = OCProject(pconfig, verbose=params['debug']) @@ -1466,7 +1469,7 @@ class OCProject(OpenShiftCLI): # Get ##### if state == 'list': - exit_json(changed=False, results=api_rval['results'], state="list") + return {'changed': False, 'results': api_rval['results'], 'state': state} ######## # Delete diff --git a/roles/lib_openshift/src/class/oc_project.py b/roles/lib_openshift/src/class/oc_project.py index e587570bb..cf378ef6d 100644 --- a/roles/lib_openshift/src/class/oc_project.py +++ b/roles/lib_openshift/src/class/oc_project.py @@ -36,7 +36,6 @@ class OCProject(OpenShiftCLI): def get(self): '''return project ''' - #result = self.openshift_cmd(['get', self.kind, self.config.name, '-o', 'json'], output=True, output_type='raw') result = self._get(self.kind, self.config.name) if result['returncode'] == 0: @@ -90,11 +89,15 @@ class OCProject(OpenShiftCLI): # Check rolebindings and policybindings return False - # pylint: disable=too-many-return-statements + # pylint: disable=too-many-return-statements,too-many-branches @staticmethod def run_ansible(params, check_mode): '''run the idempotent ansible code''' + _ns = None + if params['node_selector'] is not None: + _ns = ','.join(params['node_selector']) + pconfig = ProjectConfig(params['name'], params['name'], params['kubeconfig'], @@ -102,7 +105,7 @@ class OCProject(OpenShiftCLI): 'admin_role': {'value': params['admin_role'], 'include': True}, 'description': {'value': params['description'], 'include': True}, 'display_name': {'value': params['display_name'], 'include': True}, - 'node_selector': {'value': ','.join(params['node_selector']), 'include': True}, + 'node_selector': {'value': _ns, 'include': True}, }) oadm_project = OCProject(pconfig, verbose=params['debug']) @@ -115,7 +118,7 @@ class OCProject(OpenShiftCLI): # Get ##### if state == 'list': - exit_json(changed=False, results=api_rval['results'], state="list") + return {'changed': False, 'results': api_rval['results'], 'state': state} ######## # Delete diff --git a/roles/lib_openshift/src/test/integration/oc_project.yml b/roles/lib_openshift/src/test/integration/oc_project.yml new file mode 100755 index 000000000..9f700c62c --- /dev/null +++ b/roles/lib_openshift/src/test/integration/oc_project.yml @@ -0,0 +1,83 @@ +#!/usr/bin/ansible-playbook --module-path=../../../library/ +# ./oc_project.yml -M ../../../library -e "cli_master_test=$OPENSHIFT_MASTER +--- +- hosts: "{{ cli_master_test }}" + gather_facts: no + user: root + tasks: + - name: create a project + oc_project: + display_name: operations project + name: operations + state: present + description: All things operations + node_selector: + - ops_only=true + register: projout + - debug: var=projout + + - assert: + that: + - "projout.results.results['metadata']['name'] == 'operations'" + - projout.changed + msg: project create failed. + + - name: create a project + oc_project: + display_name: operations project + name: operations + state: present + description: All things operations + node_selector: + - ops_only=true + register: projout + - debug: var=projout + + - assert: + that: + - "projout.results.results['metadata']['name'] == 'operations'" + - projout.changed == False + msg: project create failed. + + - name: update a project + oc_project: + display_name: operations project one + name: operations + state: present + description: All things operations + node_selector: + - ops_only=true + register: projout + - debug: var=projout + + - assert: + that: + - "projout.results.results['metadata']['annotations']['openshift.io/display-name'] == 'operations project one'" + - projout.changed == True + msg: project create failed. + + - name: update a project + oc_project: + name: operations + state: list + register: projout + - debug: var=projout + + - assert: + that: + - "projout.results['metadata']['annotations']['openshift.io/display-name'] == 'operations project one'" + - projout.changed == False + - projout.state == 'list' + msg: project list failed. + + - name: delete a project + oc_project: + name: operations + state: absent + register: projout + - debug: var=projout + + - assert: + that: + - projout.changed == True + msg: project delete failed. -- cgit v1.2.1