From caeab76468258c1c9b3661df04e72988ec98b316 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Wed, 31 Jan 2018 17:37:37 -0600 Subject: [PATCH] Test case: new standard resource class unusable If the placement service code is newer than that of the compute service, new standard resource classes may have been introduced in placement which compute doesn't yet know about. These resource classes will be unusable due to the noted bug. This change set adds a test case demonstrating the bug. Change-Id: I71ce6796beb23c4bb3d637dab5ca0e620274b2fc Partial-Bug: #1746615 --- .../openstack/placement/test_report_client.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/nova/tests/functional/api/openstack/placement/test_report_client.py b/nova/tests/functional/api/openstack/placement/test_report_client.py index 88db651970b8..4dc11f2a17fa 100644 --- a/nova/tests/functional/api/openstack/placement/test_report_client.py +++ b/nova/tests/functional/api/openstack/placement/test_report_client.py @@ -216,6 +216,77 @@ class SchedulerReportClientTests(test.TestCase): self.context, self.compute_uuid, self.compute_name, inv_data) + @mock.patch('nova.compute.utils.is_volume_backed_instance', + new=mock.Mock(return_value=False)) + @mock.patch('nova.objects.compute_node.ComputeNode.save', new=mock.Mock()) + @mock.patch('keystoneauth1.session.Session.get_auth_headers', + new=mock.Mock(return_value={'x-auth-token': 'admin'})) + @mock.patch('keystoneauth1.session.Session.get_endpoint', + new=mock.Mock(return_value='http://localhost:80/placement')) + def test_ensure_standard_resource_class(self): + """Test case for bug #1746615: If placement is running a newer version + of code than compute, it may have new standard resource classes we + don't know about. Make sure this scenario doesn't cause errors in + set_inventory_for_provider. + """ + inv = { + 'VCPU': { + 'total': 10, + 'reserved': 0, + 'min_unit': 1, + 'max_unit': 2, + 'step_size': 1, + 'allocation_ratio': 10.0, + }, + 'MEMORY_MB': { + 'total': 1048576, + 'reserved': 2048, + 'min_unit': 1024, + 'max_unit': 131072, + 'step_size': 1024, + 'allocation_ratio': 1.0, + }, + 'DISK_GB': { + 'total': 100, + 'reserved': 1, + 'min_unit': 1, + 'max_unit': 10, + 'step_size': 2, + 'allocation_ratio': 10.0, + }, + # A standard resource class known by placement, but not locally + 'PCI_DEVICE': { + 'total': 4, + 'reserved': 0, + 'min_unit': 1, + 'max_unit': 4, + 'step_size': 1, + 'allocation_ratio': 1.0, + }, + 'CUSTOM_BANDWIDTH': { + 'total': 1250000, + 'reserved': 10000, + 'min_unit': 5000, + 'max_unit': 250000, + 'step_size': 5000, + 'allocation_ratio': 8.0, + }, + } + with interceptor.RequestsInterceptor(app=self.app, url=self.url): + self.client.update_compute_node(self.context, self.compute_node) + # Simulate that our locally-running code has an outdated notion of + # standard resource classes. + with mock.patch.object(fields.ResourceClass, 'STANDARD', + ('VCPU', 'MEMORY_MB', 'DISK_GB')): + # TODO(efried): Once bug #1746615 is fixed, this will no longer + # raise, and can be replaced with: + # self.client.set_inventory_for_provider( + # self.context, self.compute_uuid, self.compute_name, inv) + self.assertRaises( + exception.InvalidResourceClass, + self.client.set_inventory_for_provider, + self.context, self.compute_uuid, self.compute_name, inv) + @mock.patch('keystoneauth1.session.Session.get_endpoint', return_value='http://localhost:80/placement') def test_global_request_id(self, mock_endpoint):