'Testing when all objects are invalid'

@mock.patch('oc_objectvalidator.locate_oc_binary')
@mock.patch('oc_objectvalidator.Utils.create_tmpfile_copy')
@mock.patch('oc_objectvalidator.OCObjectValidator._run')
def test_invalid_both(self, mock_cmd, mock_tmpfile_copy, mock_oc_binary):

    params = {'kubeconfig': '/etc/origin/master/admin.kubeconfig'}
    invalid_hostsubnet = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar0",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:09Z",\n                                                                "name":    "bar0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "986",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar0",\n                                                                "uid":    "528dbb41-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar1",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:18Z",\n                                                                "name":    "bar1",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "988",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar1",\n                                                                "uid":    "57710d84-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar2",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:26Z",\n                                                                "name":    "bar2",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "991",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar2",\n                                                                "uid":    "5c59a28c-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "baz1",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:49Z",\n                                                                "name":    "baz0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "996",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbaz0",\n                                                                "uid":    "69f75f87-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n}'
    invalid_netnamespace = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:52Z",\n                                                                "name":    "bar0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "969",\n                                                                "selfLink":    "/oapi/v1/netnamespacesbar0",\n                                                                "uid":    "245d416e-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "bar1"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:16Z",\n                                                                "name":    "foo0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "959",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo0",\n                                                                "uid":    "0f1c85b2-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo0"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:26Z",\n                                                                "name":    "foo1",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "962",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo1",\n                                                                "uid":    "14effa0d-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo1"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:36Z",\n                                                                "name":    "foo2",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "965",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo2",\n                                                                "uid":    "1aabdf84-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo2"\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n}'
    invalid_namespace = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c1,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000000000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000000000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:49Z",\n                                                                "name":    "default",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "165",\n                                                                "selfLink":    "/api/v1/namespacesdefault",\n                                                                "uid":    "23c0c6aa-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/requester":    "",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c3,c2",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000010000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000010000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:49Z",\n                                                                "name":    "kube-system",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "3052",\n                                                                "selfLink":    "/api/v1/namespaceskube-system",\n                                                                "uid":    "23c21758-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/description":    "",\n                                                                                "openshift.io/display-name":    "",\n                                                                                "openshift.io/requester":    "developer",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c9,c4",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000080000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000080000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T02:17:16Z",\n                                                                "name":    "myproject",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "2898",\n                                                                "selfLink":    "/api/v1/namespacesmyproject",\n                                                                "uid":    "5ae3764d-feee-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "openshift.io/origin",\n                                                                                "kubernetes"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/requester":    "",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c6,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000030000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000030000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:51Z",\n                                                                "name":    "openshift",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "3057",\n                                                                "selfLink":    "/api/v1/namespacesopenshift",\n                                                                "uid":    "24f7b34d-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/description":    "",\n                                                                                "openshift.io/display-name":    "",\n                                                                                "openshift.io/requester":    "system:admin",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c10,c5",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000100000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000100000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T02:21:15Z",\n                                                                "name":    "openshift-fancy",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "3072",\n                                                                "selfLink":    "/api/v1/namespacesopenshift-fancy",\n                                                                "uid":    "e958063c-feee-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "openshift.io/origin",\n                                                                                "kubernetes"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c5,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000020000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000020000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:51Z",\n                                                                "name":    "openshift-infra",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "169",\n                                                                "selfLink":    "/api/v1/namespacesopenshift-infra",\n                                                                "uid":    "24a2ed75-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/description":    "",\n                                                                                "openshift.io/display-name":    "",\n                                                                                "openshift.io/requester":    "developer1",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c10,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000090000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000090000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T02:17:56Z",\n                                                                "name":    "yourproject",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "2955",\n                                                                "selfLink":    "/api/v1/namespacesyourproject",\n                                                                "uid":    "72df7fb9-feee-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "openshift.io/origin",\n                                                                                "kubernetes"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n}'
    invalid_results = {'hostsubnets    where    metadata.name    !=    host': [{'apiVersion': 'v1', 'host': 'baz1', 'hostIP': '1.1.1.1', 'kind': 'HostSubnet', 'metadata': {'creationTimestamp': '2017-02-16T18:47:49Z', 'name': 'baz0', 'namespace': '', 'resourceVersion': '996', 'selfLink': '/oapi/v1/hostsubnetsbaz0', 'uid': '69f75f87-f478-11e6-aae0-507b9dac97ff'}, 'subnet': '1.1.0.0/24'}], 'netnamespaces    where    metadata.name    !=    netname': [{'apiVersion': 'v1', 'kind': 'NetNamespace', 'metadata': {'creationTimestamp': '2017-02-16T18:45:52Z', 'name': 'bar0', 'namespace': '', 'resourceVersion': '969', 'selfLink': '/oapi/v1/netnamespacesbar0', 'uid': '245d416e-f478-11e6-aae0-507b9dac97ff'}, 'netid': 100, 'netname': 'bar1'}], 'namespaces    that    use    reserved    names    and    were    not    created    by    infrastructure    components': [{'apiVersion': 'v1', 'kind': 'Namespace', 'metadata': {'annotations': {'openshift.io/requester': '', 'openshift.io/sa.scc.mcs': 's0:c3,c2', 'openshift.io/sa.scc.supplemental-groups': '1000010000/10000', 'openshift.io/sa.scc.uid-range': '1000010000/10000'}, 'creationTimestamp': '2017-03-02T00:49:49Z', 'name': 'kube-system', 'namespace': '', 'resourceVersion': '3052', 'selfLink': '/api/v1/namespaceskube-system', 'uid': '23c21758-fee2-11e6-b45a-507b9dac97ff'}, 'spec': {'finalizers': ['kubernetes', 'openshift.io/origin']}, 'status': {'phase': 'Active'}}, {'apiVersion': 'v1', 'kind': 'Namespace', 'metadata': {'annotations': {'openshift.io/requester': '', 'openshift.io/sa.scc.mcs': 's0:c6,c0', 'openshift.io/sa.scc.supplemental-groups': '1000030000/10000', 'openshift.io/sa.scc.uid-range': '1000030000/10000'}, 'creationTimestamp': '2017-03-02T00:49:51Z', 'name': 'openshift', 'namespace': '', 'resourceVersion': '3057', 'selfLink': '/api/v1/namespacesopenshift', 'uid': '24f7b34d-fee2-11e6-b45a-507b9dac97ff'}, 'spec': {'finalizers': ['kubernetes', 'openshift.io/origin']}, 'status': {'phase': 'Active'}}, {'apiVersion': 'v1', 'kind': 'Namespace', 'metadata': {'annotations': {'openshift.io/description': '', 'openshift.io/display-name': '', 'openshift.io/requester': 'system:admin', 'openshift.io/sa.scc.mcs': 's0:c10,c5', 'openshift.io/sa.scc.supplemental-groups': '1000100000/10000', 'openshift.io/sa.scc.uid-range': '1000100000/10000'}, 'creationTimestamp': '2017-03-02T02:21:15Z', 'name': 'openshift-fancy', 'namespace': '', 'resourceVersion': '3072', 'selfLink': '/api/v1/namespacesopenshift-fancy', 'uid': 'e958063c-feee-11e6-b45a-507b9dac97ff'}, 'spec': {'finalizers': ['openshift.io/origin', 'kubernetes']}, 'status': {'phase': 'Active'}}]}
    mock_cmd.side_effect = [(0, invalid_hostsubnet, ''), (0, invalid_netnamespace, ''), (0, invalid_namespace, '')]
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    mock_oc_binary.side_effect = ['oc']
    results = OCObjectValidator.run_ansible(params)
    self.assertTrue(results['failed'])
    self.assertIn('All    objects    are    not    valid.', results['msg'])
    self.assertEqual(results['state'], 'list')
    self.assertEqual(results['results'], invalid_results)
    mock_cmd.assert_has_calls([mock.call(['oc', 'get', 'hostsubnet', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'netnamespace', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'namespace', '-o', 'json', '-n', 'default'], None)])
