From ed210226e0996ebb6d31ff55185ad96357bf3014 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Tue, 21 Mar 2017 16:53:16 -0400 Subject: Adding configmap support and adding tests. --- .../lib_openshift/src/test/unit/test_oc_volume.py | 271 ++++++++++++++++++++- 1 file changed, 258 insertions(+), 13 deletions(-) (limited to 'roles/lib_openshift/src/test') diff --git a/roles/lib_openshift/src/test/unit/test_oc_volume.py b/roles/lib_openshift/src/test/unit/test_oc_volume.py index 88bcd3c77..14f915c7e 100755 --- a/roles/lib_openshift/src/test/unit/test_oc_volume.py +++ b/roles/lib_openshift/src/test/unit/test_oc_volume.py @@ -2,6 +2,7 @@ Unit tests for oc volume ''' +import copy import os import six import sys @@ -23,24 +24,25 @@ class OCVolumeTest(unittest.TestCase): ''' Test class for OCVolume ''' + params = {'name': 'oso-rhel7-zagg-web', + 'kubeconfig': '/etc/origin/master/admin.kubeconfig', + 'namespace': 'test', + 'labels': None, + 'state': 'present', + 'kind': 'dc', + 'mount_path': None, + 'secret_name': None, + 'mount_type': 'pvc', + 'claim_name': 'testclaim', + 'claim_size': '1G', + 'vol_name': 'test-volume', + 'debug': False} @mock.patch('oc_volume.Utils.create_tmpfile_copy') @mock.patch('oc_volume.OCVolume._run') def test_create_pvc(self, mock_cmd, mock_tmpfile_copy): ''' Testing a label list ''' - params = {'name': 'oso-rhel7-zagg-web', - 'kubeconfig': '/etc/origin/master/admin.kubeconfig', - 'namespace': 'test', - 'labels': None, - 'state': 'present', - 'kind': 'dc', - 'mount_path': None, - 'secret_name': None, - 'mount_type': 'pvc', - 'claim_name': 'testclaim', - 'claim_size': '1G', - 'vol_name': 'test-volume', - 'debug': False} + params = copy.deepcopy(OCVolumeTest.params) dc = '''{ "kind": "DeploymentConfig", @@ -277,6 +279,249 @@ class OCVolumeTest(unittest.TestCase): self.assertTrue(results['changed']) self.assertTrue(results['results']['results'][-1]['name'] == 'test-volume') + @mock.patch('oc_volume.Utils.create_tmpfile_copy') + @mock.patch('oc_volume.OCVolume._run') + def test_create_configmap(self, mock_cmd, mock_tmpfile_copy): + ''' Testing a label list ''' + params = copy.deepcopy(OCVolumeTest.params) + params.update({'mount_path': '/configmap', + 'mount_type': 'configmap', + 'vol_name': 'configtest'}) + + dc = '''{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "oso-rhel7-zagg-web", + "namespace": "new-monitoring", + "selfLink": "/oapi/v1/namespaces/new-monitoring/deploymentconfigs/oso-rhel7-zagg-web", + "uid": "f56e9dd2-7c13-11e6-b046-0e8844de0587", + "resourceVersion": "137095771", + "generation": 4, + "creationTimestamp": "2016-09-16T13:46:24Z", + "labels": { + "app": "oso-rhel7-ops-base", + "name": "oso-rhel7-zagg-web" + }, + "annotations": { + "openshift.io/generated-by": "OpenShiftNewApp" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "rollingParams": { + "updatePeriodSeconds": 1, + "intervalSeconds": 1, + "timeoutSeconds": 600, + "maxUnavailable": "25%", + "maxSurge": "25%" + }, + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "oso-rhel7-zagg-web" + ], + "from": { + "kind": "ImageStreamTag", + "namespace": "new-monitoring", + "name": "oso-rhel7-zagg-web:latest" + }, + "lastTriggeredImage": "notused" + } + } + ], + "replicas": 10, + "test": false, + "selector": { + "deploymentconfig": "oso-rhel7-zagg-web" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "app": "oso-rhel7-ops-base", + "deploymentconfig": "oso-rhel7-zagg-web" + }, + "annotations": { + "openshift.io/generated-by": "OpenShiftNewApp" + } + }, + "spec": { + "volumes": [ + { + "name": "monitoring-secrets", + "secret": { + "secretName": "monitoring-secrets" + } + } + ], + "containers": [ + { + "name": "oso-rhel7-zagg-web", + "image": "notused", + "resources": {}, + "volumeMounts": [ + { + "name": "monitoring-secrets", + "mountPath": "/secrets" + } + ], + "terminationMessagePath": "/dev/termination-log", + "imagePullPolicy": "Always", + "securityContext": { + "capabilities": {}, + "privileged": false + } + } + ], + "restartPolicy": "Always", + "terminationGracePeriodSeconds": 30, + "dnsPolicy": "ClusterFirst", + "securityContext": {} + } + } + } + }''' + + post_dc = '''{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "oso-rhel7-zagg-web", + "namespace": "new-monitoring", + "selfLink": "/oapi/v1/namespaces/new-monitoring/deploymentconfigs/oso-rhel7-zagg-web", + "uid": "f56e9dd2-7c13-11e6-b046-0e8844de0587", + "resourceVersion": "137095771", + "generation": 4, + "creationTimestamp": "2016-09-16T13:46:24Z", + "labels": { + "app": "oso-rhel7-ops-base", + "name": "oso-rhel7-zagg-web" + }, + "annotations": { + "openshift.io/generated-by": "OpenShiftNewApp" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "rollingParams": { + "updatePeriodSeconds": 1, + "intervalSeconds": 1, + "timeoutSeconds": 600, + "maxUnavailable": "25%", + "maxSurge": "25%" + }, + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "oso-rhel7-zagg-web" + ], + "from": { + "kind": "ImageStreamTag", + "namespace": "new-monitoring", + "name": "oso-rhel7-zagg-web:latest" + }, + "lastTriggeredImage": "notused" + } + } + ], + "replicas": 10, + "test": false, + "selector": { + "deploymentconfig": "oso-rhel7-zagg-web" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "app": "oso-rhel7-ops-base", + "deploymentconfig": "oso-rhel7-zagg-web" + }, + "annotations": { + "openshift.io/generated-by": "OpenShiftNewApp" + } + }, + "spec": { + "volumes": [ + { + "name": "monitoring-secrets", + "secret": { + "secretName": "monitoring-secrets" + } + }, + { + "name": "configtest", + "configMap": { + "name": "configtest" + } + } + ], + "containers": [ + { + "name": "oso-rhel7-zagg-web", + "image": "notused", + "resources": {}, + "volumeMounts": [ + { + "name": "monitoring-secrets", + "mountPath": "/secrets" + }, + { + "name": "configtest", + "mountPath": "/configmap" + } + ], + "terminationMessagePath": "/dev/termination-log", + "imagePullPolicy": "Always", + "securityContext": { + "capabilities": {}, + "privileged": false + } + } + ], + "restartPolicy": "Always", + "terminationGracePeriodSeconds": 30, + "dnsPolicy": "ClusterFirst", + "securityContext": {} + } + } + } + }''' + + mock_cmd.side_effect = [ + (0, dc, ''), + (0, dc, ''), + (0, '', ''), + (0, post_dc, ''), + ] + + mock_tmpfile_copy.side_effect = [ + '/tmp/mocked_kubeconfig', + ] + + results = OCVolume.run_ansible(params, False) + + self.assertTrue(results['changed']) + self.assertTrue(results['results']['results'][-1]['name'] == 'configtest') + @unittest.skipIf(six.PY3, 'py2 test only') @mock.patch('os.path.exists') @mock.patch('os.environ.get') -- cgit v1.2.3