@@ -0,0 +1,3381 @@
+# Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may obtain%0A# a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations%0A# under the License.%0A%0Afrom oslo_utils.fixture import uuidsentinel as uuids%0Aimport six%0A%0Afrom nova.tests.functional.api import client as api_client%0Afrom nova.tests.functional import integrated_helpers%0A%0A%0Aclass ResizeSameHostDoubledAllocations(%0A        integrated_helpers.ProviderUsageBaseTestCase):%0A    %22%22%22Regression test for bug 1790204 introduced in Pike.%0A%0A    Since Pike, the FilterScheduler uses Placement to %22claim%22 resources%0A    via allocations during scheduling. During a move operation, the%0A    scheduler will claim resources on the selected destination resource%0A    provider (compute node). For a same-host resize, this means claiming%0A    resources from the *new_flavor* on the destination while holding%0A    allocations for the *old_flavor* on the source, which is the same%0A    provider. This can lead to NoValidHost failures during scheduling a%0A    resize to the same host since the allocations are %22doubled up%22 on the%0A    same provider even though the *new_flavor* allocations could fit.%0A%0A    This test reproduces the regression.%0A    %22%22%22%0A%0A    # Use the SmallFakeDriver which has little inventory:%0A    # vcpus = 2, memory_mb = 8192, local_gb = 1028%0A    compute_driver = 'fake.SmallFakeDriver'%0A%0A    def setUp(self):%0A        super(ResizeSameHostDoubledAllocations, self).setUp()%0A        self._start_compute(uuids.host)%0A%0A    def test_resize_same_host_full_allocations(self):%0A        self.flags(allow_resize_to_same_host=True)%0A        # Create two flavors so we can control what the test uses.%0A        flavor = %7B%0A            'flavor': %7B%0A                'name': 'v1r2d1', 'ram': 2048, 'vcpus': 1, 'disk': 1028,%0A            %7D%0A        %7D%0A        flavor1 = self.admin_api.post_flavor(flavor)%0A        # Tweak the flavor to increase the number of VCPUs.%0A        flavor%5B'flavor'%5D.update(%7B'name': 'v2r2d1', 'vcpus': 2%7D)%0A        flavor2 = self.admin_api.post_flavor(flavor)%0A%0A        # Create a server from flavor1.%0A        server = self._boot_and_check_allocations(flavor1, uuids.host)%0A%0A        # Now try to resize to flavor2.%0A        resize_req = %7B%0A            'resize': %7B%0A                'flavorRef': flavor2%5B'id'%5D,%0A            %7D%0A        %7D%0A        # FIXME(mriedem): This is bug 1790204 where scheduling fails with%0A        # NoValidHost because the scheduler fails to claim %22doubled up%22%0A        # allocations on the same compute node resource provider. Scheduling%0A        # fails because DISK_GB inventory allocation ratio is 1.0 and when%0A        # resizing to the same host we'll be trying to claim 2048 but the%0A        # provider only has a total of 1024.%0A        ex = self.assertRaises(api_client.OpenStackApiException,%0A                               self.api.post_server_action,%0A                               server%5B'id'%5D, resize_req)%0A        self.assertEqual(400, ex.response.status_code)%0A        self.assertIn('No valid host was found', six.text_type(ex))%0A

Add functional regression recreate test for bug 1790204