Merge "Refactor TestEvacuateDeleteServerRestartOriginalCompute"

This commit is contained in:
Zuul 2018-12-04 07:49:27 +00:00 committed by Gerrit Code Review
commit 5f648dda49
3 changed files with 12 additions and 110 deletions

View File

@ -787,3 +787,11 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
# The migration should hold an old_flavor allocation
self.assertFlavorMatchesAllocation(old_flavor, migration_uuid,
rp_uuid)
def _check_allocation_during_evacuate(
self, flavor, server_uuid, source_root_rp_uuid, dest_root_rp_uuid):
allocations = self._get_allocations_by_server_uuid(server_uuid)
self.assertEqual(2, len(allocations))
self.assertFlavorMatchesUsage(source_root_rp_uuid, flavor)
self.assertFlavorMatchesUsage(dest_root_rp_uuid, flavor)

View File

@ -10,12 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from nova.tests.functional import integrated_helpers
LOG = logging.getLogger(__name__)
class TestEvacuateDeleteServerRestartOriginalCompute(
integrated_helpers.ProviderUsageBaseTestCase):
@ -30,95 +26,6 @@ class TestEvacuateDeleteServerRestartOriginalCompute(
flavors = self.api.get_flavors()
self.flavor1 = flavors[0]
# NOTE(mriedem): This is here for backports and should be removed later
# on master (Stein).
def assertFlavorMatchesAllocation(self, flavor, allocation):
self.assertEqual(flavor['vcpus'], allocation['VCPU'])
self.assertEqual(flavor['ram'], allocation['MEMORY_MB'])
self.assertEqual(flavor['disk'], allocation['DISK_GB'])
# NOTE(mriedem): This is here for backports and should be removed later
# on master (Stein).
def _boot_and_check_allocations(self, flavor, source_hostname):
"""Boot an instance and check that the resource allocation is correct
After booting an instance on the given host with a given flavor it
asserts that both the providers usages and resource allocations match
with the resources requested in the flavor. It also asserts that
running the periodic update_available_resource call does not change the
resource state.
:param flavor: the flavor the instance will be booted with
:param source_hostname: the name of the host the instance will be
booted on
:return: the API representation of the booted instance
"""
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=flavor['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
server_req['availability_zone'] = 'nova:%s' % source_hostname
LOG.info('booting on %s', source_hostname)
created_server = self.api.post_server({'server': server_req})
server = self._wait_for_state_change(
self.admin_api, created_server, 'ACTIVE')
# Verify that our source host is what the server ended up on
self.assertEqual(source_hostname, server['OS-EXT-SRV-ATTR:host'])
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
# Before we run periodics, make sure that we have allocations/usages
# only on the source host
source_usages = self._get_provider_usages(source_rp_uuid)
self.assertFlavorMatchesAllocation(flavor, source_usages)
# Check that the other providers has no usage
for rp_uuid in [self._get_provider_uuid_by_host(hostname)
for hostname in self.computes.keys()
if hostname != source_hostname]:
usages = self._get_provider_usages(rp_uuid)
self.assertEqual({'VCPU': 0,
'MEMORY_MB': 0,
'DISK_GB': 0}, usages)
# Check that the server only allocates resource from the host it is
# booted on
allocations = self._get_allocations_by_server_uuid(server['id'])
self.assertEqual(1, len(allocations),
'No allocation for the server on the host it '
'is booted on')
allocation = allocations[source_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(flavor, allocation)
self._run_periodics()
# After running the periodics but before we start any other operation,
# we should have exactly the same allocation/usage information as
# before running the periodics
# Check usages on the selected host after boot
source_usages = self._get_provider_usages(source_rp_uuid)
self.assertFlavorMatchesAllocation(flavor, source_usages)
# Check that the server only allocates resource from the host it is
# booted on
allocations = self._get_allocations_by_server_uuid(server['id'])
self.assertEqual(1, len(allocations),
'No allocation for the server on the host it '
'is booted on')
allocation = allocations[source_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(flavor, allocation)
# Check that the other providers has no usage
for rp_uuid in [self._get_provider_uuid_by_host(hostname)
for hostname in self.computes.keys()
if hostname != source_hostname]:
usages = self._get_provider_usages(rp_uuid)
self.assertEqual({'VCPU': 0,
'MEMORY_MB': 0,
'DISK_GB': 0}, usages)
return server
def test_evacuate_delete_server_restart_original_compute(self):
"""Regression test for bug 1794996 where a server is successfully
evacuated from a down host and then deleted. Then the source compute
@ -158,18 +65,13 @@ class TestEvacuateDeleteServerRestartOriginalCompute(
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
source_usages = self._get_provider_usages(source_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, source_usages)
dest_usages = self._get_provider_usages(dest_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
self.assertFlavorMatchesUsage(source_rp_uuid, self.flavor1)
self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
allocations = self._get_allocations_by_server_uuid(server['id'])
self.assertEqual(2, len(allocations))
source_allocation = allocations[source_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, source_allocation)
dest_allocation = allocations[dest_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)
self._check_allocation_during_evacuate(
self.flavor1, server['id'], source_rp_uuid, dest_rp_uuid)
# Delete the evacuated server. The allocations should be gone from
# both the original evacuated-from host and the evacuated-to host.

View File

@ -2363,14 +2363,6 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
self._delete_and_check_allocations(server)
def _check_allocation_during_evacuate(
self, flavor, server_uuid, source_root_rp_uuid, dest_root_rp_uuid):
allocations = self._get_allocations_by_server_uuid(server_uuid)
self.assertEqual(2, len(allocations))
self.assertFlavorMatchesUsage(source_root_rp_uuid, flavor)
self.assertFlavorMatchesUsage(dest_root_rp_uuid, flavor)
def test_evacuate(self):
source_hostname = self.compute1.host
dest_hostname = self.compute2.host