From 8a95bb14d811f0e7fbb9f6504d1b66f78adfd877 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Fri, 27 Jan 2017 09:25:57 -0500 Subject: Adding fix for when the resource does not exist. Added test cases. --- roles/lib_openshift/library/oc_scale.py | 2 ++ roles/lib_openshift/src/class/oc_scale.py | 2 ++ .../src/test/integration/oc_scale.yml | 19 +++++++++++++++++ roles/lib_openshift/src/test/unit/oc_scale.py | 24 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) (limited to 'roles') diff --git a/roles/lib_openshift/library/oc_scale.py b/roles/lib_openshift/library/oc_scale.py index 6ae85e220..1259c5711 100644 --- a/roles/lib_openshift/library/oc_scale.py +++ b/roles/lib_openshift/library/oc_scale.py @@ -1644,6 +1644,8 @@ class OCScale(OpenShiftCLI): state = params['state'] api_rval = oc_scale.get() + if api_rval['returncode'] != 0: + return {'failed': True, 'msg': api_rval} ##### # Get diff --git a/roles/lib_openshift/src/class/oc_scale.py b/roles/lib_openshift/src/class/oc_scale.py index 19fba3af5..16255688b 100644 --- a/roles/lib_openshift/src/class/oc_scale.py +++ b/roles/lib_openshift/src/class/oc_scale.py @@ -77,6 +77,8 @@ class OCScale(OpenShiftCLI): state = params['state'] api_rval = oc_scale.get() + if api_rval['returncode'] != 0: + return {'failed': True, 'msg': api_rval} ##### # Get diff --git a/roles/lib_openshift/src/test/integration/oc_scale.yml b/roles/lib_openshift/src/test/integration/oc_scale.yml index e96e16820..43a42c589 100755 --- a/roles/lib_openshift/src/test/integration/oc_scale.yml +++ b/roles/lib_openshift/src/test/integration/oc_scale.yml @@ -90,3 +90,22 @@ - "'results' in pods and 'results' in pods.results" - "{{ pods.results.results[0]['items']|length }} == 2" msg: "Did not find 1 replica in scale results." + + + # Test scale on non-existent dc + - name: scale non-existent dc + oc_scale: + name: not_there + kind: dc + replicas: 2 + register: scaleout + ignore_errors: True + + - debug: var=scaleout + + - assert: + that: + - scaleout.changed == False + - scaleout.msg.returncode == 1 + - "'msg' in scaleout and 'stderr' in scaleout.msg" + msg: "Deploymentconfig exists. This should error." diff --git a/roles/lib_openshift/src/test/unit/oc_scale.py b/roles/lib_openshift/src/test/unit/oc_scale.py index c523592de..d8d5a231f 100755 --- a/roles/lib_openshift/src/test/unit/oc_scale.py +++ b/roles/lib_openshift/src/test/unit/oc_scale.py @@ -119,6 +119,30 @@ class OCScaleTest(unittest.TestCase): self.assertFalse(results['changed']) self.assertEqual(results['result'][0], 3) + @mock.patch('oc_scale.OCScale.openshift_cmd') + def test_no_dc_scale(self, mock_openshift_cmd): + ''' Testing a get ''' + params = {'name': 'not_there', + 'namespace': 'default', + 'replicas': 3, + 'state': 'present', + 'kind': 'dc', + 'kubeconfig': '/etc/origin/master/admin.kubeconfig', + 'debug': False} + + mock_openshift_cmd.side_effect = [ + {"cmd": '/usr/bin/oc -n default get dc not_there -o json', + 'results': [{}], + 'returncode': 1, + 'stderr': "Error from server: deploymentconfigs \"not_there\" not found\n", + 'stdout': ""}, + ] + + results = OCScale.run_ansible(params, False) + + self.assertTrue(results['failed']) + self.assertEqual(results['msg']['returncode'], 1) + def tearDown(self): '''TearDown method''' pass -- cgit v1.2.3