'Testing a label list'

@mock.patch('oc_volume.Utils.create_tmpfile_copy')
@mock.patch('oc_volume.OCVolume._run')
def test_create_pvc(self, mock_cmd, mock_tmpfile_copy):

    params = copy.deepcopy(OCVolumeTest.params)
    dc = '{\n                                                                "kind":    "DeploymentConfig",\n                                                                "apiVersion":    "v1",\n                                                                "metadata":    {\n                                                                                "name":    "oso-rhel7-zagg-web",\n                                                                                "namespace":    "new-monitoring",\n                                                                                "selfLink":    "/oapi/v1/namespaces/new-monitoring/deploymentconfigs/oso-rhel7-zagg-web",\n                                                                                "uid":    "f56e9dd2-7c13-11e6-b046-0e8844de0587",\n                                                                                "resourceVersion":    "137095771",\n                                                                                "generation":    4,\n                                                                                "creationTimestamp":    "2016-09-16T13:46:24Z",\n                                                                                "labels":    {\n                                                                                                "app":    "oso-rhel7-ops-base",\n                                                                                                "name":    "oso-rhel7-zagg-web"\n                                                                                },\n                                                                                "annotations":    {\n                                                                                                "openshift.io/generated-by":    "OpenShiftNewApp"\n                                                                                }\n                                                                },\n                                                                "spec":    {\n                                                                                "strategy":    {\n                                                                                                "type":    "Rolling",\n                                                                                                "rollingParams":    {\n                                                                                                                "updatePeriodSeconds":    1,\n                                                                                                                "intervalSeconds":    1,\n                                                                                                                "timeoutSeconds":    600,\n                                                                                                                "maxUnavailable":    "25%",\n                                                                                                                "maxSurge":    "25%"\n                                                                                                },\n                                                                                                "resources":    {}\n                                                                                },\n                                                                                "triggers":    [\n                                                                                                {\n                                                                                                                "type":    "ConfigChange"\n                                                                                                },\n                                                                                                {\n                                                                                                                "type":    "ImageChange",\n                                                                                                                "imageChangeParams":    {\n                                                                                                                                "automatic":    true,\n                                                                                                                                "containerNames":    [\n                                                                                                                                                "oso-rhel7-zagg-web"\n                                                                                                                                ],\n                                                                                                                                "from":    {\n                                                                                                                                                "kind":    "ImageStreamTag",\n                                                                                                                                                "namespace":    "new-monitoring",\n                                                                                                                                                "name":    "oso-rhel7-zagg-web:latest"\n                                                                                                                                },\n                                                                                                                                "lastTriggeredImage":    "notused"\n                                                                                                                }\n                                                                                                }\n                                                                                ],\n                                                                                "replicas":    10,\n                                                                                "test":    false,\n                                                                                "selector":    {\n                                                                                                "deploymentconfig":    "oso-rhel7-zagg-web"\n                                                                                },\n                                                                                "template":    {\n                                                                                                "metadata":    {\n                                                                                                                "creationTimestamp":    null,\n                                                                                                                "labels":    {\n                                                                                                                                "app":    "oso-rhel7-ops-base",\n                                                                                                                                "deploymentconfig":    "oso-rhel7-zagg-web"\n                                                                                                                },\n                                                                                                                "annotations":    {\n                                                                                                                                "openshift.io/generated-by":    "OpenShiftNewApp"\n                                                                                                                }\n                                                                                                },\n                                                                                                "spec":    {\n                                                                                                                "volumes":    [\n                                                                                                                                {\n                                                                                                                                                "name":    "monitoring-secrets",\n                                                                                                                                                "secret":    {\n                                                                                                                                                                "secretName":    "monitoring-secrets"\n                                                                                                                                                }\n                                                                                                                                }\n                                                                                                                ],\n                                                                                                                "containers":    [\n                                                                                                                                {\n                                                                                                                                                "name":    "oso-rhel7-zagg-web",\n                                                                                                                                                "image":    "notused",\n                                                                                                                                                "resources":    {},\n                                                                                                                                                "volumeMounts":    [\n                                                                                                                                                                {\n                                                                                                                                                                                "name":    "monitoring-secrets",\n                                                                                                                                                                                "mountPath":    "/secrets"\n                                                                                                                                                                }\n                                                                                                                                                ],\n                                                                                                                                                "terminationMessagePath":    "/dev/termination-log",\n                                                                                                                                                "imagePullPolicy":    "Always",\n                                                                                                                                                "securityContext":    {\n                                                                                                                                                                "capabilities":    {},\n                                                                                                                                                                "privileged":    false\n                                                                                                                                                }\n                                                                                                                                }\n                                                                                                                ],\n                                                                                                                "restartPolicy":    "Always",\n                                                                                                                "terminationGracePeriodSeconds":    30,\n                                                                                                                "dnsPolicy":    "ClusterFirst",\n                                                                                                                "securityContext":    {}\n                                                                                                }\n                                                                                }\n                                                                }\n                                                }'
    post_dc = '{\n                                                                "kind":    "DeploymentConfig",\n                                                                "apiVersion":    "v1",\n                                                                "metadata":    {\n                                                                                "name":    "oso-rhel7-zagg-web",\n                                                                                "namespace":    "new-monitoring",\n                                                                                "selfLink":    "/oapi/v1/namespaces/new-monitoring/deploymentconfigs/oso-rhel7-zagg-web",\n                                                                                "uid":    "f56e9dd2-7c13-11e6-b046-0e8844de0587",\n                                                                                "resourceVersion":    "137095771",\n                                                                                "generation":    4,\n                                                                                "creationTimestamp":    "2016-09-16T13:46:24Z",\n                                                                                "labels":    {\n                                                                                                "app":    "oso-rhel7-ops-base",\n                                                                                                "name":    "oso-rhel7-zagg-web"\n                                                                                },\n                                                                                "annotations":    {\n                                                                                                "openshift.io/generated-by":    "OpenShiftNewApp"\n                                                                                }\n                                                                },\n                                                                "spec":    {\n                                                                                "strategy":    {\n                                                                                                "type":    "Rolling",\n                                                                                                "rollingParams":    {\n                                                                                                                "updatePeriodSeconds":    1,\n                                                                                                                "intervalSeconds":    1,\n                                                                                                                "timeoutSeconds":    600,\n                                                                                                                "maxUnavailable":    "25%",\n                                                                                                                "maxSurge":    "25%"\n                                                                                                },\n                                                                                                "resources":    {}\n                                                                                },\n                                                                                "triggers":    [\n                                                                                                {\n                                                                                                                "type":    "ConfigChange"\n                                                                                                },\n                                                                                                {\n                                                                                                                "type":    "ImageChange",\n                                                                                                                "imageChangeParams":    {\n                                                                                                                                "automatic":    true,\n                                                                                                                                "containerNames":    [\n                                                                                                                                                "oso-rhel7-zagg-web"\n                                                                                                                                ],\n                                                                                                                                "from":    {\n                                                                                                                                                "kind":    "ImageStreamTag",\n                                                                                                                                                "namespace":    "new-monitoring",\n                                                                                                                                                "name":    "oso-rhel7-zagg-web:latest"\n                                                                                                                                },\n                                                                                                                                "lastTriggeredImage":    "notused"\n                                                                                                                }\n                                                                                                }\n                                                                                ],\n                                                                                "replicas":    10,\n                                                                                "test":    false,\n                                                                                "selector":    {\n                                                                                                "deploymentconfig":    "oso-rhel7-zagg-web"\n                                                                                },\n                                                                                "template":    {\n                                                                                                "metadata":    {\n                                                                                                                "creationTimestamp":    null,\n                                                                                                                "labels":    {\n                                                                                                                                "app":    "oso-rhel7-ops-base",\n                                                                                                                                "deploymentconfig":    "oso-rhel7-zagg-web"\n                                                                                                                },\n                                                                                                                "annotations":    {\n                                                                                                                                "openshift.io/generated-by":    "OpenShiftNewApp"\n                                                                                                                }\n                                                                                                },\n                                                                                                "spec":    {\n                                                                                                                "volumes":    [\n                                                                                                                                {\n                                                                                                                                                "name":    "monitoring-secrets",\n                                                                                                                                                "secret":    {\n                                                                                                                                                                "secretName":    "monitoring-secrets"\n                                                                                                                                                }\n                                                                                                                                },\n                                                                                                                                {\n                                                                                                                                                "name":    "test-volume",\n                                                                                                                                                "persistentVolumeClaim":    {\n                                                                                                                                                                "claimName":    "testclass",\n                                                                                                                                                                "claimSize":    "1G"\n                                                                                                                                                }\n                                                                                                                                }\n                                                                                                                ],\n                                                                                                                "containers":    [\n                                                                                                                                {\n                                                                                                                                                "name":    "oso-rhel7-zagg-web",\n                                                                                                                                                "image":    "notused",\n                                                                                                                                                "resources":    {},\n                                                                                                                                                "volumeMounts":    [\n                                                                                                                                                                {\n                                                                                                                                                                                "name":    "monitoring-secrets",\n                                                                                                                                                                                "mountPath":    "/secrets"\n                                                                                                                                                                },\n                                                                                                                                                                {\n                                                                                                                                                                                "name":    "test-volume",\n                                                                                                                                                                                "mountPath":    "/data"\n                                                                                                                                                                }\n                                                                                                                                                ],\n                                                                                                                                                "terminationMessagePath":    "/dev/termination-log",\n                                                                                                                                                "imagePullPolicy":    "Always",\n                                                                                                                                                "securityContext":    {\n                                                                                                                                                                "capabilities":    {},\n                                                                                                                                                                "privileged":    false\n                                                                                                                                                }\n                                                                                                                                }\n                                                                                                                ],\n                                                                                                                "restartPolicy":    "Always",\n                                                                                                                "terminationGracePeriodSeconds":    30,\n                                                                                                                "dnsPolicy":    "ClusterFirst",\n                                                                                                                "securityContext":    {}\n                                                                                                }\n                                                                                }\n                                                                }\n                                                }'
    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'] == 'test-volume'))
