'Tests deleting the error instance in cell0 and quota.
This test will create the server which will fail to schedule because
there is no compute to send it to. This will trigger the conductor
manager to put the instance into ERROR state and create it in cell0.
The test asserts that quota was decremented. Then it deletes the
instance and will check quota again after the instance is gone.'

def test_delete_error_instance_in_cell0_and_check_quota(self):

    starting_usage = self.api.get_limits()
    server = dict(name='cell0-quota-test', imageRef=self.image_id, flavorRef=self.flavor_id)
    server = self.api.post_server({'server': server})
    self.addCleanup(self._delete_server, server['id'])
    self._wait_for_instance_status(server['id'], 'ERROR')
    current_usage = self.api.get_limits()
    self.assertEqual((starting_usage['absolute']['totalInstancesUsed'] + 1), current_usage['absolute']['totalInstancesUsed'])
    self._delete_server(server['id'])
    self._wait_for_instance_delete(server['id'])
    ending_usage = self.api.get_limits()
    self.assertEqual((current_usage['absolute']['totalInstancesUsed'] - 1), ending_usage['absolute']['totalInstancesUsed'])
