'Tests that allocations are removed after a local delete.
This tests the scenario where a server is local deleted (because the
compute host is down) and we want to make sure that its allocations
have been cleaned up.'

def test_local_delete_removes_allocations(self):

    resp = self.placement_api.get('/resource_providers')
    rp_uuid = resp.body['resource_providers'][0]['uuid']
    usages_before = self._get_usages(rp_uuid)
    for usage in usages_before.values():
        self.assertEqual(0, usage)
    server = self._build_minimal_create_server_request(self.api, 'local-delete-test', self.image_id, self.flavor_id, 'none')
    server = self.admin_api.post_server({'server': server})
    server = self._wait_for_state_change(self.api, server, 'ACTIVE')
    usages_during = self._get_usages(rp_uuid)
    for usage in usages_during.values():
        self.assertNotEqual(0, usage)
    self.compute.stop()
    compute_service_id = self.admin_api.get_services(host=self.compute.host, binary='nova-compute')[0]['id']
    self.admin_api.put_service(compute_service_id, {'forced_down': True})
    self.api.delete_server(server['id'])
    self.compute.start()
    usages_after = self._get_usages(rp_uuid)
    self.assertEqual(usages_before, usages_after)
