'Tests that if a service is deleted but the compute node is not we
don\'t fail when listing hypervisors.'

def test_index_compute_host_not_found(self):

    compute_nodes = objects.ComputeNodeList(objects=[objects.ComputeNode(**TEST_HYPERS[0]), objects.ComputeNode(**TEST_HYPERS[1])])
    def fake_service_get_by_compute_host(context, host):
        if (host == TEST_HYPERS[0]['host']):
            return TEST_SERVICES[0]
        raise exception.ComputeHostNotFound(host=host)
    @mock.patch.object(self.controller.host_api, 'compute_node_get_all', return_value=compute_nodes)
    @mock.patch.object(self.controller.host_api, 'service_get_by_compute_host', fake_service_get_by_compute_host)
    def _test(self, compute_node_get_all):
        req = self._get_request(True)
        result = self.controller.index(req)
        self.assertEqual(1, len(result['hypervisors']))
        expected = {'id': (compute_nodes[0].uuid if self.expect_uuid_for_id else compute_nodes[0].id), 'hypervisor_hostname': compute_nodes[0].hypervisor_hostname, 'state': 'up', 'status': 'enabled'}
        self.assertDictEqual(expected, result['hypervisors'][0])
    _test(self)
