'Check things go as expected when doing the right things.'

@mock.patch('nova.compute.utils.is_volume_backed_instance', return_value=False)
@mock.patch('nova.objects.compute_node.ComputeNode.save')
@mock.patch('keystoneauth1.session.Session.get_auth_headers', return_value={'x-auth-token': 'admin'})
@mock.patch('keystoneauth1.session.Session.get_endpoint', return_value='http://localhost:80/placement')
def test_client_report_smoke(self, mock_vbi, mock_endpoint, mock_auth, mock_cn):

    res_class = fields.ResourceClass.VCPU
    with interceptor.RequestsInterceptor(app=self.app, url=self.url):
        rp = self.client._get_resource_provider(self.compute_uuid)
        self.assertIsNone(rp)
        self.client.update_compute_node(self.compute_node)
        rp = self.client._get_resource_provider(self.compute_uuid)
        self.assertIsNotNone(rp)
        pam = self.client._provider_aggregate_map
        self.assertIn(self.compute_uuid, pam)
        self.assertEqual(set(), pam[self.compute_uuid])
        inventory_url = ('/resource_providers/%s/inventories' % self.compute_uuid)
        resp = self.client.get(inventory_url)
        inventory_data = resp.json()['inventories']
        self.assertEqual(self.compute_node.vcpus, inventory_data[res_class]['total'])
        self.client.update_instance_allocation(self.compute_node, self.instance, 1)
        resp = self.client.get(('/allocations/%s' % self.instance_uuid))
        alloc_data = resp.json()['allocations']
        vcpu_data = alloc_data[self.compute_uuid]['resources'][res_class]
        self.assertEqual(2, vcpu_data)
        resp = self.client.get(('/resource_providers/%s/usages' % self.compute_uuid))
        usage_data = resp.json()['usages']
        vcpu_data = usage_data[res_class]
        self.assertEqual(2, vcpu_data)
        self.client.update_instance_allocation(self.compute_node, self.instance, (-1))
        resp = self.client.get(('/resource_providers/%s/usages' % self.compute_uuid))
        usage_data = resp.json()['usages']
        vcpu_data = usage_data[res_class]
        self.assertEqual(0, vcpu_data)
        self.compute_node.vcpus = 0
        self.compute_node.memory_mb = 0
        self.compute_node.local_gb = 0
        self.client.update_compute_node(self.compute_node)
        resp = self.client.get(inventory_url)
        inventory_data = resp.json()['inventories']
        self.assertEqual({}, inventory_data)
        inv_data = {'BAD_FOO': {'total': 100, 'reserved': 0, 'min_unit': 1, 'max_unit': 100, 'step_size': 1, 'allocation_ratio': 1.0}}
        self.assertRaises(exception.InvalidResourceClass, self.client.set_inventory_for_provider, self.compute_uuid, self.compute_name, inv_data)
