def test_no_dc_scale(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing scale for inexisting dc ''' 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': ""}, ] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertTrue(results['failed']) self.assertEqual(results['msg']['returncode'], 1)
def test_no_dc_scale(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing scale for inexisting dc ''' 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': "" }, ] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertTrue(results['failed']) self.assertEqual(results['msg']['returncode'], 1)
def test_scale_failed(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing a scale failure ''' params = { 'name': 'router', 'namespace': 'default', 'replicas': 1, 'state': 'present', 'kind': 'dc', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False } dc = '''{"kind": "DeploymentConfig", "apiVersion": "v1", "metadata": { "name": "router", "namespace": "default", "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router", "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42", "resourceVersion": "6558", "generation": 8, "creationTimestamp": "2017-01-23T20:58:07Z", "labels": { "router": "router" } }, "spec": { "replicas": 2, } }''' error_message = "foo" mock_openshift_cmd.side_effect = [{ "cmd": '/usr/bin/oc get dc router -n default', 'results': dc, 'returncode': 0 }, { "cmd": '/usr/bin/oc get dc router -n default', 'results': dc, 'returncode': 0 }, { "cmd": '/usr/bin/oc replace', 'results': error_message, 'returncode': 1 }] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertTrue(results['failed'])
def test_scale_rc(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing scale for replication controllers ''' params = { 'name': 'router', 'namespace': 'default', 'replicas': 3, 'state': 'list', 'kind': 'rc', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False } rc = '''{"kind": "ReplicationController", "apiVersion": "v1", "metadata": { "name": "router", "namespace": "default", "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router", "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42", "resourceVersion": "6558", "generation": 8, "creationTimestamp": "2017-01-23T20:58:07Z", "labels": { "router": "router" } }, "spec": { "replicas": 3, } }''' mock_openshift_cmd.side_effect = [{ "cmd": '/usr/bin/oc get rc router -n default', 'results': rc, 'returncode': 0 }, { "cmd": '/usr/bin/oc create -f /tmp/router -n default', 'results': '', 'returncode': 0 }] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertFalse(results['changed']) self.assertEqual(results['module_results'][0], 3)
def test_scale_failed(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing a scale failure ''' params = {'name': 'router', 'namespace': 'default', 'replicas': 1, 'state': 'present', 'kind': 'dc', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False} dc = '''{"kind": "DeploymentConfig", "apiVersion": "v1", "metadata": { "name": "router", "namespace": "default", "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router", "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42", "resourceVersion": "6558", "generation": 8, "creationTimestamp": "2017-01-23T20:58:07Z", "labels": { "router": "router" } }, "spec": { "replicas": 2, } }''' error_message = "foo" mock_openshift_cmd.side_effect = [ {"cmd": '/usr/bin/oc get dc router -n default', 'results': dc, 'returncode': 0}, {"cmd": '/usr/bin/oc get dc router -n default', 'results': dc, 'returncode': 0}, {"cmd": '/usr/bin/oc replace', 'results': error_message, 'returncode': 1}] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertTrue(results['failed'])
def test_scale_rc(self, mock_openshift_cmd, mock_tmpfile_copy): ''' Testing scale for replication controllers ''' params = {'name': 'router', 'namespace': 'default', 'replicas': 3, 'state': 'list', 'kind': 'rc', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False} rc = '''{"kind": "ReplicationController", "apiVersion": "v1", "metadata": { "name": "router", "namespace": "default", "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router", "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42", "resourceVersion": "6558", "generation": 8, "creationTimestamp": "2017-01-23T20:58:07Z", "labels": { "router": "router" } }, "spec": { "replicas": 3, } }''' mock_openshift_cmd.side_effect = [ {"cmd": '/usr/bin/oc get rc router -n default', 'results': rc, 'returncode': 0}, {"cmd": '/usr/bin/oc create -f /tmp/router -n default', 'results': '', 'returncode': 0} ] mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] results = OCScale.run_ansible(params, False) self.assertFalse(results['changed']) self.assertEqual(results['result'][0], 3)
def test_state_list(self, mock_openshift_cmd): ''' Testing a get ''' params = {'name': 'router', 'namespace': 'default', 'replicas': 2, 'state': 'list', 'kind': 'dc', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False} dc = '''{"kind": "DeploymentConfig", "apiVersion": "v1", "metadata": { "name": "router", "namespace": "default", "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router", "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42", "resourceVersion": "6558", "generation": 8, "creationTimestamp": "2017-01-23T20:58:07Z", "labels": { "router": "router" } }, "spec": { "replicas": 2, } }''' mock_openshift_cmd.side_effect = [ {"cmd": '/usr/bin/oc get dc router -n default', 'results': dc, 'returncode': 0}] results = OCScale.run_ansible(params, False) self.assertFalse(results['changed']) self.assertEqual(results['result'][0], 2)